<?php

declare(strict_types=1);

namespace App\Filament\Resources\UserDevices;

use App\Filament\Resources\UserDevices\Pages\ListUserDevices;
use App\Filament\Resources\UserDevices\Tables\UserDevicesTable;
use App\Filament\Support\NavigationBadge;
use App\Models\UserDevice;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Tables\Table;
use UnitEnum;

class UserDeviceResource extends Resource
{
    protected static ?string $model = UserDevice::class;

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

    protected static ?string $navigationLabel = 'دستگاه‌های کاربران';

    protected static ?string $modelLabel = 'دستگاه';

    protected static ?string $pluralModelLabel = 'دستگاه‌های کاربران';

    protected static string|null|UnitEnum $navigationGroup = 'کاربران';

    protected static ?int $navigationSort = 5;

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

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

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

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