<?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\Nova\Fields\FieldHelpers;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

trait HasFieldsForIndex
{
    /**
     * Get the fields displayed by the resource.
     */
    public function fieldsForIndex(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make(__('Customer'), 'customer_name')
                ->canSeeWhen('systemUser', $this)
                ->sortable(),

            Text::make(__('Phone'), 'customer_phone')
                ->canSeeWhen('systemUser', $this)
                ->sortable(),

            Select::make(__('Welaýat'), 'region')
                ->displayUsingLabels()
                ->options(Region::values())
                ->canSeeWhen('systemUser', $this)
                ->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(),

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

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