<?php

namespace MintyPHP\Support\Search;

class SearchUiMetaProvider
{
    private const ICONS = [
        'users' => 'bi-person-badge',
        'tenants' => 'bi-buildings',
        'departments' => 'bi-diagram-3',
        'roles' => 'bi-people',
        'permissions' => 'bi-shield-lock',
        'scheduled-jobs' => 'bi-calendar-check',
        'pages' => 'bi-file-text',
        'mail-log' => 'bi-envelope-paper',
        'docs' => 'bi-journal-text',
    ];

    private const LIST_URL_KEYS = [
        'users',
        'tenants',
        'departments',
        'roles',
        'permissions',
        'scheduled-jobs',
        'pages',
        'mail-log',
    ];

    public static function iconForKey(string $key): string
    {
        return self::ICONS[$key] ?? 'bi-search';
    }

    public static function listUrl(string $key, string $query): string
    {
        $encoded = urlencode($query);

        return match ($key) {
            'users' => lurl('admin/users') . '?search=' . $encoded,
            'tenants' => lurl('admin/tenants') . '?search=' . $encoded,
            'departments' => lurl('admin/departments') . '?search=' . $encoded,
            'roles' => lurl('admin/roles') . '?search=' . $encoded,
            'permissions' => lurl('admin/permissions') . '?search=' . $encoded,
            'scheduled-jobs' => lurl('admin/scheduled-jobs') . '?search=' . $encoded,
            'pages' => lurl(''),
            'mail-log' => lurl('admin/mail-log') . '?search=' . $encoded,
            default => lurl(''),
        };
    }

    public static function hasIconForKey(string $key): bool
    {
        return array_key_exists($key, self::ICONS);
    }

    public static function hasListUrlForKey(string $key): bool
    {
        return in_array($key, self::LIST_URL_KEYS, true);
    }
}
