<?php
$rootConfig = dirname(__DIR__, 2) . '/config.php';
if (file_exists($rootConfig)) {
    require_once($rootConfig);
}

$view = $_REQUEST['view'] ?? 'builder';
$allowedViews = ['builder', 'system_types', 'sections', 'groups', 'questions'];
if (!in_array($view, $allowedViews, true)) {
    $view = 'builder';
}
?>
<script>
document.getElementById('navBox').innerHTML =
    '<li class="breadcrumb-item active">PMR Configuration</li>';
</script>

<div class="container-fluid">
    <div class="row mb-3">
        <div class="col-12">
            <h2 class="mb-3">PMR Configuration</h2>
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a class="nav-link <?= $view === 'builder' ? 'active' : '' ?>"
                       href="index.php?t=includes/master&p=pmr_config.php&view=builder">Builder</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= $view === 'system_types' ? 'active' : '' ?>"
                       href="index.php?t=includes/master&p=pmr_config.php&view=system_types">System Types</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= $view === 'sections' ? 'active' : '' ?>"
                       href="index.php?t=includes/master&p=pmr_config.php&view=sections">Sections</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= $view === 'groups' ? 'active' : '' ?>"
                       href="index.php?t=includes/master&p=pmr_config.php&view=groups">Groups</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= $view === 'questions' ? 'active' : '' ?>"
                       href="index.php?t=includes/master&p=pmr_config.php&view=questions">Questions</a>
                </li>
            </ul>
        </div>
    </div>

    <?php
    switch ($view) {
        case 'builder':
            require_once(ROOT_URL . '/includes/pmr/pmr_builder.php');
            break;

        case 'sections':
            require_once(ROOT_URL . '/includes/pmr/pmr_sections.php');
            break;

        case 'groups':
            require_once(ROOT_URL . '/includes/pmr/pmr_groups.php');
            break;

        case 'questions':
            require_once(ROOT_URL . '/includes/pmr/pmr_questions.php');
            break;

        case 'system_types':
        default:
            require_once(ROOT_URL . '/includes/pmr/pmr_system_types.php');
            break;
    }
    ?>
</div>
