<?php

namespace App\Filament\Resources\Clients\RelationManagers;

use Filament\Schemas\Schema;
use Filament\Actions\Action;
use App\Filament\Resources\Expenses\ExpenseResource;
use App\Models\Expense;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

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

    protected static ?string $title = 'Expenses';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([]);
    }

    public function table(Table $table): Table
    {
        return ExpenseResource::table($table)->headerActions([
            Action::make('New Expense')->action('openCreateForm'),
        ]);
    }

    public function openCreateForm()
    {
        return redirect()->route('filament.admin.resources.expenses.create', ['client_id' => $this->getOwnerRecord()->id]);
    }
}
