<?php

namespace App\Filament\Membre\Resources\Annonces;

use App\Filament\Membre\Resources\Annonces\Pages\CreateAnnonce;
use App\Filament\Membre\Resources\Annonces\Pages\EditAnnonce;
use App\Filament\Membre\Resources\Annonces\Pages\ListAnnonces;
use App\Filament\Membre\Resources\Annonces\Schemas\AnnonceForm;
use App\Filament\Membre\Resources\Annonces\Tables\AnnoncesTable;
use App\Models\Annonce;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;

class AnnonceResource extends Resource
{
    protected static ?string $model = Annonce::class;

    protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;

    protected static ?string $recordTitleAttribute = 'Annonce-membre';

    public static function form(Schema $schema): Schema
    {
        return AnnonceForm::configure($schema);
    }

    public static function table(Table $table): Table
    {
        return AnnoncesTable::configure($table);
    }

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

    public static function getPages(): array
    {
        return [
            'index'  => Pages\ListAnnonces::route('/'),
            'create' => Pages\CreateAnnonce::route('/create'),
            'view'   => Pages\ViewAnnonce::route('/{record}'),
            'edit'   => Pages\EditAnnonce::route('/{record}/edit'),
        ];
    }
    public static function getEloquentQuery(): \Illuminate\Database\Eloquent\Builder
{
    return parent::getEloquentQuery()->where('user_id', auth()->id());
}

protected static ?string $navigationLabel = 'Mes annonces';
protected static ?string $modelLabel = 'annonce';
protected static ?string $pluralModelLabel = 'mes annonces';

public static function canEdit(\Illuminate\Database\Eloquent\Model $record): bool
{
    return in_array($record->statut, [
        \App\Enums\StatutAnnonce::Brouillon,
        \App\Enums\StatutAnnonce::EnAttentePaiement,
    ]);
}



}
