import { reactive } from 'vue'; import { useI18n } from 'vue-i18n'; import { defineStore } from 'pinia'; export const useWeekdayStore = defineStore('weekdayStore', () => { const weekdays = [ { code: 'sun', name: 'Sunday' }, { code: 'mon', name: 'Monday' }, { code: 'tue', name: 'Tuesday' }, { code: 'wed', name: 'Wednesday' }, { code: 'thu', name: 'Thursday' }, { code: 'fri', name: 'Friday' }, { code: 'sat', name: 'Saturday' }, ]; const { t } = useI18n(); const weekdaysMap = reactive({}); const initStore = () => { getWeekdaysMap(); }; const getWeekdaysMap = () => { if (Object.keys(weekdaysMap).length > 0) return weekdaysMap; weekdays.forEach((day, i) => { const obj = { ...day, index: i, char: day.name.substr(0, 1), abr: day.name.substr(0, 3), locale: t(`weekdays.${day.code}`), localeChar: t(`weekdays.${day.code}`).substr(0, 1), localeAbr: t(`weekdays.${day.code}`).substr(0, 3), }; weekdaysMap[day.code] = obj; }); }; return { initStore, weekdaysMap, }; });