<?php

namespace App\Filament\Customer\Resources;

use App\Enums\IconEnum;
use App\Filament\Customer\Resources\OrderResource\Pages;
use App\Models\Order;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;

class OrderResource extends Resource
{
    protected static ?string $model = Order::class;

    protected static ?string $navigationIcon = IconEnum::ORDER->value;

    public static function infolist(Infolist $infolist): Infolist
    {
        return $infolist
            ->schema([
                TextEntry::make('internal_po'),
                TextEntry::make('customer_po'),
                TextEntry::make('order_date'),
                TextEntry::make('due_date'),
                TextEntry::make('status'),
            ]);
    }

    public static function table(Table $table): Table
    {
        return \App\Filament\Admin\Resources\OrderResource::table($table)
            ->modifyQueryUsing(function (Builder $query) {
                return $query->where('customer_id', auth()->user()->customer_id);
            })
            ->actions([
                ViewAction::make(),
            ])
            ->bulKActions([]);
    }

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

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