<?php

namespace App\Filament\Resources\BranchResource\RelationManagers;

use App\Filament\Resources\ExpenseResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Actions\CreateAction;
use Filament\Tables\Table;

class ExpenseRelationManager extends RelationManager
{
    protected static string $relationship = 'expenses';

    public function form(Form $form): Form
    {
        return $form
            ->schema(ExpenseResource::getExpenseFormFields());
    }

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('branch_id')
            ->columns(ExpenseResource::getTableColumns())
            ->headerActions([
                CreateAction::make()
                    ->mutateFormDataUsing(
                        fn (array $data): array => app(ExpenseResource\Pages\CreateExpense::class)
                            ->getFormDataMutation($data)
                    ),
            ]);
    }
}
