<?php
/**
 * Printer Settings View
 *
 * @package Inveetaire
 */

$role = \App\Core\Session::get('role_snapshot') === 'crew' ? 'crew' : 'couple';
?>

<?php ob_start(); ?>

<div class="max-w-3xl mx-auto space-y-6">
    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-800">Printer Configuration</h1>
            <p class="text-sm text-slate-500 mt-1">Adjust thermal label settings for guest check-in.</p>
        </div>
        <a href="<?= url("/app/{$role}/dashboard") ?>" class="btn btn-secondary bg-white text-xs px-4 py-2 rounded-xl border border-slate-200">
            <i class="fa-solid fa-arrow-left mr-1"></i> Back
        </a>
    </div>

    <?php if (!empty($errors)): ?>
        <div class="bg-red-50 border border-red-200 text-red-600 px-4 py-3 rounded-xl text-sm mb-4">
            <?php foreach ($errors as $error): ?>
                <p><?= escape_html($error) ?></p>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    <?php if ($success): ?>
        <div class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-xl text-sm mb-4">
            <?= escape_html($success) ?>
        </div>
    <?php endif; ?>

    <div class="bg-white border border-slate-200 rounded-2xl shadow-sm p-4 md:p-6">
        <form action="<?= url("/app/{$role}/settings/printer") ?>" method="POST" class="space-y-6">
            <?= csrf_field() ?>
            
            <div class="space-y-4">
                <h3 class="text-sm font-bold text-slate-800 border-b border-slate-100 pb-2">Thermal Label Dimensions</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="form-group">
                        <label for="label_width_mm" class="block text-xs font-bold text-slate-700 mb-1.5">Label Width (mm) <span class="text-red-500">*</span></label>
                        <input type="number" id="label_width_mm" name="label_width_mm" value="<?= escape_html($config['label_width_mm'] ?? 50) ?>" min="20" max="200" required
                            class="form-input text-sm w-full rounded-xl bg-slate-50 border-slate-200 focus:bg-white transition-colors"
                            placeholder="e.g. 50">
                        <p class="text-[10px] text-slate-500 mt-1">Width of the physical thermal label sticker.</p>
                    </div>
                    
                    <div class="form-group">
                        <label for="label_height_mm" class="block text-xs font-bold text-slate-700 mb-1.5">Label Height (mm) <span class="text-red-500">*</span></label>
                        <input type="number" id="label_height_mm" name="label_height_mm" value="<?= escape_html($config['label_height_mm'] ?? 30) ?>" min="10" max="200" required
                            class="form-input text-sm w-full rounded-xl bg-slate-50 border-slate-200 focus:bg-white transition-colors"
                            placeholder="e.g. 30">
                        <p class="text-[10px] text-slate-500 mt-1">Height of the physical thermal label sticker.</p>
                    </div>
                </div>
            </div>

            <div class="pt-4 border-t border-slate-100 flex justify-end gap-3">
                <button type="submit" class="btn btn-primary bg-blue-600 hover:bg-blue-700 text-white px-6 py-2.5 rounded-xl text-sm font-bold shadow-sm transition-all flex items-center gap-3">
                    <i class="fa-solid fa-save"></i> Save Configuration
                </button>
            </div>
        </form>
    </div>
</div>

<?php
$content = ob_get_clean();
require ROOT_PATH . '/app/views/layouts/couple.php';
?>
