import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { CaseData } from '@/types'
import { cases as allCases } from '@/data/cases'

export const useCasesStore = defineStore('cases', () => {
  const cases = ref<CaseData[]>(allCases)
  const currentCase = ref<CaseData | null>(null)

  function loadCase(slug: string): CaseData | null {
    const found = cases.value.find((c) => c.slug === slug)
    currentCase.value = found || null
    return found || null
  }

  function clearCurrent(): void {
    currentCase.value = null
  }

  return {
    cases,
    currentCase,
    loadCase,
    clearCurrent,
  }
})
