<?php defined('EM_ROOT') || exit('access denied!'); ?>

<style>
    .success-card {
        /*max-width: 600px;*/
        /*margin: 0 auto;*/
        border-radius: 16px;
        box-shadow: 0 10px 30px rgba(79, 99, 235, 0.1);
        overflow: hidden;
        background: white;
        margin-top: 10px;
    }
    .success-header {
        background: linear-gradient(135deg, #4F63EB 0%, #6C5CE7 100%);
        padding: 30px 24px;
        text-align: center;
        position: relative;
        overflow: hidden;
    }
    .success-header:after {
        content: '';
        position: absolute;
        width: 200px;
        height: 200px;
        border-radius: 50%;
        background: rgba(255,255,255,0.1);
        top: -100px;
        right: -50px;
    }
    .success-header:before {
        content: '';
        position: absolute;
        width: 120px;
        height: 120px;
        border-radius: 50%;
        background: rgba(255,255,255,0.1);
        bottom: -60px;
        left: -30px;
    }
    .success-icon {
        width: 80px;
        height: 80px;
        background: white;
        border-radius: 50%;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        z-index: 2;
    }
    .success-icon i {
        font-size: 40px;
        color: #38B2AC;
    }
    .success-body {
        padding: 36px 24px;
        text-align: center;
    }
    .success-title {
        font-size: 24px;
        color: #1A202C;
        margin-bottom: 16px;
        font-weight: 600;
    }
    .success-desc {
        font-size: 16px;
        color: #4A5568;
        line-height: 1.6;
        /*margin-bottom: 30px;*/
        /*max-width: 450px;*/
        margin-left: auto;
        margin-right: auto;
    }

    .feature-item i {
        font-size: 24px;
        color: #4F63EB;
        margin-bottom: 12px;
        display: inline-block;
    }
    .feature-item p {
        color: #4A5568;
        font-size: 14px;
    }

</style>

<?php if(!defined('DEMO_MODE') || DEMO_MODE != true): ?>
<div class="panel mt-3 bg-white">

    <div class="panel-body">

        <?php if (isset($_GET['error_b'])): ?>
            <div class="alert danger-pale">授权失败了，可能是授权码可用次数已耗尽，或服务器无法访问官网 <?= SERVICE_HOST ?></div>
        <?php endif ?>

        <?php if (!Register::isRegLocal()) : ?>
            <form class="layui-form " action="?action=auth" id="form">
                <div style="padding: 25px;" id="open-box">
                    <div class="layui-form-item">
                        <label class="layui-form-label">授权码</label>
                        <div class="layui-input-block">
                            <input type="text" name="emkey" class="layui-input" placeholder="请输入授权码">
                        </div>
                    </div>

                    <input name="token" id="token" value="<?= LoginAuth::genToken() ?>" type="hidden"/>
                    <div class="layui-input-block" style="margin: 0 auto;">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="submit">立即授权</button>
                        <a href="<?= SERVICE_HOST ?>/index/register/index" target="_blank" class="layui-btn layui-bg-blue">获取授权码&rarr; </a>
                    </div>
                </div>


            </form>
        <?php else: ?>

            <div class="success-card" style="">
                <!-- 头部成功图标区域 -->
                <div class="success-header">
                    <div class="success-icon">
                        <i class="layui-icon layui-icon-ok"></i>
                    </div>
                </div>
                <!-- 内容区域 -->
                <div class="success-body">
                    <h2 class="success-title">恭喜，成功完成正版授权！</h2>
                    <p class="success-desc">
                        您已成功激活EMSHOP全部功能，现在可以享受完整的服务与支持，包括在线升级、应用商店及专属技术支持。
                    </p>
                    <br>
                    <p class="success-desc">
                        请勿向任何人透露您的授权码，自己正常使用即可。检测到异常违规使用授权码可能会被删除授权码哦~
                    </p>
                    <br>
                    <p class="success-desc" style="">
                        我的授权码：<?= $emkey ?>
                    </p>
                    <br>
                    <p class="success-desc" style="">
                        自动登录官网：<a style="color: #1e9fff;" target="_blank" href="<?= SERVICE_HOST ?>/index/emkey/login?emkey=<?= $emkey ?>"><?= SERVICE_HOST ?></a>
                    </p>
                </div>
            </div>




        <?php endif ?>
    </div>
</div>
<?php endif; ?>
<script>
    layui.use(['table'], function(){
        var $ = layui.$;
        var form = layui.form;
        form.on('submit(submit)', function(data){
            var field = data.field; // 获取表单全部字段值
            var url = $('#form').attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data: field,
                dataType: "json",
                success: function (e) {
                    location.reload();
                },
                error: function (xhr) {
                    layer.msg(JSON.parse(xhr.responseText).msg);
                }
            });
            return false; // 阻止默认 form 跳转
        });





    })
</script>


<script>
    $("#menu-auth").addClass('active');
</script>