import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-BIRwgFLv.js';
import { VerdocsEndpoint, getEnvelopeDocumentPageDisplayUri, getEnvelope } from '@verdocs/js-sdk';
import { t as throttle } from './utils-Deu82Q9L.js';
import { S as SDKError } from './errors-C1sRVZWv.js';
import { S as Store } from './Datastore-bS8INhRF.js';
import './index-dzBXqXlK.js';
import './Types-BqoC0yeA.js';

const verdocsDownloadDialogCss = "verdocs-download-dialog{-webkit-box-sizing:border-box;box-sizing:border-box;font-family:\"Inter\", \"Barlow\", sans-serif}verdocs-download-dialog .heading-container{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center}verdocs-download-dialog .content{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;gap:15px;padding:0 24px 20px 24px}verdocs-download-dialog .download-option{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;padding:12px 15px;border:1px solid #e5e7eb;border-radius:6px;cursor:pointer;-webkit-transition:all 0.2s ease;transition:all 0.2s ease;gap:15px;background:white}verdocs-download-dialog .download-option.disabled{opacity:0.5;cursor:not-allowed}verdocs-download-dialog .download-option.disabled:hover{background-color:white;border-color:#e5e7eb}verdocs-download-dialog .download-option:hover{border-color:#654dcb;background-color:#f9fafb}verdocs-download-dialog .icon-container{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:36px;height:36px;background-color:#f3f4f6;border-radius:50%;color:#4b5563;-ms-flex-negative:0;flex-shrink:0}verdocs-download-dialog .icon-container svg{width:18px;height:18px}verdocs-download-dialog .text-container{-ms-flex:1;flex:1}verdocs-download-dialog .text-container .label{font-weight:500;color:#111827;margin-bottom:2px}verdocs-download-dialog .text-container .description{font-size:13px;color:#6b7280}verdocs-download-dialog .status-indicator{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center;gap:2px;font-size:11px;color:#9ca3af;min-width:50px}verdocs-download-dialog .status-indicator .signed{color:#10b981}verdocs-download-dialog .status-indicator .spinner-inline{display:-ms-flexbox;display:flex;color:#9ca3af;-webkit-animation:rotate 2s linear infinite;animation:rotate 2s linear infinite}verdocs-download-dialog .status-indicator svg{width:16px;height:16px}verdocs-download-dialog .info-message{font-size:13px;color:#6b7280;font-style:italic;padding:0 4px}@-webkit-keyframes rotate{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes rotate{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}";

const DocumentIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13 2H6C5.46957 2 4.96086 2.21071 4.58579 2.58579C4.21071 2.96086 4 3.46957 4 4V20C4 20.5304 4.21071 21.0391 4.58579 21.4142C4.96086 21.7893 5.46957 22 6 22H18C18.5304 22 19.0391 21.7893 19.4142 21.4142C19.7893 21.0391 20 20.5304 20 20V9L13 2Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M13 2V9H20" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
const CertificateIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 15C15.866 15 19 11.866 19 8C19 4.13401 15.866 1 12 1C8.13401 1 5 4.13401 5 8C5 11.866 8.13401 15 12 15Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M8.21 13.89L7 23L12 20L17 23L15.79 13.88" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
const ZipIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10 16V22H14V16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M6 16H18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M20 22H4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 10L12 16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 12L12 16L16 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M4 16V4H20V16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
const CheckIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 6L9 17L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
const RefreshIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23 4V10H17" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M20.49 15A9 9 0 1 1 21.23 8" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
const VerdocsDownloadDialog = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.download = createEvent(this, "download");
        this.exit = createEvent(this, "exit");
        /**
         * If true, the envelope is considered signed.
         */
        this.signed = false;
        /**
         * If true, we are currently polling the server for updates.
         */
        this.polling = false;
        /**
         * The list of documents in the envelope.
         */
        this.documents = [];
        /**
         * If true, the envelope has a certificate available for download.
         */
        this.hasCertificate = false;
    }
    handleOptionClick(action, documentId) {
        const hasCert = this.documents.some(d => d.type === 'certificate') || this.hasCertificate;
        const certReady = this.signed && hasCert;
        if (action === 'certificate' && !certReady) {
            return;
        }
        if (action === 'zip' && (this.polling || !certReady)) {
            return;
        }
        this.download.emit({ action, documentId });
    }
    render() {
        const attachments = this.documents.filter(d => d.type === 'attachment').sort((a, b) => (a.order !== b.order ? a.order - b.order : a.created_at.localeCompare(b.created_at)));
        const hasCertificateDoc = this.documents.some(d => d.type === 'certificate') || this.hasCertificate;
        const certReady = this.signed && hasCertificateDoc;
        const allDone = !this.polling && certReady;
        const attachmentBusy = !this.signed;
        return (h("verdocs-dialog", { key: 'bbeaf815bfa639d92aba937fb2932171fb6a969d', onExit: () => this.exit.emit() }, h("div", { key: '3baaed7a0448b0b4487baf09996b0c0eed8dcc32', slot: "heading", class: "heading-container" }, h("h3", { key: '055f9b0b3a1cbc4bf1dde3f66d33afe3cd69c59a', style: { margin: '0', fontSize: '1.25rem', fontWeight: '600', padding: '16px 24px' } }, "Download")), h("div", { key: 'd02a5cadb9e6ccc26f42d11a04d11c8796553137', slot: "content", class: "content" }, attachments.length <= 2 &&
            attachments.map(doc => (h("div", { class: "download-option", onClick: () => this.handleOptionClick('document', doc.id) }, h("div", { class: "icon-container", innerHTML: DocumentIcon }), h("div", { class: "text-container" }, h("div", { class: "label" }, doc.name), h("div", { class: "description" }, "Download the document")), attachmentBusy ? (h("div", { class: "status-indicator" }, h("div", { class: "spinner-inline", innerHTML: RefreshIcon }))) : (h("div", { class: "status-indicator" }, h("div", { class: "signed", innerHTML: CheckIcon }), h("span", null, "Signed")))))), attachments.length > 2 && h("div", { key: '445d03fccd38d54dfce8b32528dd4ff869729b71', class: "info-message" }, "Multiple documents attached. Please use the ZIP option below to download all files."), h("div", { key: '82d95c21a9a16ab3536f85054e43333e44af83d0', class: { 'download-option': true, 'disabled': !certReady }, onClick: () => this.handleOptionClick('certificate'), title: !certReady ? 'Certificate not yet available' : '' }, h("div", { key: 'adc703860b88d7fa5cd945ed8a6436eaac4e0186', class: "icon-container", innerHTML: CertificateIcon }), h("div", { key: '36f00a3cf54559157cd472700d0d6c8ad6fea55e', class: "text-container" }, h("div", { key: 'f2329e85febf992f0ea1a601a7c355063f196942', class: "label" }, "Certificate"), h("div", { key: '9a9d90b9f55884fbfca9d289a753121737b07c0c', class: "description" }, "Download the certificate")), certReady ? (h("div", { class: "status-indicator" }, h("div", { class: "signed", innerHTML: CheckIcon }), h("span", null, "Ready"))) : (h("div", { class: "status-indicator" }, h("div", { class: "spinner-inline", innerHTML: RefreshIcon })))), h("div", { key: '05381515775fefc45fb04e935ece500a14fff159', class: { 'download-option': true, 'disabled': !allDone }, onClick: () => this.handleOptionClick('zip'), title: !allDone ? 'Waiting for all documents to be ready' : '' }, h("div", { key: 'e260f34177dde5d0994f593662c98f223f890da2', class: "icon-container", innerHTML: ZipIcon }), h("div", { key: '44a9a16e8c3a02449d331b9d74603ea8cfcd570b', class: "text-container" }, h("div", { key: '54d968ac458d60d1aac7c39c3206069317bf67a3', class: "label" }, "All Files"), h("div", { key: 'b5f7246c36b12d83fdb63d7e38e90957fec3dd32', class: "description" }, "Download everything as a ZIP file")), allDone ? (h("div", { class: "status-indicator" }, h("div", { class: "signed", innerHTML: CheckIcon }), h("span", null, "Ready"))) : (h("div", { class: "status-indicator" }, h("div", { class: "spinner-inline", innerHTML: RefreshIcon }))))), h("div", { key: 'e8f9a266b2b1302bc4a4170803737ce6c3cece6c', slot: "footer", style: { display: 'none' } })));
    }
};
VerdocsDownloadDialog.style = verdocsDownloadDialogCss;

const verdocsEnvelopeDocumentPageCss = "verdocs-envelope-document-page{width:100%;position:relative}verdocs-envelope-document-page .verdocs-envelope-document-page-layer{position:absolute;top:0;left:0;right:0;bottom:0;-webkit-box-shadow:0 0 10px 5px rgba(0, 0, 0, 0.0588235294);box-shadow:0 0 10px 5px rgba(0, 0, 0, 0.0588235294)}verdocs-envelope-document-page .verdocs-envelope-document-page-layer.img{width:100%}";

const VerdocsEnvelopeDocumentPage = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.pageRendered = createEvent(this, "pageRendered");
        /**
         * The endpoint to load from.
         */
        this.endpoint = VerdocsEndpoint.getDefault();
        /**
         * The ID of the envelope the document is for.
         */
        this.envelopeId = '';
        /**
         * The ID of the document to display.
         */
        this.documentId = '';
        /**
         * The page number being rendered. (Reminder: page numbers are 1-based.)
         */
        this.pageNumber = 1;
        /**
         * The "virtual" width of the page canvas. Defaults to 612 which at 72dpi is 8.5" wide. This is used to compute
         * the aspect ratio of the final rendered element when scaling up/down.
         */
        this.virtualWidth = 612;
        /**
         * The "virtual" height of the page canvas.  Defaults to 792 which at 72dpi is 11" tall. This is used to compute
         * the aspect ratio of the final rendered element when scaling up/down.
         */
        this.virtualHeight = 792;
        /**
         * The layers that will be rendered. The DOM structure will be a DIV container with one child DIV for each layer.
         * The parent DIV will have a unique ID, and each child DIV will have that ID with the layer name appended, e.g.
         * if `pages` was ['page', 'fields'] the structure will be:
         *
         * ```
         *     <div id="verdocs-envelope-document-page-ker2fr1p9">
         *       <div id="verdocs-envelope-document-page-ker2fr1p9-page"></div>
         *       <div id="verdocs-envelope-document-page-ker2fr1p9-fields"></div>
         *     </div>
         * ```
         */
        this.layers = [{ name: 'page', type: 'canvas' }];
        this.type = 'original';
        this.containerId = `verdocs-envelope-document-page-${Math.random().toString(36).substring(2, 11)}`;
        this.renderedWidth = this.virtualWidth;
        this.renderedHeight = this.virtualHeight;
        this.naturalWidth = this.virtualWidth;
        this.naturalHeight = this.virtualHeight;
        this.aspectRatio = this.virtualWidth / this.virtualHeight;
        this.skipFirstNotification = true;
        this.pageDisplayUri = 'https://verdocs-public-assets.s3.amazonaws.com/page-loading-placeholder.png';
    }
    async componentWillLoad() {
        this.pageDisplayUri = await getEnvelopeDocumentPageDisplayUri(this.endpoint, this.documentId, this.pageNumber, this.type);
    }
    componentDidLoad() {
        this.resizeObserver = new ResizeObserver(throttle(entries => {
            for (const entry of entries) {
                const renderedWidth = entry.contentRect.width;
                this.renderedWidth = renderedWidth;
                this.renderedHeight = this.virtualHeight * (renderedWidth / this.virtualWidth);
            }
            this.notifyRenderedSize();
        }, 100));
        this.resizeObserver.observe(this.container);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
    }
    // Left here for documentation purposes in case we find an edge case where this isn't true. But we apparently don't need this.
    // When we add the resize observer it will always be triggered at least once so notifying here as well is just a dupe.
    // componentDidRender() {
    //   this.notifyRenderedSize();
    // }
    notifyRenderedSize() {
        // We skip one notification because by default we will always get at least two, one when rendering the initial size
        // and a second once we're able to compute the scale size, when the resizeObserver sets renderedWidth/renderedHeight.
        if (this.skipFirstNotification) {
            this.skipFirstNotification = false;
            return;
        }
        this.pageRendered.emit({
            // container: this.container,
            containerId: this.containerId,
            documentId: this.documentId,
            pageNumber: this.pageNumber,
            virtualWidth: this.virtualWidth,
            virtualHeight: this.virtualHeight,
            renderedWidth: this.renderedWidth,
            renderedHeight: this.renderedHeight,
            naturalWidth: this.naturalWidth,
            naturalHeight: this.naturalHeight,
            aspectRatio: this.aspectRatio,
            xScale: this.renderedWidth / this.virtualWidth,
            yScale: this.renderedHeight / this.virtualHeight,
        });
    }
    render() {
        const height = `${this.renderedHeight}px`;
        return (h(Host, { key: '633b71e22df815319ad854618b74b035a6e43603', id: `${this.containerId}`, style: { height, flex: `0 0 ${height}` } }, this.layers.map(layer => layer.type === 'div' ? (h("div", { class: "verdocs-envelope-document-page-layer", id: `${this.containerId}-${layer.name}`, style: { height } })) : this.pageDisplayUri ? (h("img", { class: "verdocs-envelope-document-page-layer img", id: `${this.containerId}-${layer.name}`, src: this.pageDisplayUri, alt: `Page ${this.pageNumber}`, "aria-hidden": true, loading: "lazy", onLoad: (e) => {
                // Note that all we really care about is the aspect ratio. We track the natural Width and Height but they aren't really that
                // useful as individual values. The image will already have been scaled down to fit a DIV for display (100%, auto height).
                // Builder places fields offset into the rendered display area, not the original document's dimensions. So its X/Y values
                // for a field are based on the responsive Web view the Template editor was seeing. The IMG was scaled down there in the
                // exact same way, so we just honor it. We capture the natural width and height here more as information. Then we use the
                // aspect ratio to adjust the "virtual" height in case the page is not 8.5"x11".
                // TODO: Store this in the DB with each page.
                this.naturalWidth = e.target.naturalWidth;
                this.naturalHeight = e.target.naturalHeight;
                this.aspectRatio = this.naturalWidth / this.naturalHeight;
                this.virtualHeight = this.virtualWidth / this.aspectRatio;
                this.renderedHeight = e.target.offsetWidth / this.aspectRatio;
            } })) : (h("div", null)))));
    }
    get container() { return getElement(this); }
};
VerdocsEnvelopeDocumentPage.style = verdocsEnvelopeDocumentPageCss;

const verdocsQuestionDialogCss = "verdocs-question-dialog{top:0;left:0;right:0;bottom:0;position:fixed;-webkit-box-sizing:border-box;box-sizing:border-box;font-family:\"Inter\", \"Barlow\", sans-serif}verdocs-question-dialog.closed{display:none}verdocs-question-dialog textarea{-webkit-box-sizing:border-box;box-sizing:border-box;border:1px solid #707ae5;border-radius:4px;background:#ffffff;color:#000;width:100%;font-size:14px;padding:9px;outline:none}verdocs-question-dialog .heading .title{font-size:18px}verdocs-question-dialog .buttons{gap:20px;display:-ms-flexbox;display:flex;margin-top:24px;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:center;justify-content:center}verdocs-question-dialog .buttons button{-ms-flex:1;flex:1;border:0;height:38px;display:-ms-flexbox;display:flex;color:#ffffff;font-size:14px;cursor:pointer;border-radius:6px;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}verdocs-question-dialog .buttons button.cancel{background-color:#654dcb}verdocs-question-dialog .buttons button.ok{background-color:#55bc81}verdocs-question-dialog .buttons button.ok.single{max-width:150px}verdocs-question-dialog .buttons button:disabled{background-color:#6c727f}";

const QuestionIcon$1 = `<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10.4809 13.8423H15.4C16.2962 13.8423 17 13.1288 17 12.2764V5.56582C17 4.71348 16.2962 4 15.4 4H4.6C3.70383 4 3 4.71348 3 5.56582V12.2764C3 13.1288 3.70383 13.8423 4.6 13.8423H6.19908L6.2 17L6.20346 16.9997L6.20502 16.9988L10.4809 13.8423ZM6.79895 17.8034C6.35668 18.1298 5.73 18.0406 5.39921 17.6042C5.26989 17.4335 5.2 17.2262 5.2 17.0133L5.19937 14.8423H4.6C3.16406 14.8423 2 13.6935 2 12.2764V5.56582C2 4.14876 3.16406 3 4.6 3H15.4C16.8359 3 18 4.14876 18 5.56582V12.2764C18 13.6935 16.8359 14.8423 15.4 14.8423H10.81L6.79895 17.8034Z" fill="#ffffff"/></svg>`;
const VerdocsQuestionDialog = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.next = createEvent(this, "next");
        this.exit = createEvent(this, "exit");
        this.question = '';
        this.closed = false;
    }
    handleOk() {
        this.next.emit({ question: this.question });
    }
    handleCancel() {
        this.exit.emit();
    }
    // We need a separate event handler for clicking the background because it can receive events "through" other child components
    handleDismiss(e) {
        this.closed = true;
        if (e.target.className === 'background-overlay') {
            e.preventDefault();
            this.exit.emit();
        }
    }
    render() {
        return (h("verdocs-dialog", { key: 'd0e85744fa9901d1be794cd59f4c9b87922e6e91', onExit: e => this.handleDismiss(e) }, h("div", { key: '6d7ead703cdf217588ac98d2ac93a35644838b78', slot: "heading", class: "heading" }, h("div", { key: 'd07c6155fc98f51204a51add33d82afec7592c4b', class: "icon", innerHTML: QuestionIcon$1 }), h("div", { key: 'e9698d0aa4b24db343afd149adee95d9c3c0a52a', class: "title" }, "Ask the Sender a Question")), h("div", { key: 'cdef7a2b00c4c66e1748733e3c614e39ad456192', slot: "content", class: "content" }, h("textarea", { key: '81c88e1d61be54e7ba80c9101fb71bf903df8d1c', name: "question", rows: 6, placeholder: "Enter your question...", onInput: (e) => (this.question = e.target.value) }, this.question)), h("div", { key: 'a7d5a31362337e6c80c0ac5b2c6471efbacb9a23', class: "footer", slot: "footer" }, h("div", { key: '71ae8344f053cfd94dc6befed76933fe67f490d1', class: "buttons" }, h("button", { key: '04aec379b7b4f21885f72ed2016b10ac26730476', class: "cancel", onClick: () => this.handleCancel() }, "Cancel"), h("button", { key: '6e6e8bb27367c9a1167a49519da299d9ce9ee983', class: 'ok', onClick: () => this.handleOk() }, "OK")))));
    }
};
VerdocsQuestionDialog.style = verdocsQuestionDialogCss;

const verdocsSignFooterCss = "verdocs-sign-footer {\n  left: 0;\n  right: 0;\n  bottom: 0;\n  height: 48px;\n  display: -ms-flexbox;\n  display: flex;\n  color: #616161;\n  position: fixed;\n  font-size: 12px;\n  padding: 0 24px;\n  -ms-flex-align: center;\n  align-items: center;\n  -ms-flex-direction: row;\n  flex-direction: row;\n  background: #ffffff;\n  container-type: inline-size;\n  border-top: 1px solid #e0e0e0;\n  -ms-flex-pack: justify;\n  justify-content: space-between;\n  font-family: var(--verdocs-primary-font, \"Inter\", \"Barlow\", sans-serif);\n  -webkit-transition: 0.5s cubic-bezier(0.35, 0, 0.25, 1);\n  transition: 0.5s cubic-bezier(0.35, 0, 0.25, 1);\n}\nverdocs-sign-footer a {\n  color: #616161;\n  cursor: pointer;\n  text-decoration: none;\n  border-bottom: 1px dotted #616161;\n}\nverdocs-sign-footer.loading {\n  display: none;\n}\nverdocs-sign-footer .powered-by {\n  white-space: nowrap;\n}\nverdocs-sign-footer .buttons {\n  -ms-flex: 0;\n  flex: 0;\n  gap: 16px;\n  display: -ms-flexbox;\n  display: flex;\n  -ms-flex-direction: row;\n  flex-direction: row;\n  white-space: nowrap;\n  -ms-flex-align: center;\n  align-items: center;\n}\nverdocs-sign-footer .buttons button {\n  gap: 4px;\n  border: none;\n  display: -ms-flexbox;\n  display: flex;\n  outline: none;\n  cursor: pointer;\n  -ms-flex-direction: row;\n  flex-direction: row;\n  -ms-flex-align: center;\n  align-items: center;\n  background: transparent;\n}\nverdocs-sign-footer .buttons div {\n  gap: 4px;\n  display: -ms-flexbox;\n  display: flex;\n  -ms-flex-direction: row;\n  flex-direction: row;\n  -ms-flex-align: center;\n  align-items: center;\n}\nverdocs-sign-footer .links {\n  -ms-flex: 0;\n  flex: 0;\n  gap: 8px;\n  display: -ms-flexbox;\n  display: flex;\n  -ms-flex-direction: row;\n  flex-direction: row;\n  white-space: nowrap;\n}\nverdocs-sign-footer.just-buttons .buttons {\n  -ms-flex: 1;\n  flex: 1;\n  -ms-flex-pack: center;\n  justify-content: center;\n}\n@container (max-width: 720px) {\n  verdocs-sign-footer.has-buttons .powered-by {\n    display: none;\n  }\n}\n@container (max-width: 540px) {\n  verdocs-sign-footer.no-buttons .powered-by {\n    display: none;\n  }\n  verdocs-sign-footer.has-buttons .links {\n    display: none;\n  }\n  verdocs-sign-footer .buttons {\n    -ms-flex: 1;\n    flex: 1;\n    -ms-flex-pack: center;\n    justify-content: center;\n  }\n}";

const QuestionIcon = `<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10.4809 13.8423H15.4C16.2962 13.8423 17 13.1288 17 12.2764V5.56582C17 4.71348 16.2962 4 15.4 4H4.6C3.70383 4 3 4.71348 3 5.56582V12.2764C3 13.1288 3.70383 13.8423 4.6 13.8423H6.19908L6.2 17L6.20346 16.9997L6.20502 16.9988L10.4809 13.8423ZM6.79895 17.8034C6.35668 18.1298 5.73 18.0406 5.39921 17.6042C5.26989 17.4335 5.2 17.2262 5.2 17.0133L5.19937 14.8423H4.6C3.16406 14.8423 2 13.6935 2 12.2764V5.56582C2 4.14876 3.16406 3 4.6 3H15.4C16.8359 3 18 4.14876 18 5.56582V12.2764C18 13.6935 16.8359 14.8423 15.4 14.8423H10.81L6.79895 17.8034Z" fill="#424242"/></svg>`;
const DeclineIcon = `<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M7.14645 7.14645C7.34171 6.95118 7.65829 6.95118 7.85355 7.14645L10 9.29289L12.1464 7.14645C12.3417 6.95118 12.6583 6.95118 12.8536 7.14645C13.0488 7.34171 13.0488 7.65829 12.8536 7.85355L10.7071 10L12.8536 12.1464C13.0488 12.3417 13.0488 12.6583 12.8536 12.8536C12.6583 13.0488 12.3417 13.0488 12.1464 12.8536L10 10.7071L7.85355 12.8536C7.65829 13.0488 7.34171 13.0488 7.14645 12.8536C6.95118 12.6583 6.95118 12.3417 7.14645 12.1464L9.29289 10L7.14645 7.85355C6.95118 7.65829 6.95118 7.34171 7.14645 7.14645ZM3 6C3 4.34315 4.34315 3 6 3H14C15.6569 3 17 4.34315 17 6V14C17 15.6569 15.6569 17 14 17H6C4.34315 17 3 15.6569 3 14V6ZM6 4C4.89543 4 4 4.89543 4 6V14C4 15.1046 4.89543 16 6 16H14C15.1046 16 16 15.1046 16 14V6C16 4.89543 15.1046 4 14 4H6Z" fill="#424242"/></svg>`;
const SaveIcon = `<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M3 5C3 3.89543 3.89543 3 5 3H13.3787C13.9091 3 14.4178 3.21071 14.7929 3.58579L16.4142 5.20711C16.7893 5.58218 17 6.09089 17 6.62132V15C17 16.1046 16.1046 17 15 17H5C3.89543 17 3 16.1046 3 15V5ZM5 4C4.44772 4 4 4.44772 4 5V15C4 15.5523 4.44772 16 5 16L5 11.5C5 10.6716 5.67157 10 6.5 10H13.5C14.3284 10 15 10.6716 15 11.5V16C15.5523 16 16 15.5523 16 15V6.62132C16 6.3561 15.8946 6.10175 15.7071 5.91421L14.0858 4.29289C13.8983 4.10536 13.6439 4 13.3787 4L13 4V6.5C13 7.32843 12.3284 8 11.5 8L7.5 8C6.67157 8 6 7.32843 6 6.5L6 4H5ZM7 4L7 6.5C7 6.77614 7.22386 7 7.5 7L11.5 7C11.7761 7 12 6.77614 12 6.5V4L7 4ZM14 16V11.5C14 11.2239 13.7761 11 13.5 11H6.5C6.22386 11 6 11.2239 6 11.5V16H14Z" fill="#424242"/></svg>`;
const VerdocsSignFooter = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.askQuestion = createEvent(this, "askQuestion");
        this.decline = createEvent(this, "decline");
        this.finishLater = createEvent(this, "finishLater");
        this.sdkError = createEvent(this, "sdkError");
        this.envelopeListenerId = null;
        /**
         * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
         */
        this.endpoint = VerdocsEndpoint.getDefault();
        /**
         * The envelope ID to render. Set ONE OF templateId or envelopeId. If both are set, envelopeId will be ignored.
         */
        this.envelopeId = '';
        /**
         * If the recipient is "done," some buttons will be hidden.
         */
        this.isDone = false;
        /**
         * Event fired when the envelope is updated in any way. May be used for tasks such as cache invalidation or reporting to other systems.
         */
        // @Event({composed: true}) envelopeUpdated: EventEmitter<{endpoint: VerdocsEndpoint; envelope: IEnvelope; event: string}>;
        this.askingQuestion = false;
        this.declinine = false;
        this.envelope = null;
    }
    async componentWillLoad() {
        var _a, _b, _c;
        try {
            // NOTE: The caller must have a signing session already active and shared to us via
            // the endpoint property.
            if (!this.envelopeId) {
                console.log(`[FOOTER] Missing required envelope ID ${this.envelopeId}`);
                return;
            }
            this.listenToEnvelope();
        }
        catch (e) {
            console.log('[FOOTER] Error loading envelope', e);
            (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(new SDKError(e.message, (_b = e.response) === null || _b === void 0 ? void 0 : _b.status, (_c = e.response) === null || _c === void 0 ? void 0 : _c.data));
        }
    }
    disconnectedCallback() {
        this.unlistenToEnvelope();
    }
    async listenToEnvelope() {
        console.log('[FOOTER] Loading envelope', this.envelopeId);
        this.unlistenToEnvelope();
        Store.subscribe('envelopes', this.envelopeId, () => getEnvelope(this.endpoint, this.envelopeId), false, (envelope) => {
            this.envelope = envelope;
        });
    }
    unlistenToEnvelope() {
        if (this.envelopeListenerId) {
            Store.store.delListener(this.envelopeListenerId);
            this.envelopeListenerId = null;
        }
    }
    // handleRecipientAction(recipient: IRecipient, id: string) {
    //   console.log('[SIDEBAR] Recipient action', id, recipient);
    //   switch (id) {
    //     case 'update':
    //       this.showUpdateDialog = recipient.role_name;
    //       break;
    //
    //     case 'reminder':
    //       remindRecipient(this.endpoint, this.envelopeId, recipient.role_name)
    //         .then(() => {
    //           VerdocsToast('Reminder Sent', {style: 'success'});
    //         })
    //         .catch(e => {
    //           console.log('[SIDEBAR] Error resending invitation', e);
    //           VerdocsToast('Error resending invitation: ' + e.message, {style: 'error'});
    //         });
    //       break;
    //
    //     case 'reinvite':
    //       this.showReinviteDialog = recipient.role_name;
    //       break;
    //
    //     case 'inperson':
    //       this.showRecipientDialog = recipient.role_name;
    //       break;
    //
    //     case 'modify':
    //       VerdocsToast('This feature will be enabled in a future release. Please try again later.', {style: 'info'});
    //       break;
    //
    //     case 'details':
    //       VerdocsToast('This feature will be enabled in a future release. Please try again later.', {style: 'info'});
    //       break;
    //   }
    // }
    // handleUpdateRecipient(originalRecipient: IRecipient, updatedRecipient: IRecipient) {
    //   console.log('Updating recipient', originalRecipient, updatedRecipient);
    //   const fields: any = {};
    //   if (updatedRecipient.email !== originalRecipient.email) {
    //     fields.email = updatedRecipient.email;
    //   }
    //   if (updatedRecipient.phone !== originalRecipient.phone) {
    //     fields.phone = updatedRecipient.phone;
    //   }
    //   if (updatedRecipient.message !== originalRecipient.message) {
    //     fields.message = updatedRecipient.message;
    //   }
    //   if (updatedRecipient.first_name !== originalRecipient.first_name) {
    //     fields.first_name = updatedRecipient.first_name;
    //   }
    //   if (updatedRecipient.last_name !== originalRecipient.last_name) {
    //     fields.last_name = updatedRecipient.last_name;
    //   }
    //
    //   if (Object.keys(fields).length > 0) {
    //     updateRecipient(this.endpoint, this.envelopeId, originalRecipient.role_name, fields)
    //       .then(r => {
    //         // TODO: Reload the envelope?
    //         VerdocsToast('Recipient updated', {style: 'success'});
    //         console.log('[SIDEBAR] Updated recipient', r);
    //         Store.getEnvelope(this.endpoint, this.envelopeId, true);
    //         this.showUpdateDialog = '';
    //       })
    //       .catch(e => {
    //         VerdocsToast(e.response.data.error, {style: 'error'});
    //         this.showUpdateDialog = '';
    //       });
    //   } else {
    //     this.showUpdateDialog = '';
    //   }
    // }
    render() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
        const hasPoweredBy = !!((_b = (_a = this.envelope) === null || _a === void 0 ? void 0 : _a.organization) === null || _b === void 0 ? void 0 : _b.powered_by_label);
        const hasLinks = !!((_d = (_c = this.envelope) === null || _c === void 0 ? void 0 : _c.organization) === null || _d === void 0 ? void 0 : _d.terms_use_url) || !!((_f = (_e = this.envelope) === null || _e === void 0 ? void 0 : _e.organization) === null || _f === void 0 ? void 0 : _f.privacy_policy_url);
        const hasButtons = !this.isDone;
        return (h(Host, { key: '1fc747454660d14e69a4a65cbf71cd81f010d9c3', class: { 'has-buttons': hasButtons, 'no-buttons': !hasButtons, 'has-powered-by': hasPoweredBy, 'has-links': hasLinks, 'just-buttons': !hasPoweredBy && !hasLinks } }, ((_h = (_g = this.envelope) === null || _g === void 0 ? void 0 : _g.organization) === null || _h === void 0 ? void 0 : _h.powered_by_label) && (h("div", { key: 'f8cae910df0d2c759af9ee2200aef58b80bb3f37', class: "powered-by" }, ((_k = (_j = this.envelope) === null || _j === void 0 ? void 0 : _j.organization) === null || _k === void 0 ? void 0 : _k.powered_by_url) ? (h("a", { href: (_m = (_l = this.envelope) === null || _l === void 0 ? void 0 : _l.organization) === null || _m === void 0 ? void 0 : _m.powered_by_url, target: "_blank", rel: "noopener noreferrer" }, h("span", null, (_p = (_o = this.envelope) === null || _o === void 0 ? void 0 : _o.organization) === null || _p === void 0 ? void 0 : _p.powered_by_label))) : (h("span", null, (_r = (_q = this.envelope) === null || _q === void 0 ? void 0 : _q.organization) === null || _r === void 0 ? void 0 : _r.powered_by_label)))), !this.isDone && (h("div", { key: '06bd0f346de34e567cfa2e2e5ae8bf06a8b6a1d9', class: "buttons" }, h("button", { key: 'bee3e5c2aad8cc60c9b291b14bba2e5eb1ee9c32', onClick: () => (this.askingQuestion = true) }, h("span", { key: 'f42932689a3330a72b61e853d389eac39b2362a3', innerHTML: QuestionIcon }), "Ask Sender a Question"), h("button", { key: '7012513a564bfc6d5a416467843d1056ad5427c8', onClick: () => { var _a; return (_a = this.decline) === null || _a === void 0 ? void 0 : _a.emit(); } }, h("span", { key: '7e0506798239ec5935d2c98e577e482744e3aa1f', innerHTML: DeclineIcon }), "Decline Signing"), h("button", { key: '3b3765e04da3d7f0749f2cbc24d84f2a3b6edb47', onClick: () => { var _a; return (_a = this.finishLater) === null || _a === void 0 ? void 0 : _a.emit(); } }, h("span", { key: '0511b44dc272d16fdd2d2d6098f603f651c9bc50', innerHTML: SaveIcon }), "Finish Later"))), h("div", { key: 'cbea53ab6d84e268e1750bb0fec9f846040bd4ad', class: "links" }, ((_t = (_s = this.envelope) === null || _s === void 0 ? void 0 : _s.organization) === null || _t === void 0 ? void 0 : _t.terms_use_url) && (h("a", { key: '45628f09eaf2105226ab8b906e20e787de1e28ff', href: (_v = (_u = this.envelope) === null || _u === void 0 ? void 0 : _u.organization) === null || _v === void 0 ? void 0 : _v.terms_use_url, target: "_blank", rel: "noopener noreferrer" }, h("span", { key: '08dc74860f84fb34c64a21c5409571998e5ce217' }, "Terms of Use"))), ((_x = (_w = this.envelope) === null || _w === void 0 ? void 0 : _w.organization) === null || _x === void 0 ? void 0 : _x.privacy_policy_url) && (h("a", { key: 'c3cc1fb07f7de02108762611c5b69206218e4b59', href: (_z = (_y = this.envelope) === null || _y === void 0 ? void 0 : _y.organization) === null || _z === void 0 ? void 0 : _z.privacy_policy_url, target: "_blank", rel: "noopener noreferrer" }, h("span", { key: 'c4bc436c7f7213bc0af61859ef27d8c41e331884' }, "Privacy Policy")))), this.askingQuestion && (h("verdocs-question-dialog", { key: '93380ca89c21673f72c53e4d4f941b7d35c0079e', onNext: e => {
                var _a;
                (_a = this.askQuestion) === null || _a === void 0 ? void 0 : _a.emit({ question: e.detail.question });
                this.askingQuestion = false;
            }, onExit: () => (this.askingQuestion = false) }))));
    }
};
VerdocsSignFooter.style = verdocsSignFooterCss;

export { VerdocsDownloadDialog as verdocs_download_dialog, VerdocsEnvelopeDocumentPage as verdocs_envelope_document_page, VerdocsQuestionDialog as verdocs_question_dialog, VerdocsSignFooter as verdocs_sign_footer };
//# sourceMappingURL=verdocs-download-dialog.verdocs-envelope-document-page.verdocs-question-dialog.verdocs-sign-footer.entry.js.map
