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: '4c665e302ef9e73300b2e8a8199a1bca4fbc7553' }, h("verdocs-dialog", { key: 'd22e5c4521b9e5afef6d23a61e0df2787e8ff483', persistent: true, onExit: () => this.handleCancel() }, h("div", { key: '5244c91f2cc688b936dfdccb4058c31c620ad4e2', slot: "heading", class: "heading" }, h("div", { key: 'ba2fbb864b8f7df54efb7f7b06241ef1acc64afd', class: "title" }, "Passcode Required")), h("div", { key: '60c75c98dd4af071a05c23aa714c0901f51fad86', slot: "content", class: "content" }, h("div", { key: '36f257208d95c5250f7c9507eec255d9109e7d75', class: "help-box" }, h("div", { key: '03d48212677d1739754f757fe121bbd5158a0505', class: "help-details" }, h("div", { key: '8f60c2bc945a2b506c91720b56f52e863d2c2309', 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: '29da253e3865a8d25762e6e6cf7b9cc18c33ecf0', id: "verdocs-passcode-input", value: this.response, onClick: e => e.stopPropagation(), placeholder: "Enter passcode...", onInput: (e) => (this.response = e.target.value) })), h("div", { key: '23be778ccfabd914752f77ed40f4d931332d6b7a', slot: "footer", class: "buttons footer" }, h("verdocs-button", { key: '73c3c19c8618b46da14762baa63edf1aa5985dc4', label: "Cancel", variant: "outline", onClick: () => this.handleCancel() }), h("verdocs-button", { key: '5d6f474ff34ef9e9ef2d1d475783bce69934ca99', 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",
                            "referenceLocation": "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",
                            "referenceLocation": "ISignerTokenResponse"
                        }
                    }
                }
            }];
    }
}
//# sourceMappingURL=verdocs-passcode-dialog.js.map
