components([ Grid::make() ->schema([ Section::make(__('surgery_appointments.sections.info')) ->schema([ Select::make('patient_id') ->label(__('surgery_appointments.fields.patient')) ->options(fn () => Patient::all()->mapWithKeys( fn ($p) => [$p->id => $p->full_name] )->toArray()) ->searchable() ->required(), Select::make('surgery_center_id') ->label(__('surgery_appointments.fields.surgery_center')) ->options(fn () => SurgeryCenter::pluck('name', 'id')->toArray()) ->searchable() ->required(), DatePicker::make('surgery_date_date') ->label(__('surgery_appointments.fields.surgery_date')) ->jalali() ->minDate(today()) ->required(), TimePicker::make('surgery_date_time') ->label(__('surgery_appointments.fields.surgery_time')) ->native(false) ->seconds(false) ->minutesStep(15) ->default('09:00'), ]) ->columns(2) ->columnSpanFull() ->footerActions([ fn (string $operation) => Action::make('create') ->label(__('filament-panels::resources/pages/create-record.form.actions.create.label')) ->submit('create') ->keyBindings(['mod+s']) ->visible($operation === 'create'), fn (string $operation) => Action::make('createAnother') ->label(__('filament-panels::resources/pages/create-record.form.actions.create_another.label')) ->action('createAnother') ->keyBindings(['mod+shift+s']) ->color('gray') ->visible($operation === 'create'), fn (string $operation) => Action::make('cancelCreate') ->label(__('filament-panels::resources/pages/create-record.form.actions.cancel.label')) ->url(static::getUrl('index')) ->color('gray') ->visible($operation === 'create'), fn (string $operation) => Action::make('save') ->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label')) ->submit('save') ->keyBindings(['mod+s']) ->visible($operation === 'edit'), fn (string $operation) => Action::make('cancelEdit') ->label(__('filament-panels::resources/pages/edit-record.form.actions.cancel.label')) ->url(static::getUrl('index')) ->color('gray') ->visible($operation === 'edit'), ]), ]) ->columnSpanFull(), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('patient.first_name') ->label(__('surgery_appointments.fields.patient')) ->formatStateUsing(fn ($record) => $record->patient?->full_name ?? '-') ->searchable() ->sortable(), TextColumn::make('surgeryCenter.name') ->label(__('surgery_appointments.fields.surgery_center')) ->searchable() ->sortable() ->placeholder('-'), TextColumn::make('surgery_date') ->label(__('surgery_appointments.fields.surgery_date')) ->formatStateUsing(function ($state) { if (! $state) { return '-'; } try { $date = \Carbon\Carbon::parse($state); return Jalalian::fromCarbon($date)->format('Y/m/d - H:i'); } catch (\Exception $e) { return $state; } }) ->sortable(), TextColumn::make('creator.name') ->label(__('surgery_appointments.fields.created_by')) ->placeholder('-'), TextColumn::make('created_at') ->label(__('surgery_appointments.fields.created_at')) ->sortable(), ]) ->defaultSort('surgery_date', 'desc') ->recordActions([ EditAction::make(), DeleteAction::make(), ]) ->toolbarActions([ DeleteBulkAction::make(), ]); } public static function getPages(): array { return [ 'index' => Pages\ListSurgeryAppointments::route('/'), 'create' => Pages\CreateSurgeryAppointment::route('/create'), 'edit' => Pages\EditSurgeryAppointment::route('/{record}/edit'), ]; } }