import { defineStore } from 'pinia'

export const useSearchStore = defineStore('search', {
  state: () => {
    const searchText = ref('')
    // 是否处于正在键入搜索状态
    const isSearching = ref(false)
    // 是否处于已搜索状态
    const searched = ref(false)

    const searchProduct = (text: string) => {
      searchText.value = text
      isSearching.value = false
      searched.value = true
    }

    const clearSearch = () => {
      searchText.value = ''
      isSearching.value = true
      searched.value = false
    }

    return {
      searched,
      searchText,
      isSearching,
      searchProduct,
      clearSearch,
    }
  },
})
