<?php

declare(strict_types=1);

namespace App\Support;

use Filament\Resources\Pages\ListRecords;

/**
 * Filament v5 {@see ListRecords} 将表格筛选状态同步到 URL 查询参数 {@code filters}，
 * 而非 {@code tableFilters}。
 */
final class DberpFilamentListPageUrl
{
    /**
     * @param  array<string, mixed>  $tableFilters
     */
    public static function queryString(array $tableFilters): string
    {
        if ($tableFilters === []) {
            return '';
        }

        return '?'.http_build_query(['filters' => $tableFilters]);
    }

    /**
     * @param  array<string, mixed>  $tableFilters
     */
    public static function append(string $baseUrl, array $tableFilters): string
    {
        $query = self::queryString($tableFilters);

        return $query === '' ? $baseUrl : $baseUrl.$query;
    }
}
