label('Refund') ->icon(Heroicon::OutlinedReceiptRefund) ->color('danger') ->visible(fn (): bool => auth()->user()?->can('process_refunds') ?? false) ->disabled(fn (Booking $record): bool => $record->status !== BookingStatus::Confirmed) ->schema([ Toggle::make('full_refund') ->label('Full refund') ->live() ->default(true) ->helperText(fn (Booking $record): string => 'Refundable balance: '.(app(RefundBookingAction::class) ->resolveRefundablePayment($record)?->refundableBalance() ?? '0.00')), TextInput::make('amount') ->numeric() ->minValue(0.01) ->visible(fn (Get $get): bool => ! $get('full_refund')) ->required(fn (Get $get): bool => ! $get('full_refund')) ->maxValue(fn (Booking $record): ?string => app(RefundBookingAction::class) ->resolveRefundablePayment($record)?->refundableBalance()), Textarea::make('reason') ->required(), ]) ->action(function (Booking $record, array $data): void { $amount = $data['full_refund'] ? app(RefundBookingAction::class)->resolveRefundablePayment($record)?->refundableBalance() ?? '0.00' : (string) $data['amount']; try { app(RefundBookingAction::class)->handle( $record, $amount, $data['reason'], auth()->id(), ); Notification::make() ->title('Refund processed') ->success() ->send(); } catch (RefundNotAllowedException|RefundFailedException $exception) { Notification::make() ->title('Refund failed') ->body($exception->getMessage()) ->danger() ->send(); } }); } }