import { userLogin } from "../api/apiHttps";
import { ElMessage } from "element-plus";

export const useColor = () => useState<string>('color', () => 'red')
// 登录状态
export const useUserisLogin = () => useState('isLogin', () => {
  const isLogin = ref(true)
  return isLogin
})

// 登录状态
export const useUserStore = () => useState('user', () => {
  const isLogin: any = useCookie('tokenKey')
  const username: any = ref('')
  const userInfo: any = ref({})
  const userId = ref('')
  const avatar = '/img/profile.svg'
  const cartFalg = false
  const cartUpdate = 0
  const cartNumber = 0
  const cartGroup: any = []
  const cartEnd = false
  const cartLoading = false
  const createOrderFalg = true
  const categoryClickFalg = false
  const adminTitle = ''
  const publicSearch = ''
  const msgLoad = false
  const regOpen = false
  const searchFalg = false

  return { username, isLogin, userId, avatar, userInfo, cartFalg, cartUpdate, cartNumber, cartGroup, cartLoading,createOrderFalg,categoryClickFalg,publicSearch,adminTitle,msgLoad,regOpen,searchFalg,cartEnd}
})

export const useListStore = () => useState('ListStore', () => {
  const categoryListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const searcgListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const freeshippingListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const presaleListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const newsListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const applicationListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })

  const wantListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  return { categoryListData,searcgListData,freeshippingListData,presaleListData,newsListData,wantListData,applicationListData}
})

export const useAdminListStore = () => useState('adminListStore', () => {
  const collectListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const storehouseListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const monitorListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const presaleListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const msgListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const wantListData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  const wantListJlData: any = ref({
    data:null,
    query:null,
    scrollPosition:0,
    loading:false
  })
  return { storehouseListData,presaleListData,monitorListData,msgListData,wantListData,wantListJlData,collectListData}
})

export const useHomeStore = () => useState('HomeStore', () => {
  const presaleData: any = ref([])
  const freeshippingData: any = ref([])
  const categoryData: any = ref([])
  const homeScrollPosition:any = ref(0)
  return { presaleData,freeshippingData,categoryData,homeScrollPosition}
})

// 分类
export const useCategoryStore = () => useState('CategoryStore', () => {
  const Category:any = ref([])
  const CategoryAll = ref([])
  return { Category, CategoryAll }
})

// 判断端口
export const useUserAgent = () => useState('userAgent', () => {
  let isM = ref(false)
  if (process.server) return isM
  const flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
  if (flag)
    isM.value = true
  else
    isM.value = false
  return isM
})