<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>🎯 MCP反馈通道 v3.0 | AI助手交互工具</title>
    <meta name="description" content="现代化的Model Context Protocol反馈收集工具，支持文字、图片反馈，完美兼容SSH远程环境">
    <meta name="keywords" content="MCP,反馈收集,AI助手,Web界面,SSH兼容">
    <meta name="author" content="MCP Feedback Collector Team">
    
    <!-- 安全策略 -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; img-src 'self' data: blob:; connect-src 'self';">
    
    <!-- Favicon using emoji -->
    <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🎯</text></svg>">
    
    <!-- 外部依赖 - 最新版本 + 多CDN备用 -->
    <!-- Marked.js for Markdown parsing - v15.0.12 -->
    <script>
        // CDN备用加载机制
        function loadScript(urls, onLoad, onError) {
            let index = 0;
            function tryNext() {
                if (index >= urls.length) {
                    if (onError) onError();
                    return;
                }
                const script = document.createElement('script');
                script.src = urls[index];
                script.crossOrigin = 'anonymous';
                script.referrerPolicy = 'no-referrer';
                script.onload = onLoad;
                script.onerror = () => {
                    index++;
                    tryNext();
                };
                document.head.appendChild(script);
            }
            tryNext();
        }
        
        function loadCSS(urls) {
            let index = 0;
            function tryNext() {
                if (index >= urls.length) return;
                const link = document.createElement('link');
                link.rel = 'stylesheet';
                link.href = urls[index];
                link.crossOrigin = 'anonymous';
                link.referrerPolicy = 'no-referrer';
                link.onerror = () => {
                    index++;
                    tryNext();
                };
                document.head.appendChild(link);
            }
            tryNext();
        }
    </script>
    
    <!-- 加载样式 -->
    <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
    <div class="container">
        <div class="header" style="display: none;">
            <h1>🎯 AI工作反馈通道</h1>
            <p>您的反馈对我们很重要</p>
        </div>
        
        <div class="content">
            <!-- AI工作汇报区域 - 占主要空间 -->
            <div class="section work-report-section">
                <div class="section-header">
                    📋 AI工作完成汇报
                    <!-- 超时时间提示和进度条 -->
                    <div class="timeout-info" id="timeoutInfo">
                        <span id="timeoutMessage" class="timeout-message">此窗口将在 <span id="timeoutCountdown" class="timeout-countdown"></span> 后自动关闭</span>
                    </div>
                    <div class="timeout-progress-container">
                        <div class="timeout-progress-bar" id="timeoutProgressBar"></div>
                    </div>
                    <button type="button" class="btn btn-small" id="toggleReportBtn" onclick="window.MCPFeedback.toggleReportSize()" aria-label="调整汇报区域大小">
                        ↔️ 调整
                    </button>
                </div>
                <div class="section-content">
                    <div class="work-summary" id="workSummary" data-raw-content="{{ work_summary or '等待AI汇报工作内容...' }}">
                        {{ work_summary or "等待AI汇报工作内容..." }}
                    </div>
                </div>
            </div>
            
            <!-- 反馈表单 - 占较小空间 -->
            <form id="feedbackForm">
                <!-- CSRF保护令牌 -->
                <input type="hidden" name="csrf_token" value="{{ csrf_token }}" id="csrfToken">
                <!-- 统一反馈区域 -->
                <div class="section feedback-section">
                    <div class="section-header">
                        💬 您的反馈（文字+图片，可选）
                        <button type="button" class="btn btn-small" id="toggleFeedbackBtn" onclick="window.MCPFeedback.toggleFeedbackSize()" aria-label="展开或收起反馈区域">
                            📏 展开/收起
                        </button>
                    </div>
                    <div class="section-content" id="feedbackContent">
                        <!-- 建议选项区域 -->
                        <div class="suggest-options" id="suggestOptions" style="display: none;">
                            <div class="suggest-header">💡 建议选项（点击直接提交或复制到输入框）：</div>
                            <div class="suggest-list" id="suggestList"></div>
                        </div>
                        
                        <!-- 图片预览区域 -->
                        <div class="image-preview" id="imagePreview"></div>
                        
                        <div class="form-group">
                            <textarea 
                                id="textFeedback" 
                                name="textFeedback" 
                                placeholder="请在此输入您的反馈、建议或问题...&#10;💡 提示：可直接按 Ctrl+V 粘贴图片"
                                rows="3"
                                aria-label="反馈内容输入框"
                                aria-describedby="feedbackHelp"
                            ></textarea>
                            <div id="feedbackHelp" class="sr-only">支持文字输入和图片粘贴，也可以拖拽图片到此区域</div>
                        </div>
                        
                        <!-- 操作按钮组 -->
                        <div class="inline-button-group">
                            <button type="button" class="btn btn-icon btn-compact" id="uploadBtn" title="上传图片" aria-label="选择图片文件上传">
                                🖼️ 图片
                            </button>
                            <button type="button" class="btn btn-secondary btn-compact" onclick="window.close()" aria-label="取消并关闭窗口">
                                ❌ 取消
                            </button>
                            <button type="submit" class="btn btn-success btn-compact" id="submitBtn" aria-label="提交反馈内容">
                                ✅ 提交反馈
                            </button>
                        </div>
                        
                        <!-- 隐藏的文件输入 -->
                        <input type="file" id="fileInput" accept="image/*" multiple class="hidden">
                        
                        <!-- 隐藏的建议数据 -->
                        <script type="application/json" id="suggestData">{{ suggest_json | safe }}</script>
                        
                        <!-- 超时时间数据（保持在表单内部，JS读取用） -->
                        <script type="application/json" id="timeoutData">{{ timeout_seconds }}</script>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- 动态加载外部依赖 -->
    <script>
        // 加载Prism.js CSS
        loadCSS([
            'https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism-tomorrow.min.css',
            'https://unpkg.com/prismjs@1.30.0/themes/prism-tomorrow.min.css'
        ]);
        
        // 加载Marked.js
        loadScript([
            'https://cdn.jsdelivr.net/npm/marked@15.0.12/marked.min.js',
            'https://unpkg.com/marked@15.0.12/marked.min.js'
        ], function() {
            console.log('✅ Marked.js 加载成功');
        }, function() {
            console.warn('❌ Marked.js 加载失败，Markdown渲染将不可用');
        });
        
        // 加载Mermaid.js
        loadScript([
            'https://cdn.jsdelivr.net/npm/mermaid@11.6.0/dist/mermaid.min.js',
            'https://unpkg.com/mermaid@11.6.0/dist/mermaid.min.js'
        ], function() {
            console.log('✅ Mermaid.js 加载成功');
        }, function() {
            console.warn('❌ Mermaid.js 加载失败，图表渲染将不可用');
        });
        
        // 加载Prism.js Core
        loadScript([
            'https://cdn.jsdelivr.net/npm/prismjs@1.30.0/components/prism-core.min.js',
            'https://unpkg.com/prismjs@1.30.0/components/prism-core.min.js'
        ], function() {
            console.log('✅ Prism.js Core 加载成功');
            // 加载Prism.js Autoloader
            loadScript([
                'https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js',
                'https://unpkg.com/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js'
            ], function() {
                console.log('✅ Prism.js Autoloader 加载成功');
            }, function() {
                console.warn('❌ Prism.js Autoloader 加载失败，代码高亮将不可用');
            });
        }, function() {
            console.warn('❌ Prism.js Core 加载失败，代码高亮将不可用');
        });
    </script>
    
    <script type="module" src="{{ url_for('static', filename='js/feedback-main.js') }}"></script>
</body>
</html> 