import FormFieldGroup from "../Components/FormFieldGroup"; class BillingView { constructor(selector, elements) { this.el = elements; this.billingFormFields = new FormFieldGroup({ baseSelector: '.woocommerce-checkout', contentSelector: selector, template: (data) => { const valueOfSelect = (selectSelector, key) => { if (!key) { return ''; } const selectElement = document.querySelector(selectSelector); const option = selectElement.querySelector(`option[value="${key}"]`); return option ? option.textContent : key; } if (data.isEmpty()) { return `

Billing details Edit

Please fill in your billing details.
`; } return `

Billing details Edit

${data.value('email')}
${data.value('company')}
${data.value('firstName')} ${data.value('lastName')}
${data.value('street1')}
${data.value('street2')}
${data.value('postCode')} ${data.value('city')}
${valueOfSelect('#billing_state', data.value('stateCode'))}
${valueOfSelect('#billing_country', data.value('countryCode'))}
${data.value('phone')}
`; }, fields: { email: { 'valuePath': 'email', }, firstName: { 'selector': '#billing_first_name_field', 'valuePath': 'billing.name.firstName', }, lastName: { 'selector': '#billing_last_name_field', 'valuePath': 'billing.name.lastName', }, street1: { 'selector': '#billing_address_1_field', 'valuePath': 'billing.address.addressLine1', }, street2: { 'selector': '#billing_address_2_field', 'valuePath': null }, postCode: { 'selector': '#billing_postcode_field', 'valuePath': 'billing.address.postalCode', }, city: { 'selector': '#billing_city_field', 'valuePath': 'billing.address.adminArea2', }, stateCode: { 'selector': '#billing_state_field', 'valuePath': 'billing.address.adminArea1', }, countryCode: { 'selector': '#billing_country_field', 'valuePath': 'billing.address.countryCode', }, company: { 'selector': '#billing_company_field', 'valuePath': null, }, phone: { 'selector': '#billing_phone_field', 'valuePath': null, }, } }); } activate() { this.billingFormFields.activate(); } deactivate() { this.billingFormFields.deactivate(); } setData(data) { this.billingFormFields.setData(data); } } export default BillingView;