import { h } from '../webmapgl.core.js';

import { a as _t } from './chunk-cf921ba9.js';

class DownloadButton {
    async openPopover(ev) {
        const options = {
            component: document.createElement('gl-download-list'),
            componentProps: {
                files: Array.from(this.el.querySelectorAll('gl-download-file'))
            },
            ev: ev
        };
        const popover = await this.popoverCtrl.create(options);
        await popover.present();
        return popover;
    }
    ;
    render() {
        let title = _t('webmapgl.download-button.title');
        return (h("ion-button", { onClick: (e) => this.openPopover(e), title: title },
            h("ion-icon", { slot: "icon-only", name: 'download' })));
    }
    static get is() { return "gl-download-button"; }
    static get properties() { return {
        "el": {
            "elementRef": true
        },
        "popoverCtrl": {
            "connect": "ion-popover-controller"
        }
    }; }
}

class DownloadList {
    render() {
        const header = _t('webmapgl.download-list.header');
        let fileList = this.files.map((file) => {
            let formatString = [file.format, file.size]
                .filter((item) => item)
                .join(', ');
            if (formatString)
                formatString = `(${formatString})`;
            return (h("ion-item", null,
                h("ion-label", { "text-wrap": true },
                    file.label,
                    " ",
                    formatString),
                h("ion-button", { slot: "end", href: file.url, title: _t('webmapgl.download-list.download', { file: file.label }) },
                    h("ion-icon", { slot: "icon-only", name: "download" }))));
        });
        return (h("ion-content", null,
            h("ion-list", null,
                h("ion-list-header", null, header),
                fileList)));
    }
    static get is() { return "gl-download-list"; }
    static get properties() { return {
        "files": {
            "type": "Any",
            "attr": "files"
        }
    }; }
}

export { DownloadButton as GlDownloadButton, DownloadList as GlDownloadList };
