<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        /* 设置.sidebar的样式 */
        .sidebar {
            position: absolute;
            left: 0;
            height: calc(100%);
            width: 20vw;
            background-color: #b3eff1;
            border-radius: 10px;
            padding: 20px;
            overflow: auto;
            min-width: 88px;
        }

        .sidebar ul li {
            text-align: center;
            border-bottom: 1px solid #dee2e6;
            padding: 10px 0;
            border-radius: 10px;
            border: 1px solid #b3eff1;
            margin-bottom: 10px;
            display: block;
            background-color: #fff;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            word-wrap: break-word;
        }

        .sidebar ul li:hover {
            cursor: pointer;
            background-color: #b3eff1;
        }

        /* 修改.main的样式 */
        .main {
            padding: 50px;
            border: 1px solid rgb(93, 90, 90);
            border-radius: 10px;
            margin-top: 22px;
            margin-bottom: 20px;
            margin-right: 20px;
            margin-left: max(21vw, 90px);
        }

        .btn-primary {
            margin-top: 20px;
            margin-left: -4px;
        }

        .comment {
            color: #6c757d;
            font-size: 0.8rem;
            margin-bottom: 0.2rem;
        }

        /* 将body的高度设置为100vh */
        body {
            height: 100vh;
            margin: 0;
        }

        /* 修改按钮样式 */
        .my-btn {
            position: relative;
            top: 60px;
            left: 0px;
            margin-right: 10px;
            z-index: 9999;
        }
    </style>
</head>

<body>

<!-- 侧边栏 -->
<div class="sidebar">
    <ul class="list-unstyled">
        {% for dict_name in dicts.keys() %}
            <li onclick="window.location='/config/{{ dict_name }}'">{{ dict_name }}</li>
        {% endfor %}
    </ul>
    <a href="https://canxin121.github.io/docs/docs/Spark_GPT.html" style="position: relative; display: inline-block;">
        <div
                style="position: absolute; top: 0; left: 0; width: 50px; height: 50px; border-radius: 50%; overflow: hidden;">
            <img src="https://avatars.githubusercontent.com/u/69547456?s=96&v=4" alt="logo"
                 style="width: 100%; height: 100%; object-fit: cover;">
        </div>
    </a>
    <div>
        <a href="/config" class="btn btn-primary my-btn">配置</a>
        <a href="/prompt" class="btn btn-primary my-btn">预设</a>
        <a href="/prefix" class="btn btn-primary my-btn">前缀</a>
    </div>
</div>
<!-- 主内容 -->
<div class="main"> {% if dict_name %} <!-- 在main上方添加一个h3标签，用来显示当前dict的描述 -->
    <!-- 使用{{ description }}来获取传入的description参数的值 -->
    <h3>{{ description }}</h3>
    <form method="POST" action="/config/{{ dict_name }}"> {% for key, value in dicts[dict_name].items() %}
        <div
                class="form-group row"><label class="col-sm-3 col-form-label">{{ key }}</label>
            <div class="col-sm-9">
                <div class="comment">{{ comments[0][dict_name].get(key, '') }}</div>
                <textarea class="form-control"
                          name="{{ key }}" cols="40" rows="3">{{ value }}</textarea>
            </div>
        </div> {% endfor %} <input type="hidden" name="save" value="True">
        <button type="submit" class="btn
            btn-primary">保存
        </button>
    </form> {% endif %}
</div>

<!-- 引入所需的JavaScript库 -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<!-- 使用JavaScript动态设置sidebar的高度 -->
<script>
(function() {
  const sidebar = document.querySelector('.sidebar');
  const main = document.querySelector('.main');

  const sidebarHeight = sidebar.offsetHeight; 
  const mainHeight = main.offsetHeight;

  const maxHeight = Math.max(sidebarHeight, mainHeight);

  sidebar.style.height = maxHeight + 'px';
  main.style.height = maxHeight + 'px';

})();
</script>

{% if saved %}
    <script> $(document).ready(function () {
        alert('保存成功！');
    }); </script> {% endif %}

</body>

</html>