<?php

namespace App\Filament\Resources;

use App\Filament\Resources\InvoiceReportResource\Pages;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Support\Enums\FontFamily;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class InvoiceReportResource extends Resource
{
    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    protected static ?string $navigationGroup = 'Reports';

    protected static ?string $navigationLabel = 'Invoice Reports';

    protected static ?int $navigationSort = 2;

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

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('id')
                    ->formatStateUsing(fn ($state) => 'TN-INR-'.$state)
                    ->fontFamily(FontFamily::Mono)
                    ->color('primary'),
                TextColumn::make('customer.company_name'),
                TextColumn::make('date_start')
                    ->date('Y-m-d'),
                TextColumn::make('date_end')
                    ->date('Y-m-d'),
            ])
            ->defaultSort('created_at', 'asc')

            ->filters([
            ])
            ->actions([]);
        //            ->defaultGroup(
        //                Group::make('date')
        //                    ->getKeyFromRecordUsing(fn (Order $record): string => $record->invoice->date->format('Y-m-0'))
        //                    ->getTitleFromRecordUsing(fn (Order $record): string => $record->invoice->date->format('F Y'))
        //                    ->orderQueryUsing(function (Builder $query) {
        //
        //                        return $query->join('invoices', 'orders.invoice_id', '=', 'invoices.id')
        //                            ->orderBy('invoices.date', 'desc');
        //                    })
        //                    ->titlePrefixedWithLabel(false),
        //            );
    }

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

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListInvoiceReports::route('/'),
        ];
    }
}
