<?php

namespace App\Filament\Pages\Analytic\Actions;

use Filament\Actions\Action;

class ResetFiltersAction extends Action
{
    public static function getDefaultName(): ?string
    {
        return 'reset';
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this->label('Reset Filter')
            ->color('danger')
            ->action(fn ($livewire) => $livewire->resetFilters())
            ->visible(function ($livewire): bool {
                $filters = $livewire->filters ?? [];

                return ! empty($filters['startDate']) || ! empty($filters['endDate']);
            });
    }
}
