export const DEFAULT_MODEL = "gpt-5.4";
export const DEFAULT_BASE_URL = "https://api.aixhan.com/v1";
export const DEFAULT_SYSTEM_PROMPT =
  "你是 Sensa基础版，一个运行在浏览器侧边栏中的 AI 助手。你的任务是基于用户当前页面内容、页面结构、可选截图和历史对话，给出简洁、准确、可执行的回答。回答要求：1. 默认使用中文。2. 结论优先，尽量简洁。3. 如果信息不足，要明确说明缺失点。4. 优先依据当前页面最新材料作答。5. 可以使用简短 Markdown，但不要过度排版。";
export const SETTINGS_KEY = "sensaBasicSettings";

export const DEFAULT_SETTINGS = {
  openaiApiKey: "",
  openaiBaseUrl: DEFAULT_BASE_URL,
  openaiModel: DEFAULT_MODEL,
  systemPrompt: DEFAULT_SYSTEM_PROMPT,
  fontScale: "small",
  screenshotMode: "fullpage",
  includePageContext: true,
  includeScreenshot: true,
  debugMode: false
};

export function normalizeBaseUrl(url) {
  return String(url || DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
}

export function normalizeSettings(input) {
  return {
    openaiApiKey: String(input.openaiApiKey || "").trim(),
    openaiBaseUrl: normalizeBaseUrl(input.openaiBaseUrl || DEFAULT_BASE_URL),
    openaiModel: String(input.openaiModel || DEFAULT_MODEL).trim() || DEFAULT_MODEL,
    systemPrompt: String(input.systemPrompt || DEFAULT_SYSTEM_PROMPT).trim() || DEFAULT_SYSTEM_PROMPT,
    fontScale: ["small", "medium", "large"].includes(input.fontScale) ? input.fontScale : "small",
    screenshotMode: input.screenshotMode === "viewport" ? "viewport" : "fullpage",
    includePageContext: input.includePageContext !== false,
    includeScreenshot: input.includeScreenshot !== false,
    debugMode: input.debugMode === true
  };
}
