<?php

namespace Modules\Routing\Filament\Resources\EvRoutes\Pages;

use Filament\Actions\DeleteAction;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Modules\Routing\Filament\Resources\EvRoutes\EvRouteResource;

class EditEvRoute extends EditRecord
{
    protected static string $resource = EvRouteResource::class;

    protected function getHeaderActions(): array
    {
        return [
            DeleteAction::make(),
        ];
    }

    protected function beforeSave(): void
    {
        if (
            ($this->data['is_active'] ?? false)
            && ! EvRouteResource::hasCompletePricingData($this->data['pricing'] ?? [])
        ) {
            Notification::make()
                ->warning()
                ->title('Route cannot be activated yet')
                ->body('Set a price above 0 for every non-blocked vehicle option first, then activate the route.')
                ->send();

            $this->halt();
        }
    }
}
