<?php

namespace App\Filament\Resources;

use App\Filament\Resources\NewsCategoryResource\Pages;
use App\Filament\Resources\NewsCategoryResource\RelationManagers;
use App\Models\NewsCategory;
use App\Service\DeepLService;
use Filament\Forms;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;

class NewsCategoryResource extends Resource
{
    protected static ?string $model = NewsCategory::class;

    protected static ?string $navigationIcon = 'heroicon-o-newspaper';
    protected static ?string $navigationLabel = "最新消息分類管理";
    protected static ?string $navigationGroup = '最新消息';
    protected static ?string $modelLabel = "最新消息分類管理";
    protected static ?int $navigationSort = 3;

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make("")->schema([
                    Group::make()->schema([
                        Translate::make()->schema(fn (string $locale) => [
                            TextInput::make('name')->required($locale == 'zh_TW')->maxLength(40)->label("分類名稱")->columnSpan(1)
                        ])
                        ->locales(["zh_TW", "en"])
                        ->actions([
                            app(DeepLService::class)->createTranslationAction("Main", ["name"])
                        ])->columnSpan(2),
                    ])->columns(4)->columnSpanFull(),
                    Group::make()->schema([
                        TextInput::make('order')->label("排序")->integer()->default(0)->columnSpan(1)
                    ])->columnSpanFull()->columns(4),
                ])->columns(4)
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make("name")->label("分類名稱"),
                TextColumn::make("visible_str")->label("顯示/不顯示")
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    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'),
        ];
    }
}
