<?php

namespace App\Filament\Widgets;

use App\Models\PengajuanSurat;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class RecentPengajuanSurat extends BaseWidget
{
    protected int | string | array $columnSpan = 'full';

    protected function getTableHeading(): string
    {
        return 'Pengajuan Surat Terbaru (Pending)';
    }

    public function table(Table $table): Table
    {
        return $table
            ->query(
                PengajuanSurat::where('status', 'Pending')->latest()->limit(10)
            )
            ->columns([
                TextColumn::make('nomor_tiket')
                    ->label('Tiket')
                    ->searchable(),
                TextColumn::make('nama_lengkap')
                    ->label('Nama')
                    ->searchable(),
                TextColumn::make('jenis_surat')
                    ->label('Jenis Surat'),
                BadgeColumn::make('status')
                    ->label('Status')
                    ->colors([
                        'warning' => 'Pending',
                        'primary' => 'Diproses',
                        'success' => 'Selesai',
                    ]),
                TextColumn::make('created_at')
                    ->label('Tanggal')
                    ->dateTime('d M Y H:i'),
            ])
            ->recordActions([
                ViewAction::make()
                    ->label('Lihat')
                    ->url(fn (PengajuanSurat $record): string => \App\Filament\Resources\PengajuanSurats\PengajuanSuratResource::getUrl('edit', ['record' => $record])),
            ])
            ->paginated(false);
    }
}
