'use strict';

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

const core = require('./core-b7b9d752.js');
const drop_controller = require('./drop.controller-ebab46a4.js');
const i18n_provider = require('./i18n.provider-5632e5ed.js');

var Translations;
(function (Translations) {
    Translations["DRAG_INSTRUCTION"] = "Draggable item. Press up or down to move.";
})(Translations || (Translations = {}));
const ColumnMenuItem = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.handleFocused = false;
        this.anjDrop = core.createEvent(this, "anjDrop", 7);
    }
    onVisibleChange() {
        this.visible ? this.dropController.connect() : this.dropController.disconnect();
    }
    connectedCallback() {
        this.dragController = new drop_controller.DragController(this.element, this.getDropData.bind(this));
        this.dropController = new drop_controller.DropController(this.element);
        if (this.visible) {
            this.dropController.connect();
        }
    }
    disconnectedCallback() {
        this.dropController.disconnect();
    }
    onToggle(event) {
        if (event.detail.checked === this.visible || event.detail.value !== this.name) {
            event.stopPropagation();
        }
    }
    onEnter(ev) {
        if (this.handleFocused && (ev.key === 'ArrowDown' || ev.key === 'ArrowUp')) {
            const detail = this.getDropData();
            detail['targetIndex'] = (ev.key === 'ArrowDown') ? detail.currentIndex + 1 : detail.currentIndex - 1;
            if (detail['targetIndex'] < 0) {
                return;
            }
            this.anjDrop.emit(detail);
        }
    }
    onFocus() {
        this.handleFocused = true;
    }
    onBlur() {
        this.handleFocused = false;
    }
    getDropData() {
        return {
            currentIndex: this.index
        };
    }
    render() {
        return (core.h(core.Host, { draggable: this.handleFocused, class: { 'anj-handle-focused': this.handleFocused }, onMouseEnter: () => this.onFocus(), onMouseLeave: () => this.onBlur() }, this.visible && !this.disabled
            ? core.h("anj-button", { "aria-label": this.translator(Translations.DRAG_INSTRUCTION), context: "free", onMouseDown: () => this.dragController.connect(), onMouseUp: () => this.dragController.disconnect() }, core.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24" }, core.h("path", { d: "M20 9H4v2h16V9zM4 15h16v-2H4v2z" })))
            : undefined, core.h("anj-checkbox", { checked: this.visible, value: this.name }, core.h("slot", null))));
    }
    get element() { return core.getElement(this); }
    static get watchers() { return {
        "visible": ["onVisibleChange"]
    }; }
    static get style() { return ".sc-anj-column-menu-item-h {\n  display: block;\n  margin-left: -0.5rem;\n  padding: 0.25rem 1.5rem 0.25rem 2.75rem;\n  position: relative;\n  text-transform: capitalize;\n}\n.sc-anj-column-menu-item-h:hover anj-button.sc-anj-column-menu-item, .anj-handle-focused.sc-anj-column-menu-item-h anj-button.sc-anj-column-menu-item {\n  opacity: 1;\n}\n.sc-anj-column-menu-item-h anj-button.sc-anj-column-menu-item {\n  left: 0.75rem;\n  opacity: 0;\n  position: absolute;\n  top: 50%;\n  -webkit-transform: translateY(-50%);\n  transform: translateY(-50%);\n  -webkit-transition: opacity 0.2s ease;\n  transition: opacity 0.2s ease;\n}"; }
};
i18n_provider.Tunnel.injectProps(ColumnMenuItem, ['translator']);

exports.anj_column_menu_item = ColumnMenuItem;
