<?php

namespace App\Filament\Resources\Products\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use App\Models\Project;

class ProductsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('project.code')
                    ->label('Dự án')
                    ->sortable()
                    ->searchable(),
                TextColumn::make('code')
                    ->label('Mã SP')
                    ->sortable()
                    ->searchable(),
                TextColumn::make('product_type')
                    ->label('Loại')
                    ->badge(),
                TextColumn::make('total_price')
                    ->label('Giá')
                    ->money('VND')
                    ->sortable(),
                TextColumn::make('status')
                    ->label('Trạng thái')
                    ->badge()
                    ->color(fn (string $state): string => match ($state) {
                        'Đang mở bán' => 'success',
                        'Đã cọc' => 'warning',
                        'Đã bán' => 'danger',
                        default => 'gray',
                    }),
            ])
            ->filters([
                SelectFilter::make('project_id')
                    ->label('Dự án')
                    ->relationship('project', 'name'),
                SelectFilter::make('status')
                    ->label('Trạng thái')
                    ->options([
                        'Đang mở bán' => 'Đang mở bán',
                        'Đã cọc' => 'Đã cọc',
                        'Đã bán' => 'Đã bán',
                    ]),
                SelectFilter::make('product_type')
                    ->label('Loại sản phẩm')
                    ->options(\App\Enums\ProductType::class),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
