<?php

declare(strict_types=1);

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

namespace App\Filament\Resources\DberpReceiptPaymentQueries\Pages;

use App\Filament\Resources\DberpReceiptPaymentQueries\DberpReceiptPaymentQueryResource;
use App\Services\DberpPermissionService;
use App\Support\DberpSettlementEntryFilamentSupport;
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Auth;

class ListDberpReceiptPaymentQueries extends ListRecords
{
    protected static string $resource = DberpReceiptPaymentQueryResource::class;

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

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

        return [
            Action::make('receiptOrders')
                ->label(__('dberp.resources.receipt_payment_query.link_receipt_orders'))
                ->url(DberpSettlementEntryFilamentSupport::receiptOrdersUrlFromReceiptPaymentTableFilters($tableFilters))
                ->visible(fn (): bool => $permissions->allowsAny($user, [
                    DberpPermissionService::VIEW_RECEIPT_ORDER,
                    DberpPermissionService::CREATE_RECEIPT_ORDER,
                    DberpPermissionService::CONFIRM_RECEIPT_PAYMENT,
                ])),
            Action::make('paymentOrders')
                ->label(__('dberp.resources.receipt_payment_query.link_payment_orders'))
                ->url(DberpSettlementEntryFilamentSupport::paymentOrdersUrlFromReceiptPaymentTableFilters($tableFilters))
                ->visible(fn (): bool => $permissions->allowsAny($user, [
                    DberpPermissionService::VIEW_PAYMENT_ORDER,
                    DberpPermissionService::CREATE_PAYMENT_ORDER,
                    DberpPermissionService::CONFIRM_RECEIPT_PAYMENT,
                ])),
            Action::make('customerReceivables')
                ->label(__('dberp.resources.receipt_payment_query.link_customer_receivables'))
                ->url(DberpSettlementEntryFilamentSupport::customerReceivablesUrlFromReceiptPaymentTableFilters($tableFilters))
                ->visible(fn (): bool => $permissions->allows($user, DberpPermissionService::VIEW_CUSTOMER_RECEIVABLE)),
            Action::make('supplierPayables')
                ->label(__('dberp.resources.receipt_payment_query.link_supplier_payables'))
                ->url(DberpSettlementEntryFilamentSupport::supplierPayablesUrlFromReceiptPaymentTableFilters($tableFilters))
                ->visible(fn (): bool => $permissions->allows($user, DberpPermissionService::VIEW_SUPPLIER_PAYABLE)),
        ];
    }
}
