import { h } from "@stencil/core";
import { FormController } from "../../../ui-components/form/form";
import DuplicateChargeSchema from "./schemas/duplicate-charge-schema";
import { DisputeResponseFormStep } from "./dispute-response-form-types";
import { heading5 } from "../../../styles/parts";
import fileInputHandler from "./file-input-handler";
export class DuplicateCharge {
    constructor() {
        this.documentErrors = {};
        this.errors = {};
        this.documents = { duplicate_charge_documentation: [] };
        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.duplicateCharge));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(DuplicateChargeSchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b, _c;
        return (h("div", { key: 'ec4cfa15f2830ec56dfd9184728c1badeb9e1dfd' }, h("div", { key: '0e107461e759478735aecabea93baf060169dd14', class: "row gy-3" }, h("div", { key: '22b9223c3e92d2183d65d9125a3ebefd341c140f', class: "col-12" }, h("h2", { key: 'cf386e687b18a4f232b935a847270d8ad463db32', class: "h5", part: heading5 }, "Duplicate Charge")), h("div", { key: 'dd8cc52b7b6cfe955a09e29c145f70761db87068', class: "col-12" }, h("form-control-text", { key: 'ff024fd4e90adc3a991036eb535258bad98ab199', label: "Original Payment ID", name: "duplicate_charge_original_payment_id", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.duplicate_charge_original_payment_id, inputHandler: this.inputHandler, errorText: this.errors.duplicate_charge_original_payment_id })), h("div", { key: '0df77b3c8d8a8a777c8258cd0ca075df73552ee4', class: "col-12" }, h("form-control-textarea", { key: '27bfe00c3bdab393b35f3ca26360db65f487d789', label: "Duplicate Charge Explanation", name: "duplicate_charge_explanation", defaultValue: (_b = this.disputeResponse) === null || _b === void 0 ? void 0 : _b.duplicate_charge_explanation, inputHandler: this.inputHandler, errorText: this.errors.duplicate_charge_explanation })), h("div", { key: '8420318e367111cb73c1235c363973d7f34aa25c', class: "col-12" }, h("form-control-file-v2", { key: '71717a0c8d02e2c8198b365f61b1a6727a619e6b', label: "Duplicate Charge Documentation", name: "duplicate_charge_documentation", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_c = this.documentErrors) === null || _c === void 0 ? void 0 : _c.duplicate_charge_documentation })))));
    }
    static get is() { return "duplicate-charge"; }
    static get properties() {
        return {
            "disputeResponse": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "dispute-response"
            },
            "documentErrors": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "document-errors",
                "defaultValue": "{}"
            }
        };
    }
    static get states() {
        return {
            "form": {},
            "errors": {},
            "documents": {}
        };
    }
    static get methods() {
        return {
            "validateAndSubmit": {
                "complexType": {
                    "signature": "(onSuccess: (formData: any, documentList: DisputeEvidenceDocument[], formStep: DisputeResponseFormStep) => void) => Promise<void>",
                    "parameters": [{
                            "name": "onSuccess",
                            "type": "(formData: any, documentList: DisputeEvidenceDocument[], formStep: DisputeResponseFormStep) => void",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "DisputeEvidenceDocument": {
                            "location": "import",
                            "path": "../../../api/DisputeEvidenceDocument",
                            "id": "src/api/DisputeEvidenceDocument.ts::DisputeEvidenceDocument"
                        },
                        "DisputeResponseFormStep": {
                            "location": "import",
                            "path": "./dispute-response-form-types",
                            "id": "src/components/dispute-management/dispute-response/dispute-response-form-types.ts::DisputeResponseFormStep"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
}
;
