<?php

namespace App\Filament\Resources;

use App\Filament\Resources\UsdtC2cResource\Pages;
use App\Filament\Resources\UsdtC2cResource\RelationManagers;
use App\Models\UsdtC2c;
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;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\DatePicker;

class UsdtC2cResource extends Resource
{
    protected static ?string $model = UsdtC2c::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function getNavigationGroup(): ?string
    {
        return '财务管理'; // ⚠️ 注意这要与其他项的 group 完全一致
    }

    public static function getNavigationIcon(): string
    {
        return 'heroicon-o-currency-bangladeshi'; // 或自定义你喜欢的图示
    }

    public static function getNavigationLabel(): string
    {
        return 'USDT-LAK 记录';
    }

    public static function getPluralLabel(): string
    {
        return 'USDT-LAK 记录';
    }


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

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('Highest')->label('最高价'),
                TextColumn::make('Million')->label('200万成交价'),
                TextColumn::make('created_at')->label('时间')->dateTime(),
            ])
            ->filters([
                Filter::make('created_at')
                    ->form([
                        DatePicker::make('from'),
                        DatePicker::make('until'),
                    ])
                    ->query(function ($query, array $data) {
                        return $query
                            ->when($data['from'], fn ($q) => $q->where('created_at', '>=', $data['from']))
                            ->when($data['until'], fn ($q) => $q->where('created_at', '<=', $data['until']));
                    }),
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ])
            ->defaultSort('Highest', 'desc'); // ✅ 放在这里才对
    }

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

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