{% from 'bootstrap/nav.html' import render_nav_item %}
<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>{% block title %}{% endblock title %} - {{ admin.blog_title|default('Blog Title') }}</title>
        <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
        <link rel="stylesheet"
              href="{{ url_for('static', filename='css/%s.min.css'% request.cookies.get('theme', 'perfect_blue')) }}"
              type="text/css">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" type="text/css">
    {% endblock head %}
</head>
<body>
{% block nav %}
    <nav class="navbar navbar-expand-lg navbar-light" style="background-color: #e3f2fd;">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('blog.index') }}">{{ admin.blog_title }}</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01"
                    aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarColor01">
                <ul class="navbar-nav mr-auto">
                    {{ render_nav_item('blog.index', '主页') }}
                    {{ render_nav_item('blog.about', '我的资料') }}
                </ul>

                <ul class="nav navbar-nav navbar-right">
                    {% if current_user.is_authenticated %}
                        <li class="nav-item dropdown">
                            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button"
                               aria-haspopup="true"
                               aria-expanded="false">
                                新建 <span class="caret"></span>
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" href="{{ url_for('admin.new_post') }}">文章</a>
                                <a class="dropdown-item" href="{{ url_for('admin.new_category') }}">分类</a>
                                <a class="dropdown-item" href="{{ url_for('admin.new_link') }}">链接</a>
                            </div>
                        </li>
                        <li class="nav-item dropdown">
                            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button"
                               aria-haspopup="true"
                               aria-expanded="false">
                                管理 <span class="caret"></span>
                                {% if unread_comments %}
                                    <span class="badge badge-danger">new</span>
                                {% endif %}
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" href="{{ url_for('admin.manage_post') }}">文章</a>
                                <a class="dropdown-item" href="{{ url_for('admin.manage_category') }}">分类</a>
                                <a class="dropdown-item" href="{{ url_for('admin.manage_comment') }}">
                                    评论
                                    {% if unread_comments %}
                                        <span class="badge badge-danger">{{ unread_comments }}</span>
                                    {% endif %}
                                </a>
                                <a class="dropdown-item" href="{{ url_for('admin.manage_link') }}">链接</a>
                            </div>
                        </li>
                        {{ render_nav_item('admin.settings', '设置') }}
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>
{% endblock nav %}

<main class="container">
    {% for message in get_flashed_messages(with_categories=True) %}
        <div class="alert alert-{{ message[0] }}" role="alert">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            {{ message[1] }}
        </div>
    {% endfor %}
    {% block content %}{% endblock content %}
    {% block footer %}
        <footer>
            <p class="float-left">
                <small>
                    {% if current_user.is_authenticated %}
                        <a href="{{ url_for('auth.logout', next=request.full_path) }}">登出</a>
                    {% else %}
                        <a href="{{ url_for('auth.login', next=request.full_path) }}">登录</a>
                        <a href="{{ url_for('auth.register', next=request.full_path) }}">注册</a>
                    {% endif %}
                </small>
            </p>
        </footer>
    {% endblock footer %}
</main>

{% block scripts %}
    <script type="text/javascript" src="{{ url_for('static', filename='js/jquery-3.2.1.slim.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/popper.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/script.js') }}"></script>
    {{ moment.include_moment(local_js=url_for('static', filename='js/moment-with-locales.min.js')) }}
{% endblock %}
</body>
</html>