import axios from 'axios'
import type { CaseLibraryItem } from '../types'

export function useCaseLibrary() {
  const list = ref<CaseLibraryItem[]>([])
  const loading = ref(false)

  function fetchList() {
    loading.value = true
    return axios.get(`https://webapp-pub.ezijing.com/case_library/case.json?_t=${Date.now()}`)
      .then((res) => {
        list.value = res.data
      })
      .finally(() => {
        loading.value = false
      })
  }

  return { list, loading, fetchList }
}
