import * as actions from './actions'
import getters from './getters'
import mutations from './mutations'
import * as L from '../../../utils/localStorageKeys'

const state = {
  enrolForm: JSON.parse(localStorage.getItem(L.ENROL_FORM)) || null,
  memberDetail: JSON.parse(localStorage.getItem(L.MEMBER_DETAILS)) || [],
  sponsorMemberDetails: JSON.parse(localStorage.getItem(L.ENROL_SPONSOR_MEMBER)) || false,
  upgradeMemberDetails: JSON.parse(localStorage.getItem(L.ENROL_UPGRADE_MEMBER)) || {},
  placementMemberDetails: JSON.parse(localStorage.getItem(L.ENROL_PLACEMENT_MEMBER)) || {},
  verification: {
    code: '',
    get: {},
    post: {},
  },
  enrolmentTypes: JSON.parse(localStorage.getItem(L.ENROL_TYPES)) || [],
  memberPlacementVerify: {},
  guest: [],
  guide: JSON.parse(localStorage.getItem(L.ENROL_GUIDE_STATUS)) || false,
  country_id: JSON.parse(localStorage.getItem(L.ENROL_COUNTRY_ID)) || 1,
  categories: JSON.parse(localStorage.getItem(L.ENROL_PRODUCT_CATEGORIES)) || [],
  enrolmentData: '',
  tempEnrolmentData: null,
  enrolmentTaiwanFiles: null,
  selectedEnrolLanguage: JSON.parse(localStorage.getItem(L.ENROL_SELECTED_LANGUAGE)) || null,
  enrolmentTabStatus: JSON.parse(localStorage.getItem(L.ENROL_TAB_STATUS)) || {
    tabs: [],
    tabCount: 0,
    activeTabId: false,
    disableChecker: true,
  },
  bankList: [],
  countryList: [],
  salaryRanges: [],
  bankCardDetails: JSON.parse(localStorage.getItem(L.BANK_CARD_DETAILS)) || {
    bank_country_name: '',
    bank_account_ic: '',
    account_holder_name: '',
    swift_code: '',
    country_bank_id: '',
    acccount_number: '',
    payout_company: '',
    account_type: '',
  },
  mPayDetails: JSON.parse(localStorage.getItem(L.MPAY_DETAILS)) || {
    card_country_name: '',
    card_holder_name: '',
    card_expiry_date: '',
    card_expiry_year: '',
    payout_company: '',
  },
  supportingDocDetails: JSON.parse(localStorage.getItem(L.SUPPORTING_DOC_DETAILS)) || [],
  nricDocsDetails: JSON.parse(localStorage.getItem(L.NRIC_DOCS_DETAILS)) || [],
  rentalCardDetails: JSON.parse(localStorage.getItem(L.CARD_RENTAL_DETAILS)) || {
    card_type_id: '',
    card_company_id: '',
    card_holder_name: '',
    country_bank_id: '',
    card_number: '',
    card_expiry_date: '',
    credit_card_photocopy: [],
    income_proof: [],
    status: '',
  },
  rentalCardDetailsEshop: JSON.parse(localStorage.getItem(L.CARD_RENTAL_DETAILS_ESHOP)) || {
    card_type_id: '',
    card_company_id: '',
    card_holder_name: '',
    country_bank_id: '',
    card_number: '',
    card_expiry_date: '',
    credit_card_photocopy: [],
    income_proof: [],
    status: '',
  },
  selectedRecurringInfoType: localStorage.getItem(L.SELECTED_RECURRING_INFO_TYPE) || '',
  // List of Memebership Types
  membershipTypes: [],
  membership_type: 'EK Smart',
  cardRecurringInfoFields: JSON.parse(localStorage.getItem(L.ENROL_RECURRING_INFO)) || null,
  payeeInfoFields: JSON.parse(localStorage.getItem(L.ENROL_PAYEE_INFO)) || null,
  employmentDetailsFields: (() => {
    let data = localStorage.getItem(L.ENROL_EMPLOYMENT_DETAILS)
    if (data) {
      return JSON.parse(data)
    } else {
      return null
    }
  })(),
  employmentFormStatus: (() => {
    let data = sessionStorage.getItem(L.ENROL_EMPLOYMENT_FORM_STATUS)
    if (data) {
      return JSON.parse(data)
    } else {
      return { eshop: false, enrolment: false }
    }
  })(),
  productSearchFilter: { selectedSort: 1, selectedCategory: null, search: '', perPage: 12 },
}

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