import { useEffect } from 'react'
import { useStatusBarStore } from '../stores/statusBarStore'
import {
  FileInfoItem,
  LoadingItem,
  DocStatsItem,
  EncodingItem,
  LangItem
} from '../components/StatusBar/StatusBarItems'

/**
 * useDefaultStatusBarItems — 注册所有默认状态栏项（不含 auto-save）。
 *
 * auto-save 项由 App.tsx 单独注册，因为它需要从 autoSaveStore
 * 读取状态并通过 toggleAutoSaveExternal() 触发切换。
 */
export function useDefaultStatusBarItems() {
  const register = useStatusBarStore(s => s.register)
  const unregister = useStatusBarStore(s => s.unregister)

  useEffect(() => {
    register({ id: 'statusbar.file-info', alignment: 'left',  priority: 0,   Component: FileInfoItem })
    register({ id: 'statusbar.loading',   alignment: 'left',  priority: 1,   Component: LoadingItem })
    register({ id: 'statusbar.doc-stats', alignment: 'right', priority: 100, Component: DocStatsItem })
    register({ id: 'statusbar.encoding',  alignment: 'right', priority: 300, Component: EncodingItem })
    register({ id: 'statusbar.lang',      alignment: 'right', priority: 400, Component: LangItem })

    return () => {
      unregister('statusbar.file-info')
      unregister('statusbar.loading')
      unregister('statusbar.doc-stats')
      unregister('statusbar.encoding')
      unregister('statusbar.lang')
    }
  }, [register, unregister])
}
