<?php

namespace App\Filament\Resources;

use App\Filament\Resources\LedgerResource\Pages;
use App\Filament\Resources\LedgerResource\RelationManagers;
use App\Models\Ledger;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class LedgerResource extends Resource
{
    protected static ?string $model = Ledger::class;
    protected static ?string $navigationLabel = '财务账本';
    protected static ?string $pluralLabel = '财务账本';
    protected static ?string $label = '账本';
    protected static ?string $navigationGroup = '财务管理';
    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                //
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('id')->label('ID')->sortable(),
                Tables\Columns\TextColumn::make('chat_id')->label('群ID')->searchable(),
                Tables\Columns\TextColumn::make('user_id')->label('用户ID')->searchable(),
                Tables\Columns\TextColumn::make('type')->label('类型')->formatStateUsing(fn ($state) => $state === 0 ? '收入' : '支出')->sortable(),
                Tables\Columns\TextColumn::make('date')->label('记账时间')->dateTime()->sortable(),
                Tables\Columns\TextColumn::make('amount')->label('金额')->money('LAK')->sortable(),
                Tables\Columns\TextColumn::make('created_at')->label('创建时间')->dateTime()->since(),
                Tables\Columns\TextColumn::make('updated_at')->label('更新时间')->dateTime()->since(),
                ])
            ->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\ListLedgers::route('/'),
            'create' => Pages\CreateLedger::route('/create'),
            'edit' => Pages\EditLedger::route('/{record}/edit'),
        ];
    }
}
