<?php

namespace App\Nova\Resources\Order\Card\Concerns;

use App\Nova\Resources\Branch\Branch;
use App\Nova\Resources\Order\Card\CardState;
use App\Nova\Resources\Order\Card\CardType;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;

class CardOrderFieldsForIndex
{
    /**
     * Fields for index page
     */
    public static function make($resource): array
    {
        return [
            ID::make()->hide(),

            Text::make(__('ID'), 'unique_id')->sortable(),

            BelongsTo::make(__('Reason'), 'cardState', CardState::class)
                ->sortable(),

            BelongsTo::make(__('Type'), 'cardType', CardType::class)
                ->sortable(),

            Select::make(__('Region'), 'region')
                ->displayUsingLabels()
                ->options(RegionRepo::values())
                ->canSeeWhen('isAdmin', $resource)
                ->sortable(),

            BelongsTo::make(__('Branch'), 'branch', Branch::class)
                ->canSeeWhen('isAdmin', $resource)
                ->filterable()
                ->sortable(),

            Text::make(__('Name'), 'customer_name'),

            Text::make(__('Surname'), 'customer_surname'),

            Text::make(__('Phone'), 'phone'),

            Badge::make(__('Status'), 'status')
                ->map(OrderRepo::statusClasses())
                ->addTypes([
                    'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
                ])
                ->labels(OrderRepo::statusValues())
                ->withIcons()
                ->icons(OrderRepo::statusIcons())
                ->sortable(),
        ];
    }
}
