import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Knowledge, FAQ } from '@/types'
import { mockKnowledges, mockFAQs } from '@/mock'

export const useCommonStore = defineStore('common', () => {
  const knowledges = ref<Knowledge[]>([...mockKnowledges])
  const faqs = ref<FAQ[]>([...mockFAQs])
  const currentKnowledge = ref<Knowledge | null>(null)
  const currentFaq = ref<FAQ | null>(null)

  function setCurrentKnowledge(id: string) {
    currentKnowledge.value = knowledges.value.find((k) => k.id === id) || null
  }

  function setCurrentFaq(id: string) {
    currentFaq.value = faqs.value.find((f) => f.id === id) || null
  }

  return {
    knowledges,
    faqs,
    currentKnowledge,
    currentFaq,
    setCurrentKnowledge,
    setCurrentFaq,
  }
})
