export type SettingFieldType = 'text' | 'textarea' | 'number' | 'menu-checkboxes' | 'email'

export interface SettingSchemaItem {
  key: string
  label: string
  type: SettingFieldType
  group: 'site' | 'seo' | 'navigation' | 'pagination' | 'contact'
  public: boolean
  default: string
  description: string
}

export const SETTING_GROUPS: { id: SettingSchemaItem['group']; label: string }[] = [
  { id: 'site', label: '站点信息' },
  { id: 'seo', label: 'SEO 优化' },
  { id: 'navigation', label: '导航菜单' },
  { id: 'pagination', label: '分页设置' },
  { id: 'contact', label: '联系方式' },
]

export const SETTINGS_SCHEMA: SettingSchemaItem[] = [
  {
    key: 'site_title',
    label: '网站标题',
    type: 'text',
    group: 'site',
    public: true,
    default: '年糕崽崽.Dev',
    description: '浏览器标签页和页头显示的网站名称',
  },
  {
    key: 'site_author',
    label: '网站作者',
    type: 'text',
    group: 'site',
    public: true,
    default: '',
    description: '网站作者名称，用于 meta 标签',
  },
  {
    key: 'site_description',
    label: '网站描述',
    type: 'textarea',
    group: 'seo',
    public: true,
    default: '',
    description: '搜索引擎摘要描述',
  },
  {
    key: 'site_keywords',
    label: '网站关键词',
    type: 'textarea',
    group: 'seo',
    public: true,
    default: '',
    description: 'SEO 关键词，逗号分隔',
  },
  {
    key: 'visible_menus',
    label: '前台菜单',
    type: 'menu-checkboxes',
    group: 'navigation',
    public: true,
    default: '["home","blog","columns","works","videos","snippets","about","services"]',
    description: '控制前台导航栏显示的菜单项',
  },
  {
    key: 'posts_per_page',
    label: '文章每页数量',
    type: 'number',
    group: 'pagination',
    public: true,
    default: '10',
    description: '博客列表页每页显示的文章数',
  },
  {
    key: 'works_per_page',
    label: '作品每页数量',
    type: 'number',
    group: 'pagination',
    public: true,
    default: '12',
    description: '作品列表页每页显示数量',
  },
  {
    key: 'snippets_per_page',
    label: '代码每页数量',
    type: 'number',
    group: 'pagination',
    public: true,
    default: '12',
    description: '代码片段列表页每页显示数量',
  },
  {
    key: 'footer_icp',
    label: 'ICP 备案号',
    type: 'text',
    group: 'contact',
    public: true,
    default: '',
    description: '页脚 ICP 备案信息',
  },
  {
    key: 'contact_email',
    label: '联系邮箱',
    type: 'email',
    group: 'contact',
    public: true,
    default: '',
    description: '公开展示的联系邮箱',
  },
]

export const MENU_OPTIONS = [
  { key: 'home', label: '首页' },
  { key: 'blog', label: '思考' },
  { key: 'columns', label: '专栏' },
  { key: 'works', label: '作品' },
  { key: 'videos', label: '视频' },
  { key: 'snippets', label: '代码' },
  { key: 'about', label: '关于' },
  { key: 'services', label: '合作' },
]

export const getSchemaByKey = (key: string) => SETTINGS_SCHEMA.find(s => s.key === key)

export const getSchemaKeys = () => SETTINGS_SCHEMA.map(s => s.key)
