import { h } from "@stencil/core";
import { FormController } from "../../../ui-components/form/form";
import ElectronicEvidenceSchema from "./schemas/electronic-evidence-schema";
import { DisputeResponseFormStep } from "./dispute-response-form-types";
import { heading5 } from "../../../styles/parts";
import fileInputHandler from "./file-input-handler";
export class ElectronicEvidence {
    constructor() {
        this.documentErrors = {};
        this.errors = {};
        this.documents = { activity_log: [] };
        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.electronicEvidence));
    }
    ;
    componentWillLoad() {
        this.form = new FormController(ElectronicEvidenceSchema);
    }
    componentDidLoad() {
        this.form.errors.subscribe(errors => {
            this.errors = Object.assign({}, errors);
        });
    }
    render() {
        var _a, _b;
        return (h("div", { key: 'cf4615613589be984c7d5b6b50f0b5239895d81d' }, h("div", { key: '1f96c50146d009cc4d0d0ccbee41c31144e7f746', class: "row gy-3" }, h("div", { key: '3a671ff5c959efaee8dc57dda073de113489f0a6', class: "col-12" }, h("h2", { key: '3b73879b357d3465c6c76b27db17b6dbdce7c538', class: "h5", part: heading5 }, "Electronic Evidence")), h("div", { key: '35c0ff43bc1dcdba8916b51da636347395c98901', class: "col-12" }, h("form-control-text", { key: 'cdabf70034babf41ba227f66936f8b340f104ca3', label: "Purchase IP Address", name: "customer_purchase_ip_address", helpText: "The IP address used by the customer during the purchase.", defaultValue: (_a = this.disputeResponse) === null || _a === void 0 ? void 0 : _a.customer_purchase_ip_address, inputHandler: this.inputHandler, errorText: this.errors.customer_purchase_ip_address })), h("div", { key: 'd9920bf1548e14c6adadbc63dc41a1a90cc1a3cc', class: "col-12" }, h("form-control-file-v2", { key: '8eec5b79872eeeda77702d9f4cc9003a627e6682', label: "Activity Logs", name: "activity_log", helpText: "Any server or activity logs that provide evidence of the customer's access to or download of the purchased digital product. This information should encompass IP addresses, relevant timestamps, and any detailed records of activity.", onChange: (e) => fileInputHandler(e, this.documents), errorText: (_b = this.documentErrors) === null || _b === void 0 ? void 0 : _b.activity_log })))));
    }
    static get is() { return "electronic-evidence"; }
    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": []
                }
            }
        };
    }
}
;
