<?php

namespace App\Filament\Resources\Branches\Pages;

use Filament\Actions\DeleteAction;
use App\Filament\Resources\Branches\BranchResource;
use App\Filament\Resources\Clients\ClientResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Database\Eloquent\Model;

class EditBranch extends EditRecord
{
    protected static string $resource = BranchResource::class;

    public function mutateFormDataBeforeFill(array $data): array
    {
        $data['series'] = $this->getRecord()->current_series;

        return $data;
    }

    public function handleRecordUpdate(Model $record, array $data): Model
    {
        $data['client_id'] = $record->client_id;
        $data['id'] = $record->id;

        return ClientResource::saveBranch($data);
    }

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