import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { c as create$3, a as create$6, F as FormController } from './form.js';
import { D as DisputeResponseFormStep, f as fileInputHandler } from './file-input-handler.js';
import { a2 as heading5 } from './parts.js';
import { d as defineCustomElement$5 } from './custom-popper2.js';
import { d as defineCustomElement$4 } from './form-control-file-v22.js';
import { d as defineCustomElement$3 } from './form-control-help-text3.js';
import { d as defineCustomElement$2 } from './form-control-textarea2.js';
import { d as defineCustomElement$1 } from './form-control-tooltip2.js';

const RefundPolicySchema = create$3({
    refund_policy_disclosure: create$6().nullable(),
    refund_refusal_explanation: create$6().nullable(),
});

const RefundPolicy = /*@__PURE__*/ proxyCustomElement(class RefundPolicy extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.documentErrors = {};
        this.errors = {};
        this.documents = { refund_policy: [], receipt: [] };
        this.inputHandler = (name, value) => {
            this.form.setValues(Object.assign(Object.assign({}, this.form.values.getValue()), { [name]: value }));
        };
    }
    async validateAndSubmit(onSuccess) {
        const documentList = Object.values(this.documents).flat();
        this.form.validateAndSubmit((formData) => onSuccess(formData, documentList, DisputeResponseFormStep.refundPolicy));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(RefundPolicySchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b, _c, _d;
        return (h("div", { key: 'd5419f7dc7ca4e66522437969b451c7adfda6b06' }, h("div", { key: 'f74344edd56fe88d481f3c428aee3f7a3170ef1a', class: "row gy-3" }, h("div", { key: 'ad826fd7a497664e8a9a97bf4f749ddd5f4899a4', class: "col-12" }, h("h2", { key: 'f792af239a7df56d2a7289fae8ee487048343851', class: "h5", part: heading5 }, "Refund Policy and Receipt")), h("div", { key: '5a159d8fbb74d7580a9d6ef34d1a752b68525251', class: "col-12" }, h("form-control-textarea", { key: '8fdcac1c9336874635d955f651b44389ddc3d576', label: "Refund Policy Disclosure", name: "refund_policy_disclosure", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.refund_policy_disclosure, inputHandler: this.inputHandler })), h("div", { key: 'ca0d7a0c5161d572a27459ec5847bd6aedda8552', class: "col-12" }, h("form-control-textarea", { key: '7dde3212e5453772afbc4dfff8de5285d29ec3b3', label: "Refund Refusal Explanation", name: "refund_refusal_explanation", defaultValue: (_b = this.disputeResponse) === null || _b === void 0 ? void 0 : _b.refund_refusal_explanation, inputHandler: this.inputHandler })), h("div", { key: 'ec5615813cceb9b2eaaf327e4a4fb2785f341ce8', class: "col-12" }, h("form-control-file-v2", { key: '38d6901b619eb353da9b6066957579caa97064e3', label: "Upload Refund Policy", name: "refund_policy", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_c = this.documentErrors) === null || _c === void 0 ? void 0 : _c.refund_policy })), h("div", { key: '64245ce028bff37a6f9852e75d1b2e6ba27fd3ef', class: "col-12" }, h("form-control-file-v2", { key: '126ce22ff40995cfc0d4f059b2463a98a6dfcb50', label: "Upload Receipt", name: "receipt", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_d = this.documentErrors) === null || _d === void 0 ? void 0 : _d.receipt })))));
    }
}, [256, "refund-policy", {
        "disputeResponse": [8, "dispute-response"],
        "documentErrors": [8, "document-errors"],
        "form": [32],
        "errors": [32],
        "documents": [32],
        "validateAndSubmit": [64]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["refund-policy", "custom-popper", "form-control-file-v2", "form-control-help-text", "form-control-textarea", "form-control-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "refund-policy":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RefundPolicy);
            }
            break;
        case "custom-popper":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "form-control-file-v2":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "form-control-help-text":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "form-control-textarea":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "form-control-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RefundPolicy as R, defineCustomElement as d };
