<?php
// pages/components/template_usage.php — BeezUI Template Usage List
require_once BEEZUI_ROOT . '/components/index.php';

use Components\Base;
use Components\Ui\UsageList;
use Components\Router;

if (!class_exists('template_manager')) {
    require_once(MH_DIR_CONFIG . 'config_editor/classes/template_manager.php');
}

$template_id = mh_get('maintemplate_id');
$usage = template_manager::get_template_usage($template_id);
$title = mh_get('title', $template_id);
echo UsageList::render($usage, [
    'title' => mh_lng('UI_TITLE_TEMPLATE_USAGE', 'Inhaltsnutzung'),
    'summary_subject' => $title,
    'summary_template' => mh_lng('UI_TEXT_TEMPLATE_USAGE_SUMMARY', '<span class="font-medium text-gray-800">%s</span> wird an <span class="font-medium text-gray-800">%d Stellen</span> verwendet.'),
    'empty_message' => mh_lng('UI_TEXT_TEMPLATE_NOT_USED', 'Dieses Template wird derzeit in keinen E-Mails oder Vorlagen verwendet.'),
    'header_actions' => [
        [
            'icon' => Base::SVG_REFRESH,
            'attrs' => [
                'hx-get' => Router::url('template_usage', ['partial' => 1, 'maintemplate_id' => $template_id, 'title' => $title]),
                'hx-target' => '#app-site-panel-body-view',
                'hx-swap' => 'innerHTML',
                'title' => mh_lng('UI_REFRESH', 'Aktualisieren')
            ]
        ],
        [
            'icon' => Base::SVG_X_MARK,
            'attrs' => [
                '@click' => 'window.MBSitePanel.resetView()',
                'title' => mh_lng('UI_CLOSE', 'Schließen')
            ]
        ]
    ]
]);
