import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-CjTHbolG.js';
import { D as DownloadAction } from './Types-CIxfEdV7.js';
import { VerdocsEndpoint, getEnvelopeDocumentPageDisplayUri, getEnvelope } from '@verdocs/js-sdk';
import { t as throttle } from './utils-D9l-GFdv.js';
import { S as SDKError } from './errors-C1sRVZWv.js';
import { S as Store } from './Datastore-C7hFgM52.js';
import './index-BglCURB-.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 isCertReady = this.signed && hasCert;
        const isCertificateDisabled = action === DownloadAction.certificate && !isCertReady;
        const isZipDisabled = action === DownloadAction.zip && (this.polling || !isCertReady);
        const isCombinedDisabled = action === DownloadAction.combined && !isCertReady;
        if (isCertificateDisabled || isZipDisabled || isCombinedDisabled)
            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 isCombinedReady = this.signed && hasCertificateDoc;
        const allDone = !this.polling && certReady;
        const attachmentBusy = !this.signed;
        return (h("verdocs-dialog", { key: 'a877948153b6b0ee7eda1f2e19d4df7f061f72d5', onExit: () => this.exit.emit() }, h("div", { key: '51da52f3f20473ae1901ce60e5edafd144521478', slot: "heading", class: "heading-container" }, h("h3", { key: 'a68c34c0de3959409e1939aed35879402cba2b09', style: { margin: '0', fontSize: '1.25rem', fontWeight: '600', padding: '16px 24px' } }, "Download")), h("div", { key: '66ccef7e477d5862f8d941ec558310aaffd9e266', slot: "content", class: "content" }, attachments.length <= 2 &&
            attachments.map(doc => (h("div", { class: "download-option", onClick: () => this.handleOptionClick(DownloadAction.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: '6eda124edbc14116b63bb1a508d5f6ca2c4ee81d', class: "info-message" }, "Multiple documents attached. Please use the ZIP option below to download all files."), h("div", { key: 'c7adc5310b532cb7ca3ce64d90547c0648675af9', class: { 'download-option': true, 'disabled': !certReady }, onClick: () => this.handleOptionClick(DownloadAction.certificate), title: !certReady ? 'Certificate not yet available' : '' }, h("div", { key: '099cece3ea7a1927a8b7d9632ffa8cc3e6220868', class: "icon-container", innerHTML: CertificateIcon }), h("div", { key: '0e09d9749a9967291fdde0a35a30287d31bedec7', class: "text-container" }, h("div", { key: '3f76cc900207bf06c5207d79d68b1219c066bde8', class: "label" }, "Certificate"), h("div", { key: '34fe2b37c150b66173f61f76cc5d8d77c74e61e8', 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: '2e1d48989564753b19f7431db7b231f1858542ce', class: { 'download-option': true, 'disabled': !isCombinedReady }, onClick: () => this.handleOptionClick(DownloadAction.combined), title: !isCombinedReady ? 'Waiting for all documents to be ready' : '' }, h("div", { key: 'de52875477a5f583624357061ee21ab65fbbf53a', class: "icon-container", innerHTML: ZipIcon }), h("div", { key: 'c7ce9b867f7e6f5eec060a65d4487e3f33814025', class: "text-container" }, h("div", { key: '63ffd99d31428740c9b19ea44281a4b966c4dab8', class: "label" }, "Combined"), h("div", { key: '5ff20fcacc17c4dbee9034181158a5202a3391b5', class: "description" }, "Merge envelopes & certificate into a single PDF")), isCombinedReady ? (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: 'feb5a60d1538f3367b082f5c8f2b41fde4c44997', class: { 'download-option': true, 'disabled': !allDone }, onClick: () => this.handleOptionClick(DownloadAction.zip), title: !allDone ? 'Waiting for all documents to be ready' : '' }, h("div", { key: 'dcad103a22173198f247005ba7cd611986865f89', class: "icon-container", innerHTML: ZipIcon }), h("div", { key: 'eccfb0e7f4a7aca6b180089a0b2392ec51e8a21d', class: "text-container" }, h("div", { key: '94586ca4646cab77493d98e85e3f0a1bcf7cc911', class: "label" }, "All Files"), h("div", { key: '2d42fa14e73f9df2e39fcd8ff8f9cb107ffd2246', 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: 'a087605743e0b7e7f3de01aa20dc5be28b8723d5', 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: '7ed2187dfb4ef248411d777ad2837ba18a85ec45', 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: '2697b58a7c65243705c15993e5a967894b725196', onExit: e => this.handleDismiss(e) }, h("div", { key: '0c6d340d05717b4580e001e8cff4d544f3dac072', slot: "heading", class: "heading" }, h("div", { key: 'e5e3c323b48a90431f2593a062715d316608dc71', class: "icon", innerHTML: QuestionIcon$1 }), h("div", { key: '8ebc86de76b84cf255efbf6bc8db8876142e858d', class: "title" }, "Ask the Sender a Question")), h("div", { key: 'c3f96587257dbd2e0ce98eba44a8ef7c3bba7c88', slot: "content", class: "content" }, h("textarea", { key: '22c2c8dd80e41e77e0bed92f0b48a81f85466532', name: "question", rows: 6, placeholder: "Enter your question...", onInput: (e) => (this.question = e.target.value) }, this.question)), h("div", { key: '11a32d726ead166b7b9bfa994a31de4c4998fdec', class: "footer", slot: "footer" }, h("div", { key: '3fa336237b33537b9154c1eb7dfcd6b929a28e1e', class: "buttons" }, h("button", { key: 'aedcec8fc3948515d93adce69f15eb048bdd824e', class: "cancel", onClick: () => this.handleCancel() }, "Cancel"), h("button", { key: '2bd012fe2e6866922edde4a4abadb943c78f44ef', class: 'ok', onClick: () => this.handleOk() }, "OK")))));
    }
};
VerdocsQuestionDialog.style = verdocsQuestionDialogCss();

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

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: '2016c55a9196cb3ec96678038df0db7daa21b64d', 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: '47d03008c756feb7d7d4ba55d3f7ebd14c46634f', 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: 'ec4243adcc09cd5ec12a91d0eb5164a05e1a15d0', class: "buttons" }, h("button", { key: '6783fd9a0a9c9b36d476291f2e7f8dd63c8fa66b', onClick: () => (this.askingQuestion = true) }, h("span", { key: '28d3a5b206498f12c4e18f64f00f7a75963172f7', innerHTML: QuestionIcon }), "Ask Sender a Question"), h("button", { key: '69509c288e80a550705880b66abb01bbc12b7a61', onClick: () => { var _a; return (_a = this.decline) === null || _a === void 0 ? void 0 : _a.emit(); } }, h("span", { key: '7bad75a4ff16fd23168045626cb579e78db9851d', innerHTML: DeclineIcon }), "Decline Signing"), h("button", { key: 'd5a61e976c924b04905f90117a3ffcb61a750a68', onClick: () => { var _a; return (_a = this.finishLater) === null || _a === void 0 ? void 0 : _a.emit(); } }, h("span", { key: '7ba6413299135e1731048ae3368df0ff5640a750', innerHTML: SaveIcon }), "Finish Later"))), h("div", { key: '1e77fd76a189e1dfdc60ef8d60b79fba5905ae22', 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: '57f9055f96d0a4bc6d0b2881a035156d1a3e1df2', 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: '8f07d35eff0a44bf56a3557c269830fe789573ec' }, "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: '89c5bbbc7d7a0c16cbe1b2116842696e357afaa0', 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: 'bdf20919570db98342527b912aca3508f952c3d0' }, "Privacy Policy")))), this.askingQuestion && (h("verdocs-question-dialog", { key: '925d2470a33d987ec5ede9b6ab39125a00115309', 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

//# sourceMappingURL=verdocs-download-dialog_4.entry.js.map