{{template "layout/header.html" .}}
<body>

{{template "layout/nav.html" .}}

<div class="studio-wrapper">
    {{template "studio/sidebar.html" .}}

    <main class="studio-main">
        <div class="editor-layout">
            {{if and .Post .Post.IsLocked}}
            <div class="studio-locked-banner">
                <div class="locked-banner-icon">🔒</div>
                <div>
                    <strong>这篇文章已被锁定，无法编辑。</strong>
                    {{if .Post.LockReason}}
                    <p>锁定理由：{{.Post.LockReason}}</p>
                    {{end}}
                </div>
            </div>
            {{end}}

            {{if and (not .Post) (lt .Exp 1)}}
            <div class="studio-locked-banner">
                <div class="locked-banner-icon">🔒</div>
                <div>
                    <strong>Lv1 解锁投稿</strong>
                    <p>完成首次任务（设置用户名、上传头像）或参与社区互动以获取经验。</p>
                </div>
            </div>
            {{end}}

            <form id="postForm" class="editor-form">
                <input type="hidden" id="postId" value="{{if .Post}}{{.Post.ID}}{{end}}">
                {{if .Post}}
                <input type="hidden" id="isLocked" value="{{if .Post.IsLocked}}1{{else}}0{{end}}">
                <textarea id="editBody" style="display:none">{{.Post.Body}}</textarea>
                {{end}}

                <div class="editor-header">
                    <input type="text" id="postTitle" class="editor-title-input"
                        value="{{if .Post}}{{.Post.Title}}{{end}}"
                        placeholder="输入文章标题..."
                        maxlength="200" required autofocus
                        {{if and .Post .Post.IsLocked}}disabled{{end}}>
                </div>

                <div class="editor-main">
                    <div class="editor-pane">
                        <div id="vditor"></div>
                    </div>
                    <aside class="editor-sidebar">
                        <div class="editor-sidebar-section">
                            <h4>快捷语法</h4>
                            <ul class="tips-list">
                                <li><code>#</code> <code>##</code> <code>###</code> 标题</li>
                                <li><code>**粗体**</code> <code>*斜体*</code></li>
                                <li><code>`行内代码`</code></li>
                                <li><code>```</code> 代码块</li>
                                <li><code>&gt;</code> 引用</li>
                                <li><code>-</code> 无序列表</li>
                                <li><code>[文字](链接)</code></li>
                                <li><code>![图片](链接)</code></li>
                            </ul>
                        </div>
                        <div class="editor-sidebar-section">
                            <h4>发布提示</h4>
                            <ul class="tips-list">
                                <li>标题控制在 50 字以内</li>
                                <li>正文清晰分段，便于阅读</li>
                                <li>代码使用代码块包裹</li>
                                <li>Ctrl+S 快速提交</li>
                            </ul>
                        </div>
                    </aside>
                </div>

                <div class="editor-statusbar">
                    <span class="status-item" id="wordCount">0 字</span>
                    <span class="status-item status-draft" id="draftStatus" style="display:none">草稿已保存</span>
                    <span class="status-spacer"></span>
                    {{if and .Post .Post.IsLocked}}
                    <span class="locked-submit-hint">🔒 此文已锁定，无法修改</span>
                    {{else if and (not .Post) (lt .Exp 1)}}
                    <span class="locked-submit-hint">🔒 Lv1 解锁投稿</span>
                    {{else}}
                    <button type="submit" class="btn btn-primary btn-submit">{{if .Post}}保存修改{{else}}发布帖子{{end}}</button>
                    {{end}}
                </div>
            </form>
        </div>
    </main>
</div>

{{template "layout/footer.html" .}}

<link rel="stylesheet" href="/static/vditor/dist/index.css?v={{assetV "/static/vditor/dist/index.css"}}">
<script src="/static/vditor/dist/index.min.js?v={{assetV "/static/vditor/dist/index.min.js"}}" nonce="{{.CSPNonce}}"></script>
<script src="/static/js/common.js?v={{assetV "/static/js/common.js"}}" nonce="{{.CSPNonce}}"></script>
<script src="/static/js/studio-editor.js?v={{assetV "/static/js/studio-editor.js"}}" nonce="{{.CSPNonce}}"></script>
</body>
</html>
