components([ TextInput::make('name')->label('Name')->required()->maxLength(120)->helperText('z. B. „Direktbuchung“ oder „FeWo-direkt“.'), Select::make('base') ->label('Berechnungsgrundlage') ->options([CancellationPolicy::BASE_RENT => 'Mietpreis (ohne Endreinigung, Service und Kurtaxe)', CancellationPolicy::BASE_TOTAL => 'Gesamtpreis']) ->default(CancellationPolicy::BASE_RENT) ->required(), Repeater::make('tiers') ->label('Stufen') ->helperText('Jede Stufe gilt, wenn bis zur Anreise mindestens so viele Tage bleiben. Beispiel: ab 60 Tagen 0 %, ab 30 Tagen 50 %, ab 0 Tagen 100 %. Die letzte Stufe (0 Tage) gilt für alles danach.') ->schema([ TextInput::make('min_days')->label('Ab Tagen vor Anreise')->integer()->minValue(0)->required(), TextInput::make('percent')->label('Entschädigung')->integer()->minValue(0)->maxValue(100)->suffix('%')->required(), ]) ->columns(2) ->default([['min_days' => 60, 'percent' => 0], ['min_days' => 30, 'percent' => 50], ['min_days' => 0, 'percent' => 100]]) ->minItems(1) ->required() ->columnSpanFull(), EuroInput::make('replacement_fee')->label('Gebühr bei Ersatzmieter (optional)'), Text::make(fn (?CancellationPolicy $record): HtmlString => new HtmlString($record ? 'So steht es im Vertrag ({{ storno_regel }}):' : ''))->columnSpanFull(), Textarea::make('notes')->label('Interne Notiz')->rows(2)->columnSpanFull(), ]); } public static function table(Table $table): Table { return $table ->defaultSort('name') ->columns([ TextColumn::make('name')->label('Regel')->weight('medium')->searchable(), TextColumn::make('base')->label('Grundlage')->formatStateUsing(fn (string $state): string => $state === CancellationPolicy::BASE_TOTAL ? 'Gesamtpreis' : 'Mietpreis'), TextColumn::make('steps')->label('Stufen')->state(fn (CancellationPolicy $record): string => collect(CancellationPolicy::normalise((array) $record->tiers))->map(fn (array $tier): string => 'ab '.$tier['min_days'].' T: '.$tier['percent'].' %')->implode(' · ')), ]) ->recordActions([EditAction::make(), DeleteAction::make()]); } public static function getPages(): array { return [ 'index' => ListCancellationPolicies::route('/'), 'create' => CreateCancellationPolicy::route('/create'), 'edit' => EditCancellationPolicy::route('/{record}/edit'), ]; } }