import { userLogin } from "../api/apiHttps";
import { ElMessage } from "element-plus";
import type Category from "~/domain/Category";

export const useColor = () => useState<string>('color', () => 'red')
interface userType {
  isLogin: Boolean
}
interface test {
  /**姓名 */
  name: string,
  /**年龄 */
  age: number
  /**数组 */
  arr: number[]
}
// 登录状态
export const useUserisLogin = () => useState('isLogin', () => {
  const isLogin = ref(true)
  return isLogin
})

// 登录状态
export const useUserStore = () => useState('user', () => {
  const noticeData:any = {}
  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 filterWarehouseList:any = []
  const wholesaleAddress: any = {
    toName: '',
    toMobile: '',
    toState: '',
    toCity: '',
    toEmail: '',
    toAddress1: '',
    toAddress2: '',
    toZip: '',
    toRoom: ''
  }
  const cartLoading = false
  const createOrderFalg = true
  const scrollPosition = 0
  const regOpen = false
  const IsSubscribe = false
  const qrCode = ''
  const filterQuery: any = {
    newSpu: "",
    freeShipping: "",
    listableTk: "",
    listableTemu: "",
    totalStockCountGT: "",
    totalStockCountLTE: null,
    totalStockCountGTE: null,
    minPrice: null,
    maxPrice: null,
    orderByColumn: null,
    isAsc: null,
  }
  return { username, isLogin, userId, avatar, userInfo, cartFalg, cartUpdate, cartNumber, cartGroup, cartLoading, createOrderFalg, scrollPosition, regOpen, filterQuery,IsSubscribe,qrCode,wholesaleAddress,filterWarehouseList,noticeData }
})

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

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

  const CategoryAll: any = 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
})