<?php

namespace App\Filament\Resources;

use App\Filament\Resources\TagResource\Pages;
use App\Models\Tag;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class TagResource extends Resource
{
    protected static ?string $model = Tag::class;

    protected static ?string $navigationIcon = 'heroicon-o-tag';
    protected static ?string $navigationGroup = 'مدیریت مشتریان (CRM)';
    protected static ?string $navigationLabel = 'برچسب‌ها';
    protected static ?string $modelLabel = 'برچسب';
    protected static ?string $pluralModelLabel = 'برچسب‌ها';
    protected static ?int $navigationSort = 3;

    public static function form(Form $form): Form
    {
        return $form->schema([
            Forms\Components\TextInput::make('name')->label('نام برچسب')->required()->unique(ignoreRecord: true),
            Forms\Components\Select::make('color')->label('رنگ')->options([
                'gray' => 'خاکستری', 'success' => 'سبز', 'warning' => 'نارنجی',
                'danger' => 'قرمز', 'info' => 'آبی', 'primary' => 'فیروزه‌ای',
            ])->default('gray'),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name')->label('نام')->badge()
                    ->color(fn ($record) => $record->color),
                Tables\Columns\TextColumn::make('customers_count')->label('تعداد مشتری')->counts('customers'),
            ])
            ->actions([Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make()]);
    }

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