import { AgreementsInterface, Agreement, AppAreas } from '..'
import Vue from 'vue'
import Const from '@/config/const'

export default class Default implements AgreementsInterface {
  appArea: AppAreas = 'enrolment'

  processAgreement(
    rootState: any,
    rootGetters: any,
    country: string,
    links: { [p: string]: string }
  ): Agreement | null {
    if (rootGetters['eshop/getCartHasRental'] === true) {
      let agreement: Agreement = {
        name: 'enrolment',
        messages: (msg => {
          if (country === 'malaysia') {
            msg.push(Vue.i18n.translate('Enrolment.Agreement.Malaysia.Waive')!)
          }
          return msg
        })([
          Vue.i18n.translate('Enrolment.Agreement.Rental', {
            agreement: `<a target='_blank' href='${links['termsOfAgreement']}'>${Vue.i18n.co(
              'Enrolment.Agreement.toa.Title'
            )!}</a>`,
            rental: `<a target='_blank' href='${links['rentalTerms']}'>${Vue.i18n.translate(
              'Eshop.Agreement.RentalTerms'
            )!}</a>`,
            website: `<a target='_blank' href='${Const.constLinks.COMPANY_SITE.value}'>${Const.constLinks.COMPANY_SITE.text}</a>`,
          })!,
        ])!,
      }

      return agreement
    }

    return null
  }
}
