class DocWizard extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
Document Generator Wizard
`;
this.shadowRoot.getElementById('generateBtn').addEventListener('click', this.handleGenerate.bind(this));
}
handleGenerate() {
const form = this.shadowRoot.getElementById('docForm');
if (!form.checkValidity()) {
form.reportValidity();
return;
}
const formData = {
agreement_date: this.shadowRoot.getElementById('agreement_date').value,
territory: this.shadowRoot.getElementById('territory').value,
vendor_name_en: this.shadowRoot.getElementById('vendor_name_en').value,
vendor_name_ar: this.shadowRoot.getElementById('vendor_name_ar').value,
vendor_cr: this.shadowRoot.getElementById('vendor_cr').value,
vendor_address: this.shadowRoot.getElementById('vendor_address').value,
delivery_mode: this.shadowRoot.getElementById('delivery_mode').value,
commission_pct: this.shadowRoot.getElementById('commission_pct').value,
payment_terms: this.shadowRoot.getElementById('payment_terms').value,
start_date: this.shadowRoot.getElementById('start_date').value,
term_months: this.shadowRoot.getElementById('term_months').value,
auto_renewal: this.shadowRoot.getElementById('auto_renewal').value,
aldobi_sign_name: this.shadowRoot.getElementById('aldobi_sign_name').value,
aldobi_sign_title: this.shadowRoot.getElementById('aldobi_sign_title').value,
vendor_sign_name: this.shadowRoot.getElementById('vendor_sign_name').value,
vendor_sign_title: this.shadowRoot.getElementById('vendor_sign_title').value,
enable_social_media: 'true',
enable_data_minimization: 'true',
enable_delay_policy: 'true',
enable_dispute_policy: 'true'
};
// Apply business rules for default values
if (!formData.commission_pct) {
formData.commission_pct = formData.delivery_mode === 'aldobi_delivery' ? '30' : '15';
}
// Dispatch custom event with form data
this.dispatchEvent(new CustomEvent('generate-document', {
bubbles: true,
composed: true,
detail: formData
}));
}
}
customElements.define('doc-wizard', DocWizard);