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 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>`;
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 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' } })));
    }
    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": "download",
                "name": "download",
                "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
