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: { vehicle: this.order.vehicle }, actions: { // Content API Actions getRouteInfo(pageName) { return globalMethods.callHttpClient({ method: endpoints.GetRouteInfo.method, endpoint: endpoints.GetRouteInfo.url(applicationConfig.APPLICATION_ABBREVIATION), payload: { pageName: pageName, }, }); }, getHomepageName() { return globalMethods.callHttpClient({ method: endpoints.GetHomepageInfo.method, endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION), }); }, getPageData(pageName) { return globalMethods.callHttpClient({ method: endpoints.GetPageData.method, endpoint: endpoints.GetPageData.url(applicationConfig.APPLICATION_ABBREVIATION, pageName), payload: {}, }); }, // Vehicle API Actions getVehicleYears() { return globalMethods.callHttpClient({ method: endpoints.GetVehicleYears.method, endpoint: endpoints.GetVehicleYears.url, payload: {}, }); }, getVehicleMakes() { return globalMethods.callHttpClient({ method: endpoints.GetVehicleMakes.method, endpoint: endpoints.GetVehicleMakes.url + this.order.vehicle.year, payload: {}, }); }, getVehicleModels() { return globalMethods.callHttpClient({ method: endpoints.GetVehicleModels.method, endpoint: `${endpoints.GetVehicleModels.url}/${this.order.vehicle.year}/${this.order.vehicle.make}`, payload: {}, }); }, getVehicleStyles() { return globalMethods.callHttpClient({ method: endpoints.GetVehicleStyles.method, endpoint: `${endpoints.GetVehicleStyles.url}/${this.order.vehicle.year}/${this.order.vehicle.make}/${this.order.vehicle.model}`, payload: {}, }); }, // Vehicle API Actions updateVehicleYear(year) { if (this.order.vehicle.year !== year) { this.order.vehicle.year = year; } }, updateVehicleMake(make) { if (this.order.vehicle.make !== make) { this.order.vehicle.make = make; } }, updateVehicleModel(model) { if (this.order.vehicle.model !== model) { this.order.vehicle.model = model; } }, updateVehicleStyle(style) { if (this.order.vehicle.style !== style) { this.order.vehicle.style = style; } }, // populate initial state populateInitialState() { if(!localStorage.getItem(storeId)) { this.$state = state; } } }, persist: true });