import { useCallback } from 'react'
import { useEditorStore } from '../stores/editorStore'
import { settingsRepository } from '../db/settingsRepository'
import type { ViewMode } from '../types/settings'

/**
 * AR-04: 设置 hook
 * 不再独立加载设置（由 useSettingsInit 统一加载）
 * 仅负责视图模式的读取和保存
 */
export function useSettings() {
  const viewMode = useEditorStore(s => s.viewMode)
  const setViewMode = useEditorStore(s => s.setViewMode)

  const saveViewMode = useCallback((mode: ViewMode) => {
    setViewMode(mode)
    settingsRepository.save({ viewMode: mode })
  }, [setViewMode])

  return { viewMode, saveViewMode }
}
