<?php

namespace App\Filament\Resources\Codes\PaymentPurposeCodes\PaymentPurposeCodes;

use Filament\Schemas\Schema;
use Filament\Actions\EditAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use App\Filament\Resources\Codes\PaymentPurposeCodes\Pages\ListPaymentPurposeCodes;
use App\Filament\Resources\Codes\PaymentPurposeCodes\Pages\CreatePaymentPurposeCode;
use App\Filament\Resources\Codes\PaymentPurposeCodes\Pages\EditPaymentPurposeCode;
use App\Filament\Resources\Codes\PaymentPurposeCodeResource\Pages;
use App\Modules\PaymentPurposeCode\Models\PaymentPurposeCode;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class PaymentPurposeCodeResource extends Resource
{
    protected static ?string $model = PaymentPurposeCode::class;

    protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-cube';

    protected static string | \UnitEnum | null $navigationGroup = 'Settings';

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('code')
                    ->integer()
                    ->unique()
                    ->required()
                    ->rules('max:255'),

                TextInput::make('name')
                    ->unique()
                    ->required()
                    ->rules('max:255'),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('id')
                    ->label(__('ID'))
                    ->sortable(),

                TextColumn::make('code')
                    ->sortable()
                    ->searchable(),

                TextColumn::make('name')
                    ->sortable()
                    ->searchable(),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => ListPaymentPurposeCodes::route('/'),
            'create' => CreatePaymentPurposeCode::route('/create'),
            'edit' => EditPaymentPurposeCode::route('/{record}/edit'),
        ];
    }
}
