<?php

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

use App\Nova\Resources\Branch\Branch;
use App\Nova\Resources\Order\Loan\LoanType;
use App\Nova\Resources\System\Location\Province;
use App\Nova\User;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Settings\Legal\EducationRepo;
use App\Repos\System\Settings\Legal\MarriageRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Email;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Panel;
use Nurmuhammet\NovaInputmask\NovaInputmask;

class LoanOrderFieldsForDetail
{
    /**
     * Loan order fields for detail
     */
    public static function make($resource): array
    {
        return [
            ID::make()->hide(),
            Text::make(__('ID'), 'unique_id'),

            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()),

            Text::make(__('Note'), 'notes'),

            BelongsTo::make(__('Created by').': ', 'user', User::class),

            new Panel(__('Loan'), [
                BelongsTo::make(__('Loan type'), 'loanType', LoanType::class),
            ]),

            new Panel(__('Location'), [
                Select::make(__('Region'), 'region')
                    ->displayUsingLabels()
                    ->options(RegionRepo::values())
                    ->size('w-1/2'),

                BelongsTo::make(__('Branch'), 'branch', Branch::class),
            ]),

            new Panel(__('Personal data'), [
                Text::make(
                    __('Full Name'),
                    fn ($model) => sprintf('%s %s %s', $model->customer_name, $model->customer_surname, $model->customer_patronic_name)
                ),

                Select::make(__('Education'), 'education')
                    ->displayUsingLabels()
                    ->options(EducationRepo::values())
                    ->size('w-1/3'),

                Select::make(__('Marriage status'), 'marriage_status')
                    ->displayUsingLabels()
                    ->options(MarriageRepo::values())
                    ->size('w-1/3'),

                Date::make(__('Date of birth'), 'born_at')
                    ->size('w-1/3')
                    ->toTurkmenFormat(),

                Text::make(__('Residence (passport)'), 'passport_address')
                    ->size('w-1/2'),

                Text::make(__('Current Residence'), 'real_address')
                    ->size('w-1/2'),
            ]),

            new Panel(__('Contact data'), [
                Email::make(__('Email'), 'email')
                    ->size('w-1/4'),

                NovaInputmask::make(__('Phone'), 'phone')
                    ->mask('+(\\9\\93)-99-99-99-99')
                    ->storeRawValue()
                    ->size('w-1/4'),

                NovaInputmask::make(__('Phone Additional'), 'phone_additional')
                    ->mask('+(\\9\\93)-99-99-99-99')
                    ->storeRawValue()
                    ->size('w-1/4'),

                NovaInputmask::make(__('Home phone'), 'phone_home')
                    ->mask('+(\\9\\93)-9{8}')
                    ->storeRawValue()
                    ->size('w-1/4'),
            ]),

            new Panel(__('Job'), [
                Text::make(__('Work company name'), 'work_company')
                    ->size('w-1/2'),

                NovaInputmask::make(__('HR department work number'), 'work_company_accountant_number')
                    ->mask('+(\\9\\93)-9{8}')
                    ->size('w-1/2'),

                Select::make(__('Work region'), 'work_region')
                    ->displayUsingLabels()
                    ->options(RegionRepo::values())
                    ->size('w-1/2'),

                BelongsTo::make(__('Work province'), 'workProvince', Province::class),

                Text::make(__('Position'), 'work_position')
                    ->size('w-1/2'),

                Text::make(__('Salary'), 'work_salary')
                    ->size('w-1/4'),

                Date::make(__('Work started at'), 'work_started_at')
                    ->size('w-1/4')
                    ->toTurkmenFormat(),
            ]),

            new Panel(__('Passport'), [
                Text::make(__('Passport'), fn ($model) => sprintf(
                    '<strong>%s %s, %sý<strong>',
                    $model->passport_serie,
                    $model->passport_id,
                    $model->passport_given_at?->format('d.m.Y')
                ))->asHtml(),

                Text::make(__('Passport given by'), 'passport_given_by')
                    ->size('w-1/2'),

                Text::make(__('Born place (passport)'), 'born_place')
                    ->size('w-1/2'),

                Image::make(__('Passport (page 1)'), 'passport_one')
                    ->size('w-1/2'),

                Image::make(__('Passport (page 2-3)'), 'passport_two')
                    ->size('w-1/2'),

                Image::make(__('Passport (page 8-9)'), 'passport_three')
                    ->size('w-1/2'),

                Image::make(__('Passport (page 32)'), 'passport_four')
                    ->size('w-1/2'),
            ]),
        ];
    }
}
