import { h } from "@stencil/core";
import { FormController } from "../../../ui-components/form/form";
import CancellationPolicySchema from "./schemas/cancellation-policy-schema";
import { DisputeResponseFormStep } from "./dispute-response-form-types";
import { heading5 } from "../../../styles/parts";
import fileInputHandler from "./file-input-handler";
export class CancellationPolicy {
    constructor() {
        this.documentErrors = {};
        this.errors = {};
        this.documents = { cancellation_policy: [] };
        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.cancellationPolicy));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(CancellationPolicySchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b, _c;
        return (h("div", { key: '8812e04b5497b1b75d4afcc18084ff224efe11e0' }, h("div", { key: 'fd414b2ebd443b490ec68bb1788efce0824877e6', class: "row gy-3" }, h("div", { key: '300e7b1afa78dac54bd3240af7ad1bdd6f386134', class: "col-12" }, h("h2", { key: 'c85c78cf40224ad06db9746c929d312d6ac53613', class: "h5", part: heading5 }, "Cancellation Policy")), h("div", { key: 'fab79ca4fb6f343674698b87fd5e713c6028ce8b', class: "col-12" }, h("form-control-textarea", { key: '106094d74237d258091a60d14e0bdeecf1106584', label: "Cancellation Policy Disclosure", name: "cancellation_policy_disclosure", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.cancellation_policy_disclosure, inputHandler: this.inputHandler, errorText: this.errors.cancellation_policy_disclosure })), h("div", { key: 'ac5d1d534d30176483fc490947e3bf65fe41afa3', class: "col-12" }, h("form-control-textarea", { key: 'd0972bf1837f9f23de6925517756ec18e1fac3fe', label: "Cancellation Rebuttal", name: "cancellation_rebuttal", defaultValue: (_b = this.disputeResponse) === null || _b === void 0 ? void 0 : _b.cancellation_rebuttal, inputHandler: this.inputHandler, errorText: this.errors.cancellation_rebuttal })), h("div", { key: '135463253e19c6a2d5ff86b04413e6838f824a89', class: "col-12" }, h("form-control-file-v2", { key: 'ef0a3a1d1113f5cb4e97bbf1017841b75463f690', label: "Upload Cancellation Policy", name: "cancellation_policy", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_c = this.documentErrors) === null || _c === void 0 ? void 0 : _c.cancellation_policy })))));
    }
    static get is() { return "cancellation-policy"; }
    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": []
                }
            }
        };
    }
}
;
