'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const __chunk_1 = require('./chunk-91f43df3.js');
const __chunk_2 = require('./chunk-a2a6832b.js');

class DrawToolbar {
    constructor(hostRef) {
        __chunk_1.registerInstance(this, hostRef);
        this.visible = false;
        this.featureCount = 0;
        this.cancelText = __chunk_2._t('webmapgl.draw-toolbar.cancel');
        this.color = 'primary';
        this.confirmText = __chunk_2._t('webmapgl.draw-toolbar.confirm');
        this.label = __chunk_2._t('webmapgl.draw-toolbar.label');
        this.maxFeatures = 1;
        this.minFeatures = 1;
        this.glDrawCancel = __chunk_1.createEvent(this, "glDrawCancel", 7);
        this.glDrawConfirm = __chunk_1.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 (__chunk_1.h("ion-toolbar", { color: this.color }, __chunk_1.h("ion-title", null, this.label), __chunk_1.h("ion-buttons", { slot: "end" }, __chunk_1.h("ion-button", { onClick: () => { this.cancel(); } }, __chunk_1.h("ion-icon", { slot: (small) ? 'icon-only' : 'start', name: "close" }), (small) ? null : this.cancelText), __chunk_1.h("ion-button", { onClick: () => {
                if (canConfirm)
                    this.confirm();
            }, disabled: !canConfirm }, __chunk_1.h("ion-icon", { slot: (small) ? 'icon-only' : 'start', name: "checkmark" }), (small) ? null : this.confirmText))));
    }
}

exports.gl_draw_toolbar = DrawToolbar;
