{{ define "admin/profile.html" }}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>SIF 小助手</title>
    {{ template "admin/nav/css.html" . }}
    <style>
        .profile-action-row {
            display: flex;
            gap: 12px;
            align-items: center;
            flex-wrap: wrap;
        }

        .profile-birth-row {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        .profile-birth-field {
            flex: 1 1 0;
            min-width: 0;
        }

        .profile-birth-sep {
            color: #666;
            white-space: nowrap;
        }

        .profile-action-row .layui-btn+.layui-btn {
            margin-left: 0;
        }

        @media screen and (max-width: 767.98px) {
            .profile-action-row {
                flex-direction: column;
                align-items: stretch;
            }

            .profile-birth-row {
                gap: 8px;
            }
        }
    </style>
</head>

<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        {{ template "admin/nav/header.html" . }}
        {{ template "admin/nav/side.html" . }}

        <div class="layui-body">
            <div style="padding: 15px 20px 100px; overflow: hidden;">
                <form class="layui-form layui-col-md8" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="user_name" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.UserName }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">等级</label>
                        <div class="layui-input-block">
                            <input type="number" name="user_level" min="1" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.UserLevel }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">当前经验</label>
                        <div class="layui-input-block">
                            <input type="number" name="user_exp" min="0" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.UserExp }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">升级经验</label>
                        <div class="layui-input-block">
                            <input type="number" name="next_exp" min="0" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.NextExp }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">金币</label>
                        <div class="layui-input-block">
                            <input type="number" name="game_coin" min="0" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.GameCoin }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">爱心</label>
                        <div class="layui-input-block">
                            <input type="number" name="sns_coin" min="0" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.SnsCoin }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">体力上限</label>
                        <div class="layui-input-block">
                            <input type="number" name="energy_max" min="1" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.EnergyMax }}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">当前体力</label>
                        <div class="layui-input-block">
                            <input type="number" name="over_max_energy" min="0" required lay-verify="required"
                                autocomplete="off" class="layui-input" value="{{ .pref.OverMaxEnergy }}">
                            <div class="layui-form-mid layui-word-aux">填 0 时按体力上限返回给客户端。</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">生日</label>
                        <div class="layui-input-block">
                            <div class="profile-birth-row">
                                <div class="profile-birth-field">
                                    <input type="number" name="birth_month" min="1" max="12" required lay-verify="required"
                                        autocomplete="off" class="layui-input" value="{{ .pref.EffectiveBirthMonth }}">
                                </div>
                                <div class="profile-birth-sep">月</div>
                                <div class="profile-birth-field">
                                    <input type="number" name="birth_day" min="1" max="31" required lay-verify="required"
                                        autocomplete="off" class="layui-input" value="{{ .pref.EffectiveBirthDay }}">
                                </div>
                                <div class="profile-birth-sep">日</div>
                            </div>
                            <div class="layui-form-mid layui-word-aux">格式为 月 / 日，默认 10 / 18。</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户 ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="invite_code" required lay-verify="required" autocomplete="off"
                                class="layui-input" value="{{ .pref.InviteCode }}">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">简介</label>
                        <div class="layui-input-block">
                            <textarea name="user_desc" class="layui-textarea"
                                style="min-height: 120px;">{{ .pref.UserDesc }}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <div class="profile-action-row">
                                <button type="button" class="layui-btn" id="save-profile">保存</button>
                                <button type="button" class="layui-btn layui-btn-primary" id="reset-profile">重置默认值</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="/static/js/layui.js"></script>
    <script>
        layui.use(['form', 'layer'], function () {
            var $ = layui.jquery
                , layer = layui.layer;

            $("#save-profile").click(function () {
                $.post("/admin/profile", $("form").serialize(), function (res) {
                    var message = res.message || "请求完成";
                    if (res.code === 0) {
                        message += " 请重新登录游戏生效。";
                    }
                    layer.msg(message);
                }).fail(function () {
                    layer.msg("请求失败，请稍后再试");
                });
            });

            $("#reset-profile").click(function () {
                layer.confirm("将数值项和用户 ID 恢复为默认安全值，是否继续？", function (index) {
                    $.post("/admin/profile/reset", function (res) {
                        var message = res.message || "请求完成";
                        if (res.code === 0) {
                            message += " 请重新登录游戏生效。";
                        }
                        layer.msg(message);
                        if (res.code === 0) {
                            setTimeout(function () {
                                window.location.reload();
                            }, 1800);
                        }
                    }).fail(function () {
                        layer.msg("请求失败，请稍后再试");
                    });
                    layer.close(index);
                });
            });
        });
    </script>
</body>

</html>
{{ end }}
