<?php

namespace App\Filament\Resources\AdoptionApplications;

use App\Filament\Resources\AdoptionApplications\Pages\CreateAdoptionApplication;
use App\Filament\Resources\AdoptionApplications\Pages\EditAdoptionApplication;
use App\Filament\Resources\AdoptionApplications\Pages\ListAdoptionApplications;
use App\Filament\Resources\AdoptionApplications\Pages\ViewApplicationHistory;
use App\Filament\Resources\AdoptionApplications\Schemas\AdoptionApplicationForm;
use App\Filament\Resources\AdoptionApplications\Tables\AdoptionApplicationsTable;
use App\Models\AdoptionApplication;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use UnitEnum;

class AdoptionApplicationResource extends Resource
{
    protected static ?string $model = AdoptionApplication::class;

    protected static ?string $panel = 'admin';

    protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;

    protected static UnitEnum|string|null $navigationGroup = 'Adoption Process';

    protected static ?int $navigationSort = 1;

    public static function shouldRegisterNavigation(): bool
    {
        return filament()->getCurrentPanel()->getId() === 'admin';
    }

    public static function form(Schema $schema): Schema
    {
        return AdoptionApplicationForm::configure($schema);
    }

    public static function table(Table $table): Table
    {
        return AdoptionApplicationsTable::configure($table);
    }

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

    public static function getNavigationBadge(): ?string
    {
        $count = AdoptionApplication::query()
            ->where('status', 'submitted')
            ->count();

        return $count > 0 ? (string) $count : null;
    }

    public static function getNavigationBadgeColor(): ?string
    {
        return 'success';
    }

    public static function getPages(): array
    {
        return [
            'index' => ListAdoptionApplications::route('/'),
            'create' => CreateAdoptionApplication::route('/create'),
            'edit' => EditAdoptionApplication::route('/{record}/edit'),
            'history' => ViewApplicationHistory::route('/{record}/history'),
        ];
    }
}
