<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Filament\Resources\DberpSalesStatistics\Pages;

use App\Filament\Resources\DberpSalesStatistics\DberpSalesStatisticResource;
use App\Services\DberpPermissionService;
use App\Support\DberpSalesStatisticsFilamentSupport;
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Auth;

class ListDberpSalesStatistics extends ListRecords
{
    protected static string $resource = DberpSalesStatisticResource::class;

    public function getSubheading(): string|Htmlable|null
    {
        return __('dberp.resources.sales_statistics.scope_hint');
    }

    protected function getHeaderActions(): array
    {
        $permissions = app(DberpPermissionService::class);
        $user = Auth::user();
        $tableFilters = is_array($this->tableFilters) ? $this->tableFilters : [];

        return [
            Action::make('salesOrders')
                ->label(__('dberp.resources.sales_statistics.link_sales_orders'))
                ->url(DberpSalesStatisticsFilamentSupport::salesOrderIndexUrlFromTableState($tableFilters))
                ->visible(fn (): bool => $permissions->allows($user, DberpPermissionService::VIEW_SALES_ORDER)),
            Action::make('customerReceivables')
                ->label(__('dberp.resources.sales_statistics.link_customer_receivables'))
                ->url(DberpSalesStatisticsFilamentSupport::customerReceivableIndexUrlFromTableState($tableFilters))
                ->visible(fn (): bool => $permissions->allows($user, DberpPermissionService::VIEW_CUSTOMER_RECEIVABLE)),
        ];
    }
}
