import { h, Host } from "@stencil/core";
import { verifySigner } from "@verdocs/js-sdk";
import { DefaultEndpoint } from "../../../utils/Environment";
import { VerdocsToast } from "../../../utils/Toast";
/**
 * Prompt the user to confirm their identity with a passcode.
 */
export class VerdocsPasscodeDialog {
    constructor() {
        /**
         * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
         */
        this.endpoint = DefaultEndpoint;
        this.response = '';
    }
    handleCancel() {
        this.exit.emit();
    }
    handleSubmit() {
        verifySigner(this.endpoint, { auth_method: 'passcode', code: this.response })
            .then(response => {
            console.log('Verification completed', response);
            this.next.emit({ response });
        })
            .catch(e => {
            VerdocsToast('Invalid passcode. Please try again.');
            console.log('Invalid code', e);
        });
        this.response = '';
    }
    render() {
        return (h(Host, { key: 'f611b89b6a936352f80d2032a571cd7e86daa2e9' }, h("verdocs-dialog", { key: '0997b0a07b87e3ca6f25979a461f0ba186fa0cf4', persistent: true, onExit: () => this.handleCancel() }, h("div", { key: 'd32ff440d13ed705a8311804fee910d714d08705', slot: "heading", class: "heading" }, h("div", { key: 'c5124f039fecd6bd695d369061da325bc10a97e6', class: "title" }, "Passcode Required")), h("div", { key: '2635315f3c53a957ae8aee32ce47dc04e7547a4a', slot: "content", class: "content" }, h("div", { key: '7ebdd819c026e2c968019996f2965d76058c019e', class: "help-box" }, h("div", { key: '7d6811fd11a47bdd8dfc03f628eb21f41fd697b6', class: "help-details" }, h("div", { key: 'aecfd4feaf6b0b669476b40b53b159a6a280dbd9', class: "help-text" }, "This document is protected by a passcode. Please enter it below to proceed. If you do not have one, please contact the sender."))), h("verdocs-text-input", { key: 'e53aad4fd9b05297383730c13d2db086444b8f84', id: "verdocs-passcode-input", value: this.response, onClick: e => e.stopPropagation(), placeholder: "Enter passcode...", onInput: (e) => (this.response = e.target.value) })), h("div", { key: 'f747484402b61c0b83efc5fdbde75b85afc2ada1', slot: "footer", class: "buttons footer" }, h("verdocs-button", { key: '16015a1a9be9fed6fc78485ea0a91ce19cdbe68d', label: "Cancel", variant: "outline", onClick: () => this.handleCancel() }), h("verdocs-button", { key: '2077f16df851706e1c80c4118b303f0ffdcc17dc', label: 'Submit', onClick: () => this.handleSubmit(), disabled: !this.response })))));
    }
    static get is() { return "verdocs-passcode-dialog"; }
    static get originalStyleUrls() {
        return {
            "$": ["verdocs-passcode-dialog.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["verdocs-passcode-dialog.css"]
        };
    }
    static get properties() {
        return {
            "endpoint": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "VerdocsEndpoint",
                    "resolved": "VerdocsEndpoint",
                    "references": {
                        "VerdocsEndpoint": {
                            "location": "import",
                            "path": "@verdocs/js-sdk",
                            "id": "node_modules::VerdocsEndpoint"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "DefaultEndpoint"
            }
        };
    }
    static get states() {
        return {
            "response": {}
        };
    }
    static get events() {
        return [{
                "method": "exit",
                "name": "exit",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event fired when the step is cancelled. This is called exit to avoid conflicts with the JS-reserved \"cancel\" event name."
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "next",
                "name": "next",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event fired when the process has completed successfully."
                },
                "complexType": {
                    "original": "{response: ISignerTokenResponse}",
                    "resolved": "{ response: ISignerTokenResponse; }",
                    "references": {
                        "ISignerTokenResponse": {
                            "location": "import",
                            "path": "@verdocs/js-sdk",
                            "id": "node_modules::ISignerTokenResponse"
                        }
                    }
                }
            }];
    }
}
//# sourceMappingURL=verdocs-passcode-dialog.js.map
