import { defineStore } from 'pinia'
import { ref, Ref } from 'vue'
import { Session } from '/@/utils/storage'
import { recentDaysRange } from '/@/views/adManage/utils/tools'
import { useShopInfo } from './shopInfo'

export const usePublicData = defineStore('publicData', () => {
  const dateRange: Ref<string[]> = ref([])

  function setDateRange(val: string[]) {
    dateRange.value = val
    Session.set('dateRange', val)
  }

  function initData() {
    const dateRangeVal = Session.get('dateRange')
    if (dateRangeVal) {
      dateRange.value = dateRangeVal
    } else {
      setDateRange(recentDaysRange(useShopInfo().profile.time_zone, 7))
    }
  }

  return { dateRange, initData, setDateRange }
})

