records(fn (?string $search, ?string $sortColumn, ?string $sortDirection, int|string $page, int|string $recordsPerPage) => $service->paginate( search: $search, sortColumn: $sortColumn, sortDirection: $sortDirection, page: (int) $page, perPage: (int) $recordsPerPage, )) ->columns([ TextColumn::make('driver_code')->label('Kode')->sortable(), TextColumn::make('name')->label('Nama')->searchable()->sortable(), TextColumn::make('phone')->label('Telepon'), IconColumn::make('is_active')->label('Aktif')->boolean(), TextColumn::make('notes')->label('Catatan')->limit(30), ]) ->headerActions([ CreateAction::make() ->schema(fn (Schema $schema): Schema => $schema->components(self::driverFormSchema())) ->using(function (array $data): void { $data['is_active'] = true; app(DriverService::class)->create($data); }), ]) ->recordActions([ EditAction::make() ->schema(fn (Schema $schema): Schema => $schema->components(self::driverFormSchema(withStatus: true))) ->fillForm(fn (array $record): array => $record) ->action(function (array $data, array $record): void { $data['is_active'] = (bool) ($data['is_active'] ?? true); app(DriverService::class)->update($record['id'], $data); }), Action::make('hapus') ->label('Hapus') ->color('danger') ->icon('heroicon-o-trash') ->requiresConfirmation() ->modalDescription('Yakin menghapus pengemudi ini?') ->action(function (array $record): void { app(DriverService::class)->delete($record['id']); }), ]) ->paginated([10, 25, 50]); } /** * @return list */ private static function driverFormSchema(bool $withStatus = false): array { return [ TextInput::make('driver_code')->label('Kode')->default(fn () => app(DriverService::class)->nextCode())->required()->maxLength(20), TextInput::make('name')->label('Nama Pengemudi')->required()->maxLength(150), TextInput::make('phone')->label('Telepon')->tel()->maxLength(30), Textarea::make('notes')->label('Catatan')->columnSpanFull(), ...($withStatus ? [Select::make('is_active')->label('Status')->options([1 => 'Aktif', 0 => 'Nonaktif'])->default(1)->required()] : []), ]; } public function content(Schema $schema): Schema { return $schema ->components([ EmbeddedTable::make(), ]); } }