<?php

namespace App\Nova\Resources\Ecommerce\Product\Order\Concerns;

use App\Models\Ecommerce\Product\Order\Shipping\OrderShipping;
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
use App\Models\System\Settings\Location\Region;
use App\Models\System\Settings\OS;
use App\Nova\Fields\FieldHelpers;
use App\Nova\Resources\Ecommerce\Product\Order\OrderShippingMethod;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Nurmuhammet\NovaInputmask\NovaInputmask;

class OrderFieldsForIndex
{
    /**
     * Fields for index
     */
    public static function make($resource, $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make(__('Customer'), 'customer_name')
                ->sortable(),

            NovaInputmask::make(__('Customer phone'), 'customer_phone')
                ->mask(phoneMaskFormat())
                ->storeRawValue()
                ->sortable(),

            Select::make(__('Welaýat'), 'region')
                ->displayUsingLabels()
                ->options(Region::values())
                ->sortable(),

            Select::make(__('Delivery time'), 'delivery_time')
                ->displayUsingLabels()
                ->searchable()
                ->options(OrderShipping::times())
                ->rules('required')
                ->sortable(),

            Date::make(__('Delivery date'), 'delivery_at')
                ->displayUsing(FieldHelpers::tmDate())
                ->sortable(),

            BelongsTo::make(__('Shipping method'), 'shippingMethod', OrderShippingMethod::class)
                ->sortable(),

            Select::make(__('Source'), 'source_app')
                ->displayUsingLabels()
                ->options(OS::apps())
                ->sortable(),

            Text::make(__('Total'), fn () => $resource->fullPriceWithShipping().' TMT')
                ->canSeeWhen('systemUser', $resource)
                ->sortable(),

            DateTime::make(__('Created at'), 'created_at')
                ->turkmenDate(),

            Badge::make('Status')
                ->map(OrderStatus::classes())
                ->labels(OrderStatus::values())
                ->addTypes([
                    'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
                ])
                ->sortable(),
        ];
    }
}
