<?php
declare(strict_types=1);
require dirname(__DIR__) . '/app/bootstrap.php';
$title = htmlspecialchars((string) env('SITE_TITLE', 'ChatGPT Demo'), ENT_QUOTES);
$headScripts = (string)(env('HEAD_SCRIPTS') ?: ''); // 与原项目一致，</head> 前注入
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= $title ?></title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="/assets/app.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github-dark.min.css">
<?= $headScripts ?>
</head>
<body>
<header>
  <div class="logo">🤖 <span><?= $title ?></span></div>
  <div class="controls">
    <label>供应商
      <select id="provider"></select>
    </label>
    <label>模型
      <select id="model"></select>
    </label>
    <button id="btn-clear" type="button" title="清空对话">清空</button>
  </div>
</header>

<details id="settings">
  <summary>设置（系统提示词 / 温度）</summary>
  <label class="block">System Prompt
    <textarea id="system-prompt" rows="3" placeholder="You are a helpful assistant."></textarea>
  </label>
  <label class="block">Temperature：<span id="temp-val">0.7</span>
    <input id="temperature" type="range" min="0" max="2" step="0.1" value="0.7">
  </label>
  <label class="block" id="pass-row" hidden>站点密码
    <input id="site-pass" type="password" placeholder="SITE_PASSWORD 已启用时填写">
  </label>
</details>

<main id="messages"></main>

<footer>
  <form id="composer">
    <textarea id="input" rows="2" placeholder="输入消息，Enter 发送，Shift+Enter 换行"></textarea>
    <button id="btn-send" type="submit">发送</button>
    <button id="btn-regen" type="button">重新生成</button>
  </form>
  <p class="hint">PHP + Nginx 版 · 接口在服务器端转发，API Key 不经过浏览器</p>
</footer>

<script src="https://cdn.jsdelivr.net/npm/marked@12.0.2/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.6/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/core.min.js"></script>
<script src="/assets/app.js"></script>
</body>
</html>
