<?php

namespace App\Filament\Resources;

use App\Filament\Resources\NewsCategoryResource\Pages;
use App\Models\NewsCategory;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;

class NewsCategoryResource extends Resource
{
    protected static ?string $model = NewsCategory::class;
    protected static ?string $modelLabel = "文章分類管理";
    protected static ?string $navigationIcon = 'heroicon-o-rectangle-group';
    protected static ?string $navigationGroup = '上稿內容管理';
    protected static ?string $navigationLabel = "文章分類管理";

    use Translatable;
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                //
                Section::make("")->schema([
                    Translate::make()->schema(fn (string $locale) => [
                        TextInput::make('name')->required($locale == 'zh_TW')->maxLength(40)->label("分類名稱")
                    ])
                    ->locales(["zh_TW", "en"])
                    ->columnSpan(5),
                    TextInput::make('order')->label("排序")->integer()->default(0)->columnSpan(1)
                ])->columns(4)
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                //
                TextColumn::make('name')->label("分類名稱"),
                TextColumn::make(name: 'created_at')->label("建立時間")->date(),
                TextColumn::make('updated_at')->label("更新時間")->date()
            ])
            ->filters([
                //
            ])
            ->actions([
                // Tables\Actions\ViewAction::make(),
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make()
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ])
            ->defaultSort('order', 'desc')
            ->defaultSort('created_at', 'desc');
    }

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

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListNewsCategories::route('/'),
            'create' => Pages\CreateNewsCategory::route('/create'),
            'edit' => Pages\EditNewsCategory::route('/{record}/edit'),
        ];
    }
}
