columns([ TextColumn::make('name') ->label(__('Name')) ->searchable() ->sortable(), TextColumn::make('code') ->label(__('Code')) ->badge() ->copyable() ->sortable(), TextColumn::make('type') ->label(__('Type')) ->badge() ->formatStateUsing(fn ($state) => Str::headline($state)) ->sortable(), TextColumn::make('amount') ->label(__('Amount')) ->formatStateUsing(fn ($state, $record) => $record->type === CouponType::PERCENTAGE ? sprintf('%s%%', $record->amount) : sprintf('%s %s', number_format($record->amount, 2), strtoupper($record->currency ?? 'EUR'))) ->sortable(), TextColumn::make('redemptions_count') ->label(__('Redeemed')) ->badge() ->sortable(), IconColumn::make('enabled_for_checkout') ->label(__('Checkout')) ->boolean(), TextColumn::make('status') ->label(__('Status')) ->badge() ->sortable() ->formatStateUsing(fn ($state) => Str::headline($state)), TextColumn::make('starts_at') ->label(__('Starts')) ->date() ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('ends_at') ->label(__('Ends')) ->date() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ SelectFilter::make('status') ->label(__('Status')) ->options( collect(CouponStatus::cases())->mapWithKeys(fn ($status) => [$status->value => $status->label()])->all() ), SelectFilter::make('type') ->label(__('Type')) ->options( collect(CouponType::cases())->mapWithKeys(fn ($type) => [$type->value => $type->label()])->all() ), TernaryFilter::make('is_active') ->label(__('Currently active')) ->placeholder(__('All')) ->queries( true: fn ($query) => $query->active(), false: fn ($query) => $query->where(function ($inner) { $inner->where('status', '!=', CouponStatus::ACTIVE->value) ->orWhere(function ($sub) { $sub->whereNotNull('ends_at') ->where('ends_at', '<', now()); }); }), ), TrashedFilter::make(), ]) ->recordActions([ ViewAction::make(), EditAction::make(), Action::make('sync') ->label(__('Sync to Paddle')) ->icon('heroicon-m-arrow-path') ->action(fn ($record) => SyncCouponToPaddle::dispatch($record)) ->requiresConfirmation(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ForceDeleteBulkAction::make(), RestoreBulkAction::make(), ]), ]); } }