<div class="panel panel-danger">
    <div class="panel-heading">
        <h4 style="margin:0">
            <i class="fa fa-exclamation-triangle"></i>
            {$L.ms_deploy_failed}
        </h4>
    </div>
    <div class="panel-body">
        <p><strong>{$L.ms_domain}:</strong> {$domain|escape}</p>

        <div class="alert alert-danger">
            {$L.ms_deploy_error_notified}
        </div>

        <p>{$L.ms_deploy_retry_or_wait}</p>

        {if $allow_redeploy}
            <button type="button" class="btn btn-warning" id="puq-client-redeploy">
                <i class="fa fa-redo"></i> {$L.ms_try_deployment_again}
            </button>
            <span class="text-muted" style="margin-left:8px;" id="puq-client-redeploy-msg"></span>
        {else}
            <p class="text-muted small">
                <i class="fa fa-info-circle"></i>
                {$L.ms_contact_support_logged}
            </p>
        {/if}
    </div>
</div>

{if $allow_redeploy}
{literal}
<script>
(function(){
    var btn = document.getElementById('puq-client-redeploy');
    if (!btn) return;
    var msg = document.getElementById('puq-client-redeploy-msg');
    // This splash renders WITHOUT header.tpl, so window.puqT may be undefined.
    // Self-contained puqT from the injected {$L_json} map (mirrors the jQuery
    // fallback below for puqClientAjax).
    var PUQ_T = (window.PUQ_T) || {/literal}{$L_json|default:'{}' nofilter}{literal};
    var puqT = (typeof window.puqT === 'function') ? window.puqT : function(k){ return (PUQ_T && PUQ_T[k] != null) ? PUQ_T[k] : k; };
    var sid = {/literal}{$service_id|default:0|intval}{literal};
    if (!sid) {
        var m = window.location.search.match(/[?&]id=(\d+)/);
        if (m) sid = parseInt(m[1], 10);
    }
    btn.addEventListener('click', function(){
        if (!sid) return;
        btn.disabled = true;
        btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> ' + puqT('ms_requeueing');
        if (msg) msg.textContent = '';
        // Route through puqClientAjax — form-urlencoded POSTs to clientarea.php
        // get 302'd by WHMCS's anti-forgery layer (response = 90KB HTML blob,
        // never reaches our dispatcher).
        window.puqServiceId = sid;
        var done = function(j){
            if (j && j.status === 'success') {
                if (msg) msg.textContent = j.msg || puqT('ms_redeploy_requested');
                setTimeout(function(){ window.location.reload(); }, 1500);
            } else {
                btn.disabled = false;
                btn.innerHTML = '<i class="fa fa-redo"></i> ' + puqT('ms_try_deployment_again');
                if (msg) msg.innerHTML = '<span class="text-danger">' + ((j && j.msg) || puqT('ms_request_failed')) + '</span>';
            }
        };
        if (typeof window.puqClientAjax === 'function') {
            window.puqClientAjax('clientRedeploy', {}, done, 'POST');
        } else if (typeof jQuery !== 'undefined') {
            jQuery.ajax({
                url: 'clientarea.php?action=productdetails&id=' + sid + '&ajax=clientRedeploy',
                method: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: '{}',
                processData: false,
                dataType: 'json',
                success: done,
                error: function(){ done({status:'error', msg:puqT('ms_network_error')}); }
            });
        } else {
            done({status:'error', msg:puqT('ms_helper_missing')});
        }
    });
})();
</script>
{/literal}
{/if}
