{{ define "admin/login.html" }}
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SIF 小助手</title>
    {{ template "admin/nav/css.html" . }}

    <style>
        body {
            background: url("/static/images/admin/top-bg.jpg") no-repeat;
            background-size: cover;
            min-height: 100vh;
        }

        .login-btn {
            margin-top: 5%;
            border: 0px;
            color: azure;
            background: #e4007f;
            min-width: 0;
            padding: 0 28px;
        }

        .login-btn:hover {
            color: aliceblue;
        }

        .login-layer .layui-layer-title {
            padding: 0 16px;
            text-align: center;
        }

        #login-form .layui-form-label {
            float: left;
            display: block;
            width: 56px;
            padding: 9px 15px;
            line-height: 20px;
            text-align: right;
        }

        #login-form .layui-input-block {
            margin-left: 86px;
        }

        #login-form .layui-input {
            width: 100%;
        }

        #login-submit-wrap {
            margin-left: 86px;
            padding-right: 15%;
        }

        .login-copyright {
            position: fixed;
            left: 20px;
            bottom: 14px;
            color: rgba(255, 255, 255, 0.92);
            font-size: 18px;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
        }

        @media screen and (max-width: 767.98px) {
            .layui-container {
                padding: 24px 16px 0;
            }

            .login-btn {
                width: auto;
                max-width: none;
                margin-top: 0;
            }

            .login-copyright {
                left: 16px;
                right: 16px;
                bottom: 12px;
                font-size: 14px;
            }
        }
    </style>
</head>

<body>
    <div class="layui-container">
        <button type="button" class="layui-btn layui-btn-lg layui-btn-primary layui-btn-radius login-btn">点击登录</button>
    </div>
    <div class="login-copyright">Copyright © 2023-2026 YumeMichi</div>
    <script src="/static/js/layui.js"></script>
    <script>
        layui.use('layer', function () {
            var $ = layui.$
                , layer = layui.layer;

            function getLoginDialogArea() {
                var viewportWidth = window.innerWidth || document.documentElement.clientWidth || 600;
                var dialogWidth = Math.min(600, Math.max(280, viewportWidth - 24));
                var dialogHeight = viewportWidth <= 767.98 ? '280px' : '230px';
                return [dialogWidth + 'px', dialogHeight];
            }

            $(".login-btn").click(function () {
                layer.open({
                    type: 1,
                    area: getLoginDialogArea(),
                    skin: 'login-layer',
                    title: "登录",
                    content: $('#login-form'),
                    shade: 0
                })
            })

            $("#login-submit").click(function () {
                let user = $("#sifuser").val();
                let pass = $("#sifpass").val();
                $.post("/admin/login", { user: user, pass: pass }, function (data) {
                    if (data.code != 0) {
                        layer.msg(data.message)
                        return
                    }
                    layer.msg(data.message)
                    setTimeout(function () {
                        window.location.href = data.redirect;
                    }, 1500)
                })
            })
        });
    </script>
</body>

<div id="login-form" style="display: none; padding: 10px;">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="sifuser" id="sifuser" required lay-verify="required" placeholder="请输入账号"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="sifpass" id="sifpass" required lay-verify="required" placeholder="请输入密码"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
    <div class="layui-input-block" id="login-submit-wrap">
        <button class="layui-btn" id="login-submit">登录</button>
    </div>
</div>

</html>
{{ end }}
