"use client"
import { useAppStore } from "@/store/app"
import { Switch } from "@heroui/react"
import { UpdateChecker } from "@/components/cstb/UpdateChecker"

export default function Page() {
  const app = useAppStore()

  // 从环境变量或配置中获取更新服务器地址
  // 这里可以改为从 store 或配置文件中读取
  const customEndpoint = process.env.NEXT_PUBLIC_UPDATE_ENDPOINT || ""
  const githubRepo = process.env.NEXT_PUBLIC_GITHUB_REPO || ""

  return (
    <div className="flex flex-col items-start gap-4 pt-2 pb-1">
      <div className="space-y-2">
        <p className="text-sm">版本号：{app.state.version}</p>
        <p className="text-sm">是否有更新：{app.state.hasUpdate ? "有" : "无"}</p>
        <p className="text-sm">是否使用镜像源：{app.state.useMirror ? "是" : "否"}</p>
      </div>

      <div className="w-full border-t border-zinc-200 dark:border-zinc-800 pt-4">
        <h3 className="text-sm font-semibold mb-3">更新检查</h3>
        <UpdateChecker customEndpoint={customEndpoint} githubRepo={githubRepo} />
      </div>

      <div className="w-full border-t border-zinc-200 dark:border-zinc-800 pt-4 space-y-3">
        <h3 className="text-sm font-semibold mb-3">启动设置</h3>
        <Switch
          isSelected={app.state.autoStart}
          size="sm"
          onChange={(e) => app.setAutoStart(e.target.checked)}
        >
          开机自启动 {app.state.autoStart ? "开" : "关"}
        </Switch>
        <Switch
          isSelected={app.state.startHidden}
          size="sm"
          onChange={(e) => app.setStartHidden(e.target.checked)}
        >
          静默启动 {app.state.startHidden ? "开" : "关"}
        </Switch>
        <Switch
          isSelected={app.state.hiddenOnClose}
          size="sm"
          onChange={(e) => app.setHiddenOnClose(e.target.checked)}
        >
          关闭时最小化到托盘 {app.state.hiddenOnClose ? "开" : "关"}
        </Switch>
      </div>
    </div>
  )
}
