import { h } from "@stencil/core";
import { FormController } from "../../../ui-components/form/form";
import ProductOrServiceSchema from "./schemas/product-or-service-schema";
import { DisputeResponseFormStep } from "./dispute-response-form-types";
import { heading5 } from "../../../styles/parts";
import fileInputHandler from "./file-input-handler";
export class ProductOrService {
    constructor() {
        this.documentErrors = {};
        this.errors = {};
        this.documents = { service_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.productOrService));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(ProductOrServiceSchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b, _c;
        return (h("div", { key: 'befcaee1dd5343ec47a55f27dc51c1d18cd57a71' }, h("div", { key: '56005c7449374963a548ea89250cc8ebbf2e75e4', class: "row gy-3" }, h("div", { key: 'ba5cdd019cb69288b49570d59317079665bf2b81', class: "col-12" }, h("h2", { key: '494feff3a2bb645653c77c7d7b031e761ed8c253', class: "h5", part: heading5 }, "Product & Service Details")), h("div", { key: '84db8064cd1c110e64b56961838f62f8676aed19', class: "col-12" }, h("form-control-text", { key: '98e82b9ca4b27476bc9e523afaf13ce55df9cce5', label: "Product Description", name: "product_description", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.product_description, inputHandler: this.inputHandler, errorText: this.errors.product_description })), h("div", { key: 'da06d2ef195dbc8cee8680e3a4c9107849836ab3', class: "col-12" }, h("form-control-date", { key: '3d2fb41fccfddb65d92468a78e3f5a4cfd9a67b5', label: "Service Date", name: "service_date", defaultValue: (_b = this.disputeResponse) === null || _b === void 0 ? void 0 : _b.service_date, inputHandler: this.inputHandler, errorText: this.errors.service_date })), h("div", { key: '824410485b182d8e309468506a9c8ae19ce1461f', class: "col-12" }, h("form-control-file-v2", { key: 'f8f5d542260b88754c05b61f0d50374d1f66a93e', label: "Service Documentation", name: "service_documentation", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_c = this.documentErrors) === null || _c === void 0 ? void 0 : _c.service_documentation })))));
    }
    static get is() { return "product-or-service"; }
    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": []
                }
            }
        };
    }
}
;
