/** web/src/store/useAppStore.ts 模块。 */
import { create } from 'zustand'
import type { AppStore, ThemeDef } from '@/types'

export const THEMES: ThemeDef[] = [
  { id: 'dark', label: '高级黑', scheme: 'dark', c1: '#000000', c2: '#666666' },
  { id: 'light', label: '高级白', scheme: 'light', c1: '#ffffff', c2: '#d9d9d9' },
  { id: 'cream', label: '奶油米', scheme: 'light', c1: '#faf2e0', c2: '#0e61ac' },
  { id: 'slate', label: '雾灰紫', scheme: 'light', c1: '#e4e4e6', c2: '#6f7899' },
  { id: 'matcha-cake', label: '抹茶糕', scheme: 'light', c1: '#f4f8df', c2: '#3f7e44' },
  { id: 'coconut-mint', label: '薄荷饮', scheme: 'light', c1: '#e9fcfa', c2: '#1d8ed6' },
  { id: 'taro-mousse', label: '芋泥酪', scheme: 'light', c1: '#f5eefb', c2: '#7b5bc2' },
  { id: 'blue-sakura', label: '樱花酪', scheme: 'light', c1: '#fceff3', c2: '#507bdb' },
  { id: 'strawberry-cake', label: '草莓糕', scheme: 'light', c1: '#fff5ef', c2: '#d93655' },
  { id: 'cool-blue-gray', label: '蓝灰调', scheme: 'light', c1: '#feffff', c2: '#47709b' },
  { id: 'peach-oolong', label: '蜜桃茶', scheme: 'light', c1: '#fff0e8', c2: '#e4783e' },
  { id: 'caramel-macchiato', label: '焦糖咖', scheme: 'light', c1: '#faf3eb', c2: '#9b6234' },
  { id: 'rose-lychee', label: '荔枝冻', scheme: 'light', c1: '#fff0f3', c2: '#d9546f' },
  { id: 'lavender-latte', label: '薰衣草', scheme: 'light', c1: '#f5f0fa', c2: '#8a75b4' },
  { id: 'sea-salt-cheese', label: '海盐酪', scheme: 'light', c1: '#f5f6f8', c2: '#6e8097' },
]

/** 处理 defaultPromptData 相关逻辑。 */
export const defaultPromptData = {
  system: '选择用户后加载 system prompt...',
  soul: '选择用户后加载 soul prompt...',
  agent: '选择用户后加载 agent prompt...',
  other: '选择用户后加载其他注入摘要...',
}

/** 提供 useAppStore Hook 的业务能力。 */
export const useAppStore = create<AppStore>(() => ({
  users: [],
  selectedUser: '',
  userActive: false,
  selectErr: '',
  theme: 'dark',
  themeMenu: false,
  themeMenuPos: { x: 0, y: 0 },
  refreshing: false,
  dragging: false,
  userScrolledUp: false,
  dragCounter: 0,
  msgId: 1,
  toastTimer: undefined,
  abortCtrl: null,
  currentRunId: null,
  running: false,
  showToolCalls: true,
  showThinking: true,
  input: '',
  attachChips: [],
  messages: [],
  conversations: [],
  activeConv: '__current__',
  showConvManager: false,
  isPreview: false,
  previewConvId: null,
  activeTab: 'overview',
  promptTab: 'system',
  statusSubTab: 'logs',
  config: {
    type: 'kemo',
    model: '',
    baseUrl: '',
    keyDraft: '',
    think: true,
    stream: false,
    acceptTask: true,
    capabilitiesOverride: null,
    visionModel: '',
    audioTranscriptionModel: '',
    imageGenerationModel: '',
    imageEditModel: '',
    speechGenerationModel: '',
    speechToSpeechModel: '',
    videoGenerationModel: '',
  },
  lastSavedConfig: {},
  stats: { messages: '-', tools: '-', size: '-' },
  contextWindow: null,
  frameworkVersion: '-',
  pluginVersions: [],
  profileName: '未连接',
  profileInfo: '选择用户开始',
  avatarUrl: '',
  chatTitle: '对话闭环与工具调用',
  mainSub: '选择用户后开始对话',
  modelName: '-',
  promptData: defaultPromptData,
  logs: [],
  tasks: [],
  taskPlans: [],
  files: [],
  activePlan: null,
  planPhase: null,
  capabilitiesInfo: null,
  capabilitiesMode: 'auto',
  toastText: '',
  toastVisible: false,
  menu: { show: false, id: '', label: '', x: 0, y: 0 },
  topStatusText: '',
  topStatusKind: '',
}))
