import { h } from "@stencil/core";
import { FormController } from "../../../ui-components/form/form";
import ShippingDetailsSchema from "./schemas/shipping-details-schema";
import { DisputeResponseFormStep } from "./dispute-response-form-types";
import { heading5 } from "../../../styles/parts";
import fileInputHandler from "./file-input-handler";
export class ShippingDetails {
    constructor() {
        this.documentErrors = {};
        this.errors = {};
        this.documents = { shipping_documentation: [] };
        this.documentList = [];
        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.shippingDetails));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(ShippingDetailsSchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b, _c, _d, _e;
        return (h("div", { key: 'dabe709653579ef5c19806146e149fdbfa65686c' }, h("div", { key: '07d9f91a68d770daed48f84678ffa2f2182b4625', class: "row gy-3" }, h("div", { key: '6052cb801e0e8cfc73a946e32d37a35e4726f8aa', class: "col-12" }, h("h2", { key: '8cea7d2ac9d5e53a01d4e8f3a14b3b6947e72f19', class: "h5", part: heading5 }, "Shipping Details")), h("div", { key: '79adf032e4435f8e89e5d848e397c8389c35ee99', class: "col-12" }, h("form-control-text", { key: '4dd59285b595b33944168e5a959fbf7686b71c4c', label: "Shipping Carrier Name", name: "shipping_carrier", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.shipping_carrier, inputHandler: this.inputHandler, errorText: this.errors.shipping_carrier })), h("div", { key: 'e25cb74edb5133cfaa1c8abb6194a43104d51e80', class: "col-12" }, h("form-control-text", { key: 'bdb47ebe63e9717db4308d89e890bdd01ecad9fc', label: "Tracking Number", name: "shipping_tracking_number", defaultValue: (_b = this.disputeResponse) === null || _b === void 0 ? void 0 : _b.shipping_tracking_number, inputHandler: this.inputHandler, errorText: this.errors.shipping_tracking_number })), h("div", { key: 'ccb5a0facc6aa6f7c311f3d1a395faa214b4c099', class: "col-12" }, h("form-control-date", { key: 'a2e1a7af287b7afae6ba7451bd4f51292e2e14fa', label: "Date Shipped", name: "shipping_date", defaultValue: (_c = this.disputeResponse) === null || _c === void 0 ? void 0 : _c.shipping_date, inputHandler: this.inputHandler, errorText: this.errors.shipping_date })), h("div", { key: 'ce176cd89d1c2fbf4cb3e1a84d84fb38e7f77ae9', class: "col-12" }, h("form-control-textarea", { key: '5f09d91a79081a8dea6eb44b44e6500f5f9b547b', label: "Shipping Address", name: "shipping_address", defaultValue: (_d = this.disputeResponse) === null || _d === void 0 ? void 0 : _d.shipping_address, inputHandler: this.inputHandler, errorText: this.errors.shipping_address })), h("div", { key: 'b41048055f1fc82bb383d300f32e13efa2a4f0fc', class: "col-12" }, h("form-control-file-v2", { key: '2fda26e5404c3a2a0c10261ffc1e005b688e057a', label: "Shipping Documentation", name: "shipping_documentation", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_e = this.documentErrors) === null || _e === void 0 ? void 0 : _e.shipping_documentation })))));
    }
    static get is() { return "shipping-details"; }
    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": {},
            "documentList": {}
        };
    }
    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": []
                }
            }
        };
    }
}
;
