import * as actions from './actions'
import getters from './getters'
import mutations from './mutations'
import {
  ESHOP_PRODUCT_CATEGORIES,
  ESHOP_PRODUCT_CURRENT_CATEGORY,
  ESHOP_PRODUCT_SELECTED_SUB_CATEGORIES,
  ESHOP_PRODUCT_FILTERED_SALES_TYPES,
  ESHOP_PRODUCT_FILTERED_IS_EK_SMART,
  ESHOP_PRODUCT_FILTERED_PRICE_RANGE,
  ESHOP_PRODUCT_FILTERED_CV_RANGE,
  ESHOP_PRODUCT_SORT_ORDER,
  ESHOP_PRODUCT_SEARCH_NAME,
  ESHOP_PRODUCT_FREE,
  ESHOP_PRODUCT_MEMBER_KIT,
  IS_RETAIL,
} from '../../../utils/localStorageKeys'

const state = {
  selectedSubCategories: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_SELECTED_SUB_CATEGORIES)) || [],
  filterSalesTypeIds: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_FILTERED_SALES_TYPES)) || [],
  filterIsEkSmart: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_FILTERED_IS_EK_SMART)) || false,
  filterPriceRange: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_FILTERED_PRICE_RANGE)) || [0, 0],
  currentCategory: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_CURRENT_CATEGORY)) || { id: false },
  filterCvRange: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_FILTERED_CV_RANGE)) || [0, 0],
  categories: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_CATEGORIES)) || [],
  sortOrder: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_SORT_ORDER)) || 0,
  searchName: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_SEARCH_NAME)) || '',
  freeProducts: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_FREE)) || [],
  memberKit: JSON.parse(localStorage.getItem(ESHOP_PRODUCT_MEMBER_KIT)) || [],
  products: [],
  totalProducts: 0,
  productDetails: [],
  productsPerPage: 12,
  availableFilters: {
    cv_range: { min: 0, max: 0 },
    price_range: { min: 0, max: 0 },
  },
  isRetailPrice: JSON.parse(sessionStorage.getItem(IS_RETAIL)) || false,
}

export default {
  state,
  actions,
  mutations,
  getters,
}
