<?php

declare(strict_types=1);

require DENTAL_ROOT . '/app/bootstrap.php';
require_login();
require_roles('super_admin');
require DENTAL_ROOT . '/app/layout.php';

$loginUrl = app_absolute_url('login.php');
$dashboardUrl = app_absolute_url('route.php?route=dashboard');
$queueUrl = app_absolute_url('route.php?route=queue_display');
$targets = [
    'login' => 'Staff login',
    'dashboard' => 'Dashboard',
    'queue_display' => 'Queue display',
    'appointments' => 'Appointments',
    'billing' => 'Cashier / Billing',
];

render_header('Kiosk Mode Setup');
?>
<div class="toolbar">
    <div>
        <span class="eyebrow">Display setup</span>
        <strong>Kiosk Mode / Fullscreen Workstation</strong>
        <span class="muted">Create a workstation shortcut that opens DentalCare in real browser kiosk mode using stable .php entry URLs.</span>
    </div>
    <div class="toolbar-actions">
        <a class="btn ghost" href="administration.php">Administration</a>
        <a class="btn ghost" href="system_setup.php">System Setup</a>
    </div>
</div>

<section class="card">
    <div class="card-head">
        <div>
            <h2>Create kiosk desktop shortcut</h2>
            <p>A plain <code>.bat</code> file cannot carry a logo. Use the shortcut creator below: it creates a Desktop shortcut and launches <code>login.php</code> or <code>route.php</code> targets so it does not depend on clean URL rewrite rules.</p>
        </div>
    </div>
    <div class="grid two">
        <form class="form-grid" action="download_kiosk_launcher.php" method="get">
            <input type="hidden" name="browser" value="edge">
            <input type="hidden" name="mode" value="shortcut">
            <label>Startup screen
                <select name="target">
                    <?php foreach ($targets as $value => $label): ?>
                        <option value="<?=e($value)?>"><?=e($label)?></option>
                    <?php endforeach; ?>
                </select>
            </label>
            <button class="btn primary">Download Edge shortcut creator</button>
            <a class="btn ghost compact" href="download_kiosk_launcher.php?browser=edge&amp;mode=batch&amp;target=login">Plain Edge batch file</a>
        </form>
        <form class="form-grid" action="download_kiosk_launcher.php" method="get">
            <input type="hidden" name="browser" value="chrome">
            <input type="hidden" name="mode" value="shortcut">
            <label>Startup screen
                <select name="target">
                    <?php foreach ($targets as $value => $label): ?>
                        <option value="<?=e($value)?>"><?=e($label)?></option>
                    <?php endforeach; ?>
                </select>
            </label>
            <button class="btn ghost">Download Chrome shortcut creator</button>
            <a class="btn ghost compact" href="download_kiosk_launcher.php?browser=chrome&amp;mode=batch&amp;target=login">Plain Chrome batch file</a>
        </form>
    </div>
    <div class="alert info">
        <strong>How to use:</strong> Download the shortcut creator on the clinic computer, double-click it, then use the new <strong>DentalCare Kiosk</strong> desktop shortcut. To exit kiosk mode, press <strong>Alt + F4</strong>.
    </div>
</section>

<section class="grid two">
    <div class="kiosk-help-card">
        <h2>Direct fallback URLs</h2>
        <p>If clean URLs are not working on the server, use these:</p>
        <pre><code>kiosk.php
kiosk-mode.php</code></pre>
        <p>Clean URLs also work when routing is active:</p>
        <pre><code>/kiosk
/kiosk-mode</code></pre>
    </div>
    <div class="kiosk-help-card">
        <h2>Why the system cannot press F11</h2>
        <p>Browsers block websites from silently pressing keyboard keys or forcing fullscreen across page loads. Kiosk mode must start from the local workstation launcher.</p>
    </div>
</section>

<section class="card">
    <h2>Suggested station setup</h2>
    <div class="table-wrap">
        <table data-paginate data-pagination-threshold="5">
            <thead><tr><th>Station</th><th>Recommended startup page</th><th>URL</th></tr></thead>
            <tbody>
                <tr><td>Front desk / staff</td><td>Staff login</td><td><code><?=e($loginUrl)?></code></td></tr>
                <tr><td>Admin / owner</td><td>Dashboard</td><td><code><?=e($dashboardUrl)?></code></td></tr>
                <tr><td>Waiting area monitor</td><td>Queue display</td><td><code><?=e($queueUrl)?></code></td></tr>
            </tbody>
        </table>
    </div>
</section>
<?php render_footer(); ?>
