<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectRequests;

use App\Filament\Resources\ProjectRequests\Pages\ListProjectRequests;
use App\Filament\Resources\ProjectRequests\Pages\ViewProjectRequest;
use App\Filament\Resources\ProjectRequests\Tables\ProjectRequestsTable;
use App\Filament\Support\NavigationBadge;
use App\Models\ProjectRequest;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use UnitEnum;

class ProjectRequestResource extends Resource
{
    protected static ?string $model = ProjectRequest::class;

    protected static string|BackedEnum|null $navigationIcon = \Filament\Support\Icons\Heroicon::OutlinedClipboardDocumentList;

    protected static ?string $navigationLabel = 'درخواست‌های پروژه';

    protected static ?string $modelLabel = 'درخواست پروژه';

    protected static ?string $pluralModelLabel = 'درخواست‌های پروژه';

    protected static string|null|UnitEnum $navigationGroup = 'پروژه‌ها و سفارشات';

    protected static ?int $navigationSort = 2;

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

    public static function getPages(): array
    {
        return [
            'index' => ListProjectRequests::route('/'),
            'view' => ViewProjectRequest::route('/{record}'),
        ];
    }

    public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
    {
        return $record->title ?? ('درخواست #' . $record->id);
    }

    public static function getNavigationBadge(): ?string
    {
        return NavigationBadge::fromQuery(
            fn () => static::getModel()::query()->where('status', ProjectRequest::STATUS_WAITING)
        );
    }

    public static function getNavigationBadgeColor(): ?string
    {
        return NavigationBadge::colorFromQuery(
            fn () => static::getModel()::query()->where('status', ProjectRequest::STATUS_WAITING)
        );
    }
}
