<?php if (!defined('STORE_ROOT')) { http_response_code(403); exit; } $isLoggedIn = Auth::isLoggedIn(); ?> <div class="page-support">     <div class="sf-section-title"><span><?= $L('support_title', 'Support') ?></span></div>     <?php if (!$isLoggedIn): ?>     <div class="page-message"><p><?= $L('support_login_required', 'Please <a href="#account" data-route="account">log in</a> to contact support.') ?></p></div>     <?php else: ?>     <div class="support-layout">         <div class="support-thread" id="support-thread">Loading messages...</div>         <div class="support-compose">             <h3><?= $L('support_compose_title', 'Send Message') ?></h3>             <form onsubmit="sendSupport(event)" class="form-standard">                 <div class="form-group"><label><?= $L('support_subject_label', 'Subject') ?></label><input type="text" id="support-subject" class="form-input" required></div>                 <div class="form-group"><label><?= $L('support_message_label', 'Message') ?></label><textarea id="support-body" class="form-input form-textarea" rows="5" required></textarea></div>                 <div class="form-group"><label><?= $L('support_urgency_label', 'Urgency') ?></label><select id="support-urgency" class="form-input"><option value="low"><?= $L('support_urgency_low', 'Low') ?></option><option value="normal" selected><?= $L('support_urgency_normal', 'Normal') ?></option><option value="high"><?= $L('support_urgency_high', 'High') ?></option><option value="critical"><?= $L('support_urgency_critical', 'Critical') ?></option></select></div>                 <button type="submit" class="btn btn-primary"><?= $L('support_send_btn', 'Send') ?></button>                 <div id="support-status" class="form-status"></div>             </form>         </div>     </div>     <?php endif; ?> </div> <script>
<?php if ($isLoggedIn): ?>
function esc(s) { if (!s) return ''; var d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
function loadMessages() {
    Bridge.sendSupport({ action: 'get_messages' }).then(function(r) {
        var el = document.getElementById('support-thread');
        if (r.messages && r.messages.length > 0) {
            var html = '';
            for (var i = 0; i < r.messages.length; i++) {
                var m = r.messages[i];
                var cls = m.is_admin ? 'msg-admin' : 'msg-user';
                html += '<div class="support-msg ' + cls + '"><div class="msg-header"><strong>' + (m.is_admin ? 'Support' : 'You') + '</strong><span class="msg-date">' + esc(m.created_at) + '</span></div>';
                if (m.subject) html += '<div class="msg-subject">' + esc(m.subject) + '</div>';
                html += '<div class="msg-body">' + esc(m.body) + '</div></div>';
            }
            el.innerHTML = html;
        } else { el.innerHTML = '<p>No messages yet.</p>'; }
    });
}
function sendSupport(e) {
    e.preventDefault();
    Bridge.sendSupport({
        action: 'submit_ticket',
        subject: document.getElementById('support-subject').value,
        body: document.getElementById('support-body').value,
        urgency: document.getElementById('support-urgency').value
    }).then(function(r) {
        var status = document.getElementById('support-status');
        if (r.success) { status.innerHTML = '<p class="form-success">Message sent.</p>'; loadMessages(); document.getElementById('support-body').value = ''; }
        else { status.innerHTML = '<p class="form-error">' + esc(r.error || 'Failed.') + '</p>'; }
    });
}
loadMessages();
<?php endif; ?>
</script>