import { h } from "@stencil/core";
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 ChevronRight = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9 18L15 12L9 6" 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 CircleIcon = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2"/></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>`;
export class VerdocsDownloadDialog {
    constructor() {
        /**
         * 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 canDownloadCert = this.signed && hasCert;
        if ((action === 'certificate' || action === 'zip') && !canDownloadCert) {
            return;
        }
        this.next.emit({ action, documentId });
    }
    render() {
        const attachments = this.documents.filter(d => d.type === 'attachment').sort((a, b) => a.order - b.order);
        const hasCertificateDoc = this.documents.some(d => d.type === 'certificate') || this.hasCertificate;
        const canDownloadFinals = this.signed && hasCertificateDoc;
        return (h("verdocs-dialog", { key: '1f3eda2e32cb5bdcd409a99c23d1cf6a104f0848', onExit: () => this.exit.emit() }, h("div", { key: '5efe04c9ae05ae69b4127d299fce5e0a91dc8515', slot: "heading", class: "heading-container" }, h("h3", { key: '3e157afe6c10acf7de8465da84b8ac8b9fd43a27', style: { margin: '0', fontSize: '1.25rem', fontWeight: '600', padding: '16px 24px' } }, "Download"), this.polling && (h("div", { key: '5ad3a1fa22819106f8586a20bf3b53857122f9e4', class: "polling-indicator", title: "Checking for updates..." }, h("div", { key: '7bd6ff763a0dd044e50ec8c25c1b1cef0b3993c9', class: "spinner", innerHTML: RefreshIcon })))), h("div", { key: '256315253dbbc5da0bd8c8b2d2cbb1ce8d398da8', 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" }, this.signed ? 'Download the document' : 'Download the document')), h("div", { class: "status-indicator" }, this.signed ? h("div", { class: "signed", innerHTML: CheckIcon }) : h("div", { class: "unsigned", innerHTML: CircleIcon }), h("span", null, this.signed ? 'Signed' : 'In Progress')), h("div", { class: "arrow", innerHTML: ChevronRight })))), attachments.length > 2 && h("div", { key: 'a8b998b71ade27a3615689e3a87eb3d5a385133e', class: "info-message" }, "Multiple documents attached. Please use the ZIP option below to download all files."), h("div", { key: 'e9aaf13d0903f5c9490ff1b67fe4fd3b40774ad7', class: { 'download-option': true, 'disabled': !canDownloadFinals }, onClick: () => this.handleOptionClick('certificate'), title: !canDownloadFinals ? 'Certificate not yet available' : '' }, h("div", { key: '54afca498036b3146b650e9c763965b9ec473b51', class: "icon-container", innerHTML: CertificateIcon }), h("div", { key: 'bf6ffaaaae31cb5ee1416ab0a13df80e18285b9e', class: "text-container" }, h("div", { key: 'fb2606a0e127a073031f2c3828778c8ef71047e1', class: "label" }, "Certificate"), h("div", { key: '2dd12b55b37acc1de0f5ccb5d4d1d3635aeebdf7', class: "description" }, "Download the certificate")), h("div", { key: 'fcb974c2842e7f3651235513b97b2d6cb500b771', class: "arrow", innerHTML: ChevronRight })), h("div", { key: 'b9caabe10e57a1dea7c6015a5b769d236b973f63', class: { 'download-option': true, 'disabled': !canDownloadFinals }, onClick: () => this.handleOptionClick('zip'), title: !canDownloadFinals ? 'Certificate not yet available' : '' }, h("div", { key: 'ef7e94af475d82581e25782b405d729168aacae5', class: "icon-container", innerHTML: ZipIcon }), h("div", { key: 'd969b98d4db2630b59d27a7cd170fd829d22166e', class: "text-container" }, h("div", { key: 'd63270f5d483f8ecfa7b4d9612aa739d2b6d1853', class: "label" }, "All Files"), h("div", { key: 'f74e6585fb1e84b90c2a09366ebfd016a4765cc3', class: "description" }, "Download everything as a ZIP file")), h("div", { key: '9965c39b090e7908e532658633f711fbe821a4cb', class: "arrow", innerHTML: ChevronRight }))), h("div", { key: 'a5640b4a944db48063ee0d0cbab257cdc264e2b4', slot: "footer", style: { display: 'none' } })));
    }
    static get is() { return "verdocs-download-dialog"; }
    static get originalStyleUrls() {
        return {
            "$": ["verdocs-download-dialog.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["verdocs-download-dialog.css"]
        };
    }
    static get properties() {
        return {
            "signed": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If true, the envelope is considered signed."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "signed",
                "defaultValue": "false"
            },
            "polling": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If true, we are currently polling the server for updates."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "polling",
                "defaultValue": "false"
            },
            "documents": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "any[]",
                    "resolved": "any[]",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The list of documents in the envelope."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "hasCertificate": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If true, the envelope has a certificate available for download."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-certificate",
                "defaultValue": "false"
            }
        };
    }
    static get events() {
        return [{
                "method": "next",
                "name": "next",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event fired when an option is selected."
                },
                "complexType": {
                    "original": "{action: 'document' | 'certificate' | 'zip'; documentId?: string}",
                    "resolved": "{ action: \"zip\" | \"document\" | \"certificate\"; documentId?: string; }",
                    "references": {}
                }
            }, {
                "method": "exit",
                "name": "exit",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event fired when Cancel is pressed or background is clicked."
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
}
//# sourceMappingURL=verdocs-download-dialog.js.map
