import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSettingsStore = defineStore('settings', () => {
  const siteName = ref('Admin Panel')
  const siteDescription = ref('')
  const enableRegistration = ref(true)

  async function loadSettings() {
    try {
      const res = await fetch('/api/settings')
      if (res.ok) {
        const data = await res.json()
        siteName.value = data.site_name || 'Admin Panel'
        siteDescription.value = data.site_description || ''
        enableRegistration.value = data.enable_registration !== 'false'
      }
    } catch (e) {
      console.error('Failed to load settings', e)
    }
  }

  return { siteName, siteDescription, enableRegistration, loadSettings }
})
