import { defineStore } from "pinia"; import { endpoints } from "@/constants/endpoints.js"; import globalMethods from "@/global-methods"; import { applicationConfig } from "@/constants/application-config"; const storeId = 'main'; const getDefaultState = () => { return { order: { vehicle: { year: null, make: null, model: null, style: null, carId: null, category: null, vin: null, imageUrl: null, imageVifNumber: null, imageColor: null, registration: { licensePlate: null, address: null, city: null, state: null, zipCode: null, firstName: null, lastName: null, }, }, referralNumber: null, referralDate: null, accountNumber: 0, }, applicationUser: { crmCustomerId: null, lastPageVisited: null, experiments: [], triggeredSiteEntry: false }, }; }; export const state = getDefaultState(); export const useMainStore = defineStore({ id: storeId, state: () => state, getters: {}, actions: { // Content API Actions getRouteInfo(context, { pageName }) { return globalMethods.callHttpClient({ method: endpoints.GetRouteInfo.method, endpoint: endpoints.GetRouteInfo.url(applicationConfig.APPLICATION_ABBREVIATION), payload: { pageName: pageName, }, }); }, getHomepageName(context) { return globalMethods.callHttpClient({ method: endpoints.GetHomepageInfo.method, endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION), }); }, getPageData(context, { pageName }) { return globalMethods.callHttpClient({ method: endpoints.GetPageData.method, endpoint: endpoints.GetPageData.url(applicationConfig.APPLICATION_ABBREVIATION, pageName), payload: {}, }); }, // Vehicle API Actions updateVehicleYear(year) { if (this.order.vehicle.year !== year) { this.order.vehicle.year = year; } }, // populate initial state populateInitialState() { if(!localStorage.getItem(storeId)) { this.$state = state; } } }, persist: true });