<?php

namespace App\Filament\Resources\BranchResource\Pages;

use App\Filament\Resources\BranchResource;
use App\Filament\Resources\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 [
            Actions\DeleteAction::make(),
        ];
    }
}
