<?php

namespace App\Filament\Resources;

use App\Filament\Resources\AlbumCategoryResource\Pages;
use App\Filament\Resources\AlbumCategoryResource\RelationManagers;
use App\Models\AlbumCategory;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
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;
use App\Service\DeepLService;

class AlbumCategoryResource extends Resource
{
    protected static ?string $model = AlbumCategory::class;
    protected static ?string $modelLabel = "影音類別管理";
    protected static ?string $navigationIcon = 'heroicon-o-rectangle-group';
    protected static ?string $navigationGroup = '最新消息';
    protected static ?string $navigationLabel = "影音類別管理";

    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"])
                    ->actions([
                        app(DeepLService::class)->createTranslationAction("Main", ["name"])
                    ])->columnSpan(5),
                ])->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(),
                ]),
            ])
            ->reorderable('order')
            ->defaultSort('order');
    }

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

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