<?php

namespace App\Filament\Resources\PolicyResource\Pages;

use App\Filament\Resources\PolicyResource;
use App\Support\Filament\CanonicalAdminEnvironmentFilterState;
use Filament\Resources\Pages\ListRecords;

class ListPolicies extends ListRecords
{
    protected static string $resource = PolicyResource::class;

    public function mount(): void
    {
        $this->syncCanonicalAdminEnvironmentFilterState();

        parent::mount();
    }

    protected function getHeaderActions(): array
    {
        return [
            PolicyResource::makeSyncAction(),
        ];
    }

    protected function getTableEmptyStateActions(): array
    {
        return [
            PolicyResource::makeSyncAction(),
        ];
    }

    private function syncCanonicalAdminEnvironmentFilterState(): void
    {
        app(CanonicalAdminEnvironmentFilterState::class)->sync(
            $this->getTableFiltersSessionKey(),
            environmentSensitiveFilters: [],
            request: request(),
            environmentFilterName: null,
        );
    }
}
