<?php

namespace App\Filament\Resources;

use App\Filament\Exports\TempClassCharacteristicExporter;
use App\Filament\Imports\TempClassCharacteristicImporter;
use App\Filament\Resources\TempClassCharacteristicResource\Pages;
use App\Models\Item;
use App\Models\Machine;
use App\Models\Plant;
use App\Models\TempClassCharacteristic;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Validation\Rule;

class TempClassCharacteristicResource extends Resource
{
    protected static ?string $model = TempClassCharacteristic::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    protected static ?string $navigationGroup = 'Laser Marking';

    protected static ?int $navigationSort = 4;

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make('')
                    ->schema([
                        Forms\Components\Select::make('plant_id')
                            ->label('PLANT NAME')
                            ->relationship('plant', 'name')
                            ->reactive()
                            ->searchable()
                            ->options(function (callable $get) {
                                $userHas = Filament::auth()->user()->plant_id;

                                return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
                            })
                            ->disabled(fn (Get $get) => ! empty($get('id')))
                            ->default(function () {
                                $userHas = Filament::auth()->user()->plant_id;

                                return ($userHas && strlen($userHas) > 0) ? $userHas : optional(TempClassCharacteristic::latest()->first())->plant_id;
                            })
                            ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
                                $set('item_id', null);
                                $set('machine_id', null);
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\Select::make('machine_id')
                        // ->relationship('item', 'id')
                            ->label('WORK CENTER')
                            ->reactive()
                            ->searchable()
                            ->options(function (callable $get) {
                                $plantId = $get('plant_id');
                                // $itemId = $get('item_id');
                                if (empty($plantId)) {
                                    return [];
                                }

                                return Machine::where('plant_id', $plantId)->pluck('work_center', 'id')->toArray();
                            })
                            ->disabled(fn (Get $get) => ! empty($get('id')))
                            ->default(function (callable $get) {
                                $plantId = $get('plant_id');
                                // $itemId = $get('item_id');
                                if (empty($plantId)) {
                                    return null;
                                }

                                return TempClassCharacteristic::where('plant_id', $plantId)->latest()->first()->machine_id ?? null;
                            })
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\Select::make('item_id')
                            // ->relationship('item', 'id')
                            ->label('ITEM CODE')
                            ->reactive()
                            ->searchable()
                            ->options(function (callable $get) {
                                $plantId = $get('plant_id');
                                if (empty($plantId)) {
                                    return [];
                                }

                                return Item::where('plant_id', $plantId)->pluck('code', 'id')->toArray();
                            })
                            ->disabled(fn (Get $get) => ! empty($get('id')))
                            ->default(function (callable $get) {
                                $plantId = $get('plant_id');
                                if (empty($plantId)) {
                                    return null;
                                }

                                return TempClassCharacteristic::where('plant_id', $plantId)->latest()->first()->item_id ?? null;
                            })
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('aufnr')
                            ->label('AUFNR')
                            ->reactive()
                            ->minLength(7)
                            ->maxLength(10)
                            ->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id') || ! $get('item_id')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('class')
                            ->label('CLASS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->readOnly(fn (callable $get) => (! $get('aufnr')))
                            ->required(),
                        Forms\Components\TextInput::make('arbid')
                            ->label('ARBID')
                            ->reactive()
                            ->readOnly(fn (callable $get) => (! $get('class')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('gamng')
                            ->label('GAMNG')
                            ->reactive()
                            ->numeric()
                            ->minValue(1.000)
                            ->readOnly(fn (callable $get) => (! $get('arbid')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('lmnga')
                            ->label('LMNGA')
                            ->reactive()
                            ->integer()
                            ->minValue(1)
                            ->maxValue(fn (callable $get) => ($get('gamng') ?? 1))
                            ->readOnly(fn (callable $get) => (! $get('gamng')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('gernr')
                            ->label('GERNR')
                            ->reactive()
                            ->minLength(13)
                            ->readOnly(fn (callable $get) => (! $get('lmnga')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->rules([
                                function (callable $get) {
                                    return Rule::unique('class_characteristics', 'gernr')
                                        ->where('plant_id', $get('plant_id'))
                                        ->ignore($get('id'));
                                }, // The GERNR has already been taken.
                                // function (callable $get): Closure {
                                //     return function (string $attribute, $value, Closure $fail) use ($get) {
                                //         $rework = $get('rework_status');
                                //         if ($value && Str::contains($value, '.') && $rework == 0) {
                                //             $fail("Rework status should be 'Yes' for rework coil number '{$value}'!");
                                //         }
                                //     };
                                // },
                            ])
                            ->validationMessages([
                                'unique' => "The 'GERNR' has already been taken.",  // The GERNR has already been taken for this plant.
                            ])
                            ->required(),
                        Forms\Components\TextInput::make('zz1_cn_bill_ord')
                            ->label('ZZ1 CN BILL ORD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_amps')
                            ->label('ZMM AMPS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_brand')
                            ->label('ZMM BRAND')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_degreeofprotection')
                            ->label('ZMM DEGREEOFPROTECTION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_delivery')
                            ->label('ZMM DELIVERY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_dir_rot')
                            ->label('ZMM DIR ROT')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_discharge')
                            ->label('ZMM DISCHARGE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_discharge_max')
                            ->label('ZMM DISCHARGE MAX')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_discharge_min')
                            ->label('ZMM DISCHARGE MIN')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_duty')
                            ->label('ZMM DUTY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_eff_motor')
                            ->label('ZMM EFF MOTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_eff_pump')
                            ->label('ZMM EFF PUMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_frequency')
                            ->label('ZMM FREQUENCY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_head')
                            ->label('ZMM HEAD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_heading')
                            ->label('ZMM HEADING')
                            ->reactive()
                            ->readOnly(fn (callable $get) => (! $get('aufnr') || ! $get('gernr')))
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            })
                            ->required(),
                        Forms\Components\TextInput::make('zmm_head_max')
                            ->label('ZMM HEAD MAX')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_head_minimum')
                            ->label('ZMM HEAD MINIMUM')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_idx_eff_mtr')
                            ->label('ZMM IDX EFF MTR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_idx_eff_pump')
                            ->label('ZMM IDX EFF PUMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_kvacode')
                            ->label('ZMM KVACODE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_maxambtemp')
                            ->label('ZMM MAXAMBTEMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_mincoolingflow')
                            ->label('ZMM MINCOOLINGFLOW')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motorseries')
                            ->label('ZMM MOTORSERIES')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motor_model')
                            ->label('ZMM MOTOR MODEL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_outlet')
                            ->label('ZMM OUTLET')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_phase')
                            ->label('ZMM PHASE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pressure')
                            ->label('ZMM PRESSURE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pumpflowtype')
                            ->label('ZMM PUMPFLOWTYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pumpseries')
                            ->label('ZMM PUMPSERIES')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pump_model')
                            ->label('ZMM PUMP MODEL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_ratedpower')
                            ->label('ZMM RATEDPOWER')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_region')
                            ->label('ZMM REGION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_servicefactor')
                            ->label('ZMM SERVICEFACTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_servicefactormaximumamps')
                            ->label('ZMM SERVICEFACTORMAXIMUMAMPS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_speed')
                            ->label('ZMM SPEED')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_suction')
                            ->label('ZMM SUCTION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_suctionxdelivery')
                            ->label('ZMM SUCTIONXDELIVERY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_supplysource')
                            ->label('ZMM SUPPLYSOURCE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_temperature')
                            ->label('ZMM TEMPERATURE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_thrustload')
                            ->label('ZMM THRUSTLOAD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_volts')
                            ->label('ZMM VOLTS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_wire')
                            ->label('ZMM WIRE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_package')
                            ->label('ZMM PACKAGE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pvarrayrating')
                            ->label('ZMM PVARRAYRATING')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isi')
                            ->label('ZMM ISI')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isimotor')
                            ->label('ZMM ISIMOTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isipump')
                            ->label('ZMM ISIPUMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isipumpset')
                            ->label('ZMM ISIPUMPSET')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pumpset_model')
                            ->label('ZMM PUMPSET MODEL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_stages')
                            ->label('ZMM STAGES')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_headrange')
                            ->label('ZMM HEADRANGE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_overall_efficiency')
                            ->label('ZMM OVERALL EFFICIENCY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_connection')
                            ->label('ZMM CONNECTION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_min_bore_size')
                            ->label('ZMM MIN BORE SIZE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isireference')
                            ->label('ZMM ISIREFERENCE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_category')
                            ->label('ZMM CATEGORY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_submergence')
                            ->label('ZMM SUBMERGENCE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_capacitorstart')
                            ->label('ZMM CAPACITORSTART')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_capacitorrun')
                            ->label('ZMM CAPACITORRUN')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_inch')
                            ->label('ZMM INCH')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motor_type')
                            ->label('ZMM MOTOR TYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_dismantle_direction')
                            ->label('ZMM DISMANTLE DIRECTION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_eff_ovrall')
                            ->label('ZMM EFF OVRALL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_bodymoc')
                            ->label('ZMM BODYMOC')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_rotormoc')
                            ->label('ZMM ROTORMOC')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_dlwl')
                            ->label('ZMM DLWL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_inputpower')
                            ->label('ZMM INPUTPOWER')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_imp_od')
                            ->label('ZMM IMP OD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_ambtemp')
                            ->label('ZMM AMBTEMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_de')
                            ->label('ZMM DE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_dischargerange')
                            ->label('ZMM DISCHARGERANGE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_efficiency_class')
                            ->label('ZMM EFFICIENCY CLASS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_framesize')
                            ->label('ZMM FRAMESIZE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_impellerdiameter')
                            ->label('ZMM IMPELLERDIAMETER')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_insulationclass')
                            ->label('ZMM INSULATIONCLASS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_maxflow')
                            ->label('ZMM MAXFLOW')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_minhead')
                            ->label('ZMM MINHEAD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_mtrlofconst')
                            ->label('ZMM MTRLOFCONST')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_nde')
                            ->label('ZMM NDE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_powerfactor')
                            ->label('ZMM POWERFACTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_tagno')
                            ->label('ZMM TAGNO')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_year')
                            ->label('ZMM YEAR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_laser_name')
                            ->label('ZMM LASER NAME')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_logo_cp')
                            ->label('ZMM LOGO CP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_logo_ce')
                            ->label('ZMM LOGO CE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_logo_nsf')
                            ->label('ZMM LOGO NSF')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_logo_eac')
                            ->label('ZMM LOGO EAC')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_beenote')
                            ->label('ZMM BEENOTE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_beenumber')
                            ->label('ZMM BEENUMBER')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_beestar')
                            ->label('ZMM BEESTAR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_codeclass')
                            ->label('ZMM CODECLASS')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_colour')
                            ->label('ZMM COLOUR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grade')
                            ->label('ZMM GRADE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grwt_pset')
                            ->label('ZMM GRWT PSET')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grwt_cable')
                            ->label('ZMM GRWT CABLE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grwt_motor')
                            ->label('ZMM GRWT MOTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grwt_pf')
                            ->label('ZMM GRWT PF')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_grwt_pump')
                            ->label('ZMM GRWT PUMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isivalve')
                            ->label('ZMM ISIVALVE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_isi_wc')
                            ->label('ZMM ISI WC')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_labelperiod')
                            ->label('ZMM LABELPERIOD')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_length')
                            ->label('ZMM LENGTH')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_license_cml_no')
                            ->label('ZMM LICENSE CML NO')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_mfgmonyr')
                            ->label('ZMM MFGMONYR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_modelyear')
                            ->label('ZMM MODELYEAR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motoridentification')
                            ->label('ZMM MOTORIDENTIFICATION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_newt_pset')
                            ->label('ZMM NEWT PSET')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_newt_cable')
                            ->label('ZMM NEWT CABLE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_newt_motor')
                            ->label('ZMM NEWT MOTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_newt_pf')
                            ->label('ZMM NEWT PF')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_newt_pump')
                            ->label('ZMM NEWT PUMP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_packtype')
                            ->label('ZMM PACKTYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_panel')
                            ->label('ZMM PANEL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_performance_factor')
                            ->label('ZMM PERFORMANCE_FACTOR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_pumpidentification')
                            ->label('ZMM PUMPIDENTIFICATION')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_psettype')
                            ->label('ZMM PSETTYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_size')
                            ->label('ZMM SIZE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_eff_ttl')
                            ->label('ZMM EFF TTL')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_type')
                            ->label('ZMM TYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_usp')
                            ->label('ZMM USP')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_operating_range')
                            ->label('ZMM OPERATING RANGE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_intake_air')
                            ->label('ZMM INTAKE AIR')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_oxygen_transfer_rate')
                            ->label('ZMM OXYGEN TRANSFER RATE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_air_inlet_pipesize')
                            ->label('ZMM AIR INLET PIPESIZE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_sump_depth')
                            ->label('ZMM SUMP DEPTH')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_poles')
                            ->label('ZMM POLES')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motor_heading')
                            ->label('ZMM MOTOR HEADING')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_motor_speed')
                            ->label('ZMM MOTOR SPEED')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zqmm_qty')
                            ->label('ZQMM QTY')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_operating_temperature')
                            ->label('ZMM OPERATING TEMPERATURE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('zmm_axial_force')
                            ->label('ZMM AXIAL FORCE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('winded_serial_number')
                            ->label('WINDED SERIAL NUMBER')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('model_type')
                            ->label('MODEL TYPE')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\TextInput::make('has_work_flow_id')
                            ->label('HAS WORK FLOW ID')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set) {
                                $set('updated_by', Filament::auth()->user()?->name);
                            }),
                        Forms\Components\Hidden::make('created_by')
                            ->label('Created By')
                            ->default(Filament::auth()->user()?->name),
                        Forms\Components\Hidden::make('updated_by')
                            ->label('Updated By')
                            ->default(Filament::auth()->user()?->name),
                        Forms\Components\TextInput::make('id')
                            ->hidden()
                            ->readOnly(),
                    ])
                    ->columns(3),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('No.')
                    ->label('NO')
                    ->alignCenter()
                    ->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
                        $paginator = $livewire->getTableRecords();
                        $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
                        $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;

                        return ($currentPage - 1) * $perPage + $rowLoop->iteration;
                    }),
                Tables\Columns\TextColumn::make('plant.name')
                    ->label('PLANT NAME')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('machine.work_center')
                    ->label('WORK CENTER')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('item.code')
                    ->label('ITEM CODE')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('model_type')
                    ->label('MODEL TYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('aufnr')
                    ->label('AUFNR')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('class')
                    ->label('CLASS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('arbid')
                    ->label('ARBID')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('gamng')
                    ->label('GAMNG')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('lmnga')
                    ->label('LMNGA')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('gernr')
                    ->label('GERNR')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zz1_cn_bill_ord')
                    ->label('ZZ1 CN BILL ORD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_amps')
                    ->label('ZMM AMPS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_brand')
                    ->label('ZMM BRAND')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_degreeofprotection')
                    ->label('ZMM DEGREEOFPROTECTION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_delivery')
                    ->label('ZMM DELIVERY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_dir_rot')
                    ->label('ZMM DIR ROT')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_discharge')
                    ->label('ZMM DISCHARGE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_discharge_max')
                    ->label('ZMM DISCHARGE MAX')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_discharge_min')
                    ->label('ZMM DISCHARGE MIN')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_duty')
                    ->label('ZMM DUTY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_eff_motor')
                    ->label('ZMM EFF MOTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_eff_pump')
                    ->label('ZMM EFF PUMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_frequency')
                    ->label('ZMM FREQUENCY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_head')
                    ->label('ZMM HEAD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_heading')
                    ->label('ZMM HEADING')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_head_max')
                    ->label('ZMM HEAD MAX')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_head_minimum')
                    ->label('ZMM HEAD MINIMUM')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_idx_eff_mtr')
                    ->label('ZMM IDX EFF MTR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_idx_eff_pump')
                    ->label('ZMM IDX EFF PUMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_kvacode')
                    ->label('ZMM KVACODE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_maxambtemp')
                    ->label('ZMM MAXAMBTEMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_mincoolingflow')
                    ->label('ZMM MINCOOLINGFLOW')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motorseries')
                    ->label('ZMM MOTORSERIES')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motor_model')
                    ->label('ZMM MOTOR MODEL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_outlet')
                    ->label('ZMM OUTLET')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_phase')
                    ->label('ZMM PHASE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pressure')
                    ->label('ZMM PRESSURE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pumpflowtype')
                    ->label('ZMM PUMPFLOWTYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pumpseries')
                    ->label('ZMM PUMPSERIES')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pump_model')
                    ->label('ZMM PUMP MODEL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_ratedpower')
                    ->label('ZMM RATEDPOWER')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_region')
                    ->label('ZMM REGION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_servicefactor')
                    ->label('ZMM SERVICEFACTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_servicefactormaximumamps')
                    ->label('ZMM SERVICEFACTORMAXIMUMAMPS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_speed')
                    ->label('ZMM SPEED')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_suction')
                    ->label('ZMM SUCTION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_suctionxdelivery')
                    ->label('ZMM SUCTIONXDELIVERY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_supplysource')
                    ->label('ZMM SUPPLYSOURCE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_temperature')
                    ->label('ZMM TEMPERATURE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_thrustload')
                    ->label('ZMM THRUSTLOAD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_volts')
                    ->label('ZMM VOLTS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_wire')
                    ->label('ZMM WIRE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_package')
                    ->label('ZMM PACKAGE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pvarrayrating')
                    ->label('ZMM PVARRAYRATING')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isi')
                    ->label('ZMM ISI')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isimotor')
                    ->label('ZMM ISIMOTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isipump')
                    ->label('ZMM ISIPUMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isipumpset')
                    ->label('ZMM ISIPUMPSET')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pumpset_model')
                    ->label('ZMM PUMPSET MODEL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_stages')
                    ->label('ZMM STAGES')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_headrange')
                    ->label('ZMM HEADRANGE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_overall_efficiency')
                    ->label('ZMM OVERALL EFFICIENCY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_connection')
                    ->label('ZMM CONNECTION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_min_bore_size')
                    ->label('ZMM MIN BORE SIZE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isireference')
                    ->label('ZMM ISIREFERENCE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_category')
                    ->label('ZMM CATEGORY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_submergence')
                    ->label('ZMM SUBMERGENCE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_capacitorstart')
                    ->label('ZMM CAPACITORSTART')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_capacitorrun')
                    ->label('ZMM CAPACITORRUN')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_inch')
                    ->label('ZMM INCH')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motor_type')
                    ->label('ZMM MOTOR TYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_dismantle_direction')
                    ->label('ZMM DISMANTLE DIRECTION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_eff_ovrall')
                    ->label('ZMM EFF OVRALL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_bodymoc')
                    ->label('ZMM BODYMOC')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_rotormoc')
                    ->label('ZMM ROTORMOC')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_dlwl')
                    ->label('ZMM DLWL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_inputpower')
                    ->label('ZMM INPUTPOWER')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_imp_od')
                    ->label('ZMM IMP OD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_ambtemp')
                    ->label('ZMM AMBTEMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_de')
                    ->label('ZMM DE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_dischargerange')
                    ->label('ZMM DISCHARGERANGE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_efficiency_class')
                    ->label('ZMM EFFICIENCY CLASS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_framesize')
                    ->label('ZMM FRAMESIZE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_impellerdiameter')
                    ->label('ZMM IMPELLERDIAMETER')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_insulationclass')
                    ->label('ZMM INSULATIONCLASS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_maxflow')
                    ->label('ZMM MAXFLOW')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_minhead')
                    ->label('ZMM MINHEAD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_mtrlofconst')
                    ->label('ZMM MTRLOFCONST')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_nde')
                    ->label('ZMM NDE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_powerfactor')
                    ->label('ZMM POWERFACTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_tagno')
                    ->label('ZMM TANGO')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_year')
                    ->label('ZMM YEAR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_laser_name')
                    ->label('ZMM LASER NAME')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_logo_cp')
                    ->label('ZMM LOGO CP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_logo_ce')
                    ->label('ZMM LOGO CE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_logo_nsf')
                    ->label('ZMM LOGO NSF')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_logo_eac')
                    ->label('ZMM LOGO EAC')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_beenote')
                    ->label('ZMM BEENOTE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_beenumber')
                    ->label('ZMM BEENUMBER')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_beestar')
                    ->label('ZMM BEESTAR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_codeclass')
                    ->label('ZMM CODECLASS')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_colour')
                    ->label('ZMM COLOUR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grade')
                    ->label('ZMM GRADE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grwt_pset')
                    ->label('ZMM GRWT PSET')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grwt_cable')
                    ->label('ZMM GRWT CABLE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grwt_motor')
                    ->label('ZMM GRWT MOTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grwt_pf')
                    ->label('ZMM GRWT PF')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_grwt_pump')
                    ->label('ZMM GRWT PUMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isivalve')
                    ->label('ZMM ISIVALVE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_isi_wc')
                    ->label('ZMM ISI WC')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_labelperiod')
                    ->label('ZMM LABELPERIOD')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_length')
                    ->label('ZMM LENGTH')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_license_cml_no')
                    ->label('ZMM LICENSE CML NO')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_mfgmonyr')
                    ->label('ZMM MFGMONYR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_modelyear')
                    ->label('ZMM MODELYEAR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motoridentification')
                    ->label('ZMM MOTORIDENTIFICATION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_newt_pset')
                    ->label('ZMM NEWT PSET')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_newt_cable')
                    ->label('ZMM NEWT CABLE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_newt_motor')
                    ->label('ZMM NEWT MOTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_newt_pf')
                    ->label('ZMM NEWT PF')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_newt_pump')
                    ->label('ZMM NEWT PUMP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_packtype')
                    ->label('ZMM PACKTYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_panel')
                    ->label('ZMM PANEL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_performance_factor')
                    ->label('ZMM PERFORMANCE FACTOR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_pumpidentification')
                    ->label('ZMM PUMPIDENTIFICATION')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_psettype')
                    ->label('ZMM PSETTYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_size')
                    ->label('ZMM SIZE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_eff_ttl')
                    ->label('ZMM EFF TTL')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_type')
                    ->label('ZMM TYPE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_usp')
                    ->label('ZMM USP')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_operating_range')
                    ->label('ZMM OPERATING RANGE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_intake_air')
                    ->label('ZMM INTAKE AIR')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_oxygen_transfer_rate')
                    ->label('ZMM OXYGEN TRANSFER RATE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_air_inlet_pipesize')
                    ->label('ZMM AIR INLET PIPESIZE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_sump_depth')
                    ->label('ZMM SUMP DEPTH')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_poles')
                    ->label('ZMM POLES')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motor_heading')
                    ->label('ZMM MOTOR HEADING')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_motor_speed')
                    ->label('ZMM MOTOR SPEED')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zqmm_qty')
                    ->label('ZQMM QTY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_operating_temperature')
                    ->label('ZMM OPERATING TEMPERATURE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('zmm_axial_force')
                    ->label('ZMM AXIAL FORCE')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('winded_serial_number')
                    ->label('WINDED SERIAL NUMBER')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('model_type')
                    ->label('MODEL TYPE')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('has_work_flow_id')
                    ->label('HAS WORK FLOW ID')
                    ->alignCenter()
                    ->sortable()
                    ->formatStateUsing(function ($state) {
                        return match ($state) {
                            '1' => 'Pending Approval',
                            '2' => 'Pending Request',
                            '0' => 'Approved',
                            default => '-',
                        };
                    }),
                Tables\Columns\TextColumn::make('created_at')
                    ->label('CREATED AT')
                    ->alignCenter()
                    ->dateTime()
                    ->sortable(),
                Tables\Columns\TextColumn::make('created_by')
                    ->label('CREATED BY')
                    ->alignCenter()
                    ->sortable(),
                Tables\Columns\TextColumn::make('updated_at')
                    ->label('UPDATED AT')
                    ->alignCenter()
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                Tables\Columns\TextColumn::make('updated_by')
                    ->label('UPDATED BY')
                    ->alignCenter()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                Tables\Columns\TextColumn::make('deleted_at')
                    ->label('DELETED AT')
                    ->alignCenter()
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                Tables\Filters\TrashedFilter::make(),
                Filter::make('advanced_filters')
                    ->label('Advanced Filters')
                    ->form([
                        Select::make('Plant')
                            ->label('Search by Plant Name')
                            ->nullable()
                            ->searchable()
                            ->reactive()
                            ->options(function (callable $get) {
                                $userHas = Filament::auth()->user()->plant_id;

                                if ($userHas && strlen($userHas) > 0) {
                                    return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
                                } else {
                                    return Plant::whereHas('tempClassCharacteristics', function ($query) {
                                        $query->whereNotNull('id');
                                    })->orderBy('code')->pluck('name', 'id');
                                }

                                // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
                            })
                            ->afterStateUpdated(function ($state, callable $set, callable $get): void {
                                $set('machine', null);
                                $set('item_id', null);
                                // $set('aufnr', null);
                            }),
                        Select::make('machine')
                            ->label('Search by Work Center')
                            ->nullable()
                            ->searchable()
                            ->reactive()
                            ->options(function (callable $get) {
                                $plantId = $get('Plant');

                                if (empty($plantId)) {
                                    return [];
                                }

                                return Machine::whereHas('tempClassCharacteristics', function ($query) use ($plantId) {
                                    if ($plantId) {
                                        $query->where('plant_id', $plantId);
                                    }
                                })->pluck('work_center', 'id');
                            })
                            ->afterStateUpdated(function ($state, callable $set, callable $get): void {
                                // $set('item_id', null);
                                // $set('aufnr', null);
                            }),
                        Select::make('item_id')
                            ->label('Search by Item Code')
                            ->nullable()
                            ->searchable()
                            ->reactive()
                            ->options(function (callable $get) {
                                $plantId = $get('Plant');

                                if (empty($plantId)) {
                                    return [];
                                }

                                return Item::whereHas('tempClassCharacteristics', function ($query) use ($plantId) {
                                    if ($plantId) {
                                        $query->where('plant_id', $plantId);
                                    }
                                })->pluck('code', 'id');
                            })
                            ->afterStateUpdated(function ($state, callable $set, callable $get): void {
                                // $set('aufnr', null);
                            }),
                        TextInput::make('aufnr')
                            ->label('Job Number')
                            ->placeholder('Enter Job Number')
                            ->minlength(7)
                            ->maxlength(10),
                        TextInput::make('gernr')
                            ->label('Serial Number')
                            ->placeholder('Enter Serial Number'),
                        TextInput::make('zmm_heading')
                            ->label('Heading')
                            ->placeholder('Enter Heading'),
                        TextInput::make('model_type')
                            ->label('Model Type')
                            ->placeholder('Enter Model Type'),
                        Select::make('work_flow_status')
                            ->label('Work Flow Status')
                            ->placeholder('Select Work Flow Status')
                            ->options([
                                '1' => 'Pending Approval',
                                '2' => 'Pending Request',
                                '0' => 'Approved',
                            ]),
                        DateTimePicker::make(name: 'created_from')
                            ->label('Created From')
                            ->placeholder('Select From DateTime')
                            ->reactive()
                            ->native(false),
                        DateTimePicker::make('created_to')
                            ->label('Created To')
                            ->placeholder('Select To DateTime')
                            ->reactive()
                            ->native(false),
                    ])
                    ->query(function ($query, array $data) {
                        // Hide all records initially if no filters are applied
                        if (empty($data['Plant']) && empty($data['machine']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['gernr']) && empty($data['zmm_heading']) && empty($data['model_type']) && empty($data['created_from']) && empty($data['created_to'])) {
                            return $query->whereRaw('1 = 0');
                        }

                        if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
                            $query->where('plant_id', $data['Plant']);
                        } else {
                            $userHas = Filament::auth()->user()->plant_id;

                            if ($userHas && strlen($userHas) > 0) {
                                return $query->whereRaw('1 = 0');
                            }
                        }

                        if (! empty($data['machine'])) {
                            $query->where('machine_id', $data['machine']);
                        }

                        if (! empty($data['item_id'])) {
                            $query->where('item_id', $data['item_id']);
                        }

                        if (! empty($data['aufnr'])) {
                            $query->where('aufnr', 'like', '%'.$data['aufnr'].'%');
                        }

                        if (! empty($data['gernr'])) {
                            $query->where('gernr', 'like', '%'.$data['gernr'].'%');
                        }

                        if (! empty($data['zmm_heading'])) {
                            $query->where('zmm_heading', 'like', '%'.$data['zmm_heading'].'%');
                        }

                        if (! empty($data['model_type'])) {
                            $query->where('model_type', 'like', '%'.$data['model_type'].'%');
                        }

                        if (array_key_exists('work_flow_status', $data) && $data['work_flow_status'] != '') {
                            $query->where('has_work_flow_id', $data['work_flow_status']);
                        }

                        if (! empty($data['created_from'])) {
                            $query->where('created_at', '>=', $data['created_from']);
                        }

                        if (! empty($data['created_to'])) {
                            $query->where('created_at', '<=', $data['created_to']);
                        }
                    })
                    ->indicateUsing(function (array $data) {
                        $indicators = [];

                        if (! empty($data['Plant'])) {
                            $indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
                        } else {
                            $userHas = Filament::auth()->user()->plant_id;

                            if ($userHas && strlen($userHas) > 0) {
                                return 'Plant: Choose plant to filter records.';
                            }
                        }

                        if (! empty($data['machine'])) {
                            $indicators[] = 'Work Center: '.Machine::where('id', $data['machine'])->value('work_center');
                        }

                        if (! empty($data['item_id'])) {
                            $indicators[] = 'Item Code: '.Item::where('id', $data['item_id'])->value('code');
                        }

                        if (! empty($data['aufnr'])) {
                            $indicators[] = 'Job No: '.$data['aufnr'];
                        }

                        if (! empty($data['gernr'])) {
                            $indicators[] = 'Serial Number: '.$data['gernr'];
                        }

                        if (! empty($data['zmm_heading'])) {
                            $indicators[] = 'Heading: '.$data['zmm_heading'];
                        }

                        if (! empty($data['model_type'])) {
                            $indicators[] = 'Model Type: '.$data['model_type'];
                        }

                        if (array_key_exists('work_flow_status', $data) && $data['work_flow_status'] != '') {
                            $statusMap = [
                                '1' => 'Pending Approval',
                                '2' => 'Pending Request',
                                '0' => 'Approved',
                            ];

                            $indicators[] = 'Work Flow Status: '.($statusMap[$data['work_flow_status']] ?? '');
                        }

                        if (! empty($data['created_from'])) {
                            $indicators[] = 'From: '.$data['created_from'];
                        }

                        if (! empty($data['created_to'])) {
                            $indicators[] = 'To: '.$data['created_to'];
                        }

                        return $indicators;
                    }),
            ])
            ->filtersFormMaxHeight('280px')
            ->actions([
                Tables\Actions\ViewAction::make(),
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                    Tables\Actions\ForceDeleteBulkAction::make(),
                    Tables\Actions\RestoreBulkAction::make(),
                ]),
            ])
            ->headerActions([
                ImportAction::make()
                    ->label('Import Temp Class Characteristics')
                    ->color('warning')
                    ->importer(TempClassCharacteristicImporter::class)
                    ->visible(function () {
                        return Filament::auth()->user()->can('view import temp class characteristic');
                    }),
                ExportAction::make()
                    ->label('Export Temp Class Characteristics')
                    ->color('warning')
                    ->exporter(TempClassCharacteristicExporter::class)
                    ->visible(function () {
                        return Filament::auth()->user()->can('view export temp class characteristic');
                    }),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListTempClassCharacteristics::route('/'),
            'create' => Pages\CreateTempClassCharacteristic::route('/create'),
            'view' => Pages\ViewTempClassCharacteristic::route('/{record}'),
            'edit' => Pages\EditTempClassCharacteristic::route('/{record}/edit'),
        ];
    }

    public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()
            ->withoutGlobalScopes([
                SoftDeletingScope::class,
            ]);
    }
}
