columns(2) ->components([ Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) ->default(fn (): ?int => Property::query()->where('is_active', true)->value('id')) ->required() ->columnSpanFull() ->hidden(fn (): bool => Property::query()->count() <= 1) ->dehydratedWhenHidden(), DatePicker::make('starts_on')->label('Von (erste gesperrte Nacht)')->required(), DatePicker::make('ends_on')->label('Bis (erster freier Tag)')->after('starts_on')->required(), TextInput::make('reason') ->label('Grund') ->placeholder('z. B. Eigennutzung, Renovierung') ->maxLength(255) ->columnSpanFull(), ]); } public static function table(Table $table): Table { return $table ->description('Zeiträume, in denen die Wohnung nicht vermietet wird. Belegungen aus Portalen erscheinen hier automatisch.') ->defaultSort('starts_on') ->columns([ TextColumn::make('starts_on')->label('Von')->date('D, d.m.Y')->sortable(), TextColumn::make('ends_on')->label('Bis')->date('D, d.m.Y'), TextColumn::make('reason')->label('Grund')->placeholder('–'), TextColumn::make('property.name')->label('Wohnung')->visible(fn (): bool => Property::query()->count() > 1), TextColumn::make('source') ->label('Quelle') ->formatStateUsing(fn (string $state): string => match ($state) { 'manual' => 'von Hand', 'channel' => 'Portal-Kalender', 'email' => 'Portal-E-Mail', default => $state, }) ->badge(), ]) ->filters([ Filter::make('upcoming') ->label('Nur kommende') ->default() ->query(fn (Builder $query): Builder => $query->whereDate('ends_on', '>=', today())), ]) ->recordActions([ EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'), DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'), ]); } public static function getPages(): array { return [ 'index' => ManageBlockedPeriods::route('/'), ]; } }