<?php

namespace App\Filament\Pages\Analytic;

use App\Filament\Pages\Analytic\Actions\ResetFiltersAction;
use App\Filament\Pages\Analytic\Schemas\AnalyticFiltersForm;
use App\Filament\Widgets\Charts\BudgetRealizationChart;
use App\Filament\Widgets\Charts\CompanyStatusChart;
use App\Filament\Widgets\Charts\CooperationStatusChart;
use App\Filament\Widgets\Charts\IssueDepartmentChart;
use App\Filament\Widgets\Charts\IssueLocationChart;
use App\Filament\Widgets\Charts\IssueSentimentByDepartmentChart;
use App\Filament\Widgets\Charts\JournalistRegistrationChart;
use App\Filament\Widgets\Charts\MediaClassificationChart;
use App\Filament\Widgets\Charts\MediaCooperationRankingChart;
use App\Filament\Widgets\Charts\MediaRegistrationChart;
use App\Filament\Widgets\Charts\MediaTypeChart;
use App\Filament\Widgets\Charts\PopularNewsChart;
use App\Filament\Widgets\Charts\SentimentTrendChart;
use App\Filament\Widgets\Charts\TaskRealizationChart;
use App\Filament\Widgets\Charts\TopMediaJournalistChart;
use App\Filament\Widgets\Charts\VerificationPerformanceChart;
use App\Filament\Widgets\Charts\VisitorTrafficChart;
use BackedEnum;
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;

class Index extends BaseDashboard
{
    use HasFiltersForm, HasPageShield;

    protected static string $routePath = 'analytic';

    protected static ?string $slug = 'analytic';

    protected static ?string $title = 'Analisa';

    protected static ?string $navigationLabel = 'Analisa';

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

    protected static ?int $navigationSort = 2;

    protected static ?string $pollingInterval = null;

    public static function canAccess(): bool
    {
        return auth()->user()->can('View:Analytic');
    }

    public function getColumns(): int|array
    {
        return 2;
    }

    public function filtersForm(Schema $schema): Schema
    {
        return AnalyticFiltersForm::configure($schema);
    }

    protected function getHeaderActions(): array
    {
        return [
            ResetFiltersAction::make(),
        ];
    }

    public function resetFilters(): void
    {
        $this->filters['startDate'] = null;
        $this->filters['endDate'] = null;

        if (method_exists($this, 'getFiltersSessionKey')) {
            session()->forget($this->getFiltersSessionKey());
        }
    }

    public function getWidgets(): array
    {
        return [
            CompanyStatusChart::class,
            CooperationStatusChart::class,
            IssueDepartmentChart::class,
            IssueSentimentByDepartmentChart::class,
            IssueLocationChart::class,
            JournalistRegistrationChart::class,
            MediaClassificationChart::class,
            MediaCooperationRankingChart::class,
            MediaRegistrationChart::class,
            MediaTypeChart::class,
            PopularNewsChart::class,
            TaskRealizationChart::class,
            TopMediaJournalistChart::class,
            VerificationPerformanceChart::class,
            BudgetRealizationChart::class,
            SentimentTrendChart::class,
            VisitorTrafficChart::class,
        ];
    }
}
