<?php

declare(strict_types=1);

namespace App\Filament\Pages;

use App\Filament\Widgets\BusinessOverviewWorkbenchWidget;
use App\Filament\Widgets\InventoryGovernanceWorkbenchLinksWidget;
use App\Filament\Widgets\InventoryWarningDistributionChartWidget;
use App\Filament\Widgets\PurchaseCollaborationWorkbenchLinksWidget;
use App\Filament\Widgets\PurchaseSalesCompareChartWidget;
use App\Filament\Widgets\SalesControlWorkbenchLinksWidget;
use App\Filament\Widgets\SalesTrendChartWidget;
use App\Filament\Widgets\SettlementWorkbenchLinksWidget;
use App\Filament\Widgets\SystemUpdateNoticeWorkbenchWidget;
use App\Services\DberpPermissionService;
use BackedEnum;
use Filament\Pages\Dashboard;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Auth;
use UnitEnum;

final class WorkbenchDashboard extends Dashboard
{
    /**
     * 根路径「/」保留为未登录时的登录首页；工作台放在 /workbench。
     */
    protected static string $routePath = '/workbench';

    protected static ?int $navigationSort = 0;

    public static function getNavigationGroup(): string|UnitEnum|null
    {
        return __('dberp.nav.workbench');
    }

    public static function getNavigationLabel(): string
    {
        return __('dberp.nav.workbench_dashboard');
    }

    /** 宿主配置关闭主导航图标 */
    public static function getNavigationIcon(): string|BackedEnum|Htmlable|null
    {
        return null;
    }

    public static function canAccess(): bool
    {
        return app(DberpPermissionService::class)->allows(Auth::user(), DberpPermissionService::VIEW_WORKBENCH_OVERVIEW);
    }

    public function getTitle(): string|Htmlable
    {
        return __('dberp.nav.workbench_dashboard');
    }

    /**
     * 经营工作台为登录后首页，保留无面包屑，避免与侧栏重复层级。
     *
     * @return array<int|string, string|Htmlable>
     */
    public function getBreadcrumbs(): array
    {
        return [];
    }

    public function getHeaderWidgets(): array
    {
        return [
            SystemUpdateNoticeWorkbenchWidget::class,
            BusinessOverviewWorkbenchWidget::class,
            SalesTrendChartWidget::class,
            PurchaseSalesCompareChartWidget::class,
            InventoryWarningDistributionChartWidget::class,
            InventoryGovernanceWorkbenchLinksWidget::class,
            PurchaseCollaborationWorkbenchLinksWidget::class,
            SettlementWorkbenchLinksWidget::class,
            SalesControlWorkbenchLinksWidget::class,
        ];
    }

    public function getHeaderWidgetsColumns(): int|array
    {
        return [
            'default' => 1,
            'lg' => 2,
        ];
    }
}
