import { r as registerInstance, e as createEvent, h } from './chunk-eb0263ab.js';
import { _ as _t } from './chunk-a41b3114.js';

class DrawToolbar {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.visible = false;
        this.featureCount = 0;
        this.cancelText = _t('webmapgl.draw-toolbar.cancel');
        this.color = 'primary';
        this.confirmText = _t('webmapgl.draw-toolbar.confirm');
        this.label = _t('webmapgl.draw-toolbar.label');
        this.maxFeatures = 1;
        this.minFeatures = 1;
        this.glDrawCancel = createEvent(this, "glDrawCancel", 7);
        this.glDrawConfirm = createEvent(this, "glDrawConfirm", 7);
    }
    handleDrawEnter(e) {
        if (e.detail.mapId != this.mapId)
            return;
        this.featureCount = 0;
        this.visible = true;
    }
    handleDrawExit(e) {
        if (e.detail.mapId != this.mapId)
            return;
        this.visible = false;
    }
    handleDrawCreate(e) {
        if (e.detail.mapId != this.mapId)
            return;
        this.featureCount += 1;
    }
    handleDrawDelete(e) {
        if (e.detail.mapId != this.mapId)
            return;
        this.featureCount -= 1;
    }
    cancel() {
        this.glDrawCancel.emit({
            mapId: this.mapId
        });
    }
    confirm() {
        this.glDrawConfirm.emit({
            mapId: this.mapId
        });
    }
    render() {
        if (!this.visible)
            return;
        let small = screen.width <= 640;
        let canConfirm = this.featureCount >= this.minFeatures &&
            this.featureCount <= this.maxFeatures;
        return (h("ion-toolbar", { color: this.color }, h("ion-title", null, this.label), h("ion-buttons", { slot: "end" }, h("ion-button", { onClick: () => { this.cancel(); } }, h("ion-icon", { slot: (small) ? 'icon-only' : 'start', name: "close" }), (small) ? null : this.cancelText), h("ion-button", { onClick: () => {
                if (canConfirm)
                    this.confirm();
            }, disabled: !canConfirm }, h("ion-icon", { slot: (small) ? 'icon-only' : 'start', name: "checkmark" }), (small) ? null : this.confirmText))));
    }
}

export { DrawToolbar as gl_draw_toolbar };
