"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AtomicIpxTab: ()=>AtomicIpxTab
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const store_cjs_namespaceObject = require("../../common/interface/store.cjs");
const tab_common_cjs_namespaceObject = require("../../common/tabs/tab-common.cjs");
const bind_state_cjs_namespaceObject = require("../../../decorators/bind-state.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
class AtomicIpxTab extends external_lit_namespaceObject.LitElement {
    connectedCallback() {
        super.connectedCallback();
        this.addEventListener('click', this.handleClick);
        this.addEventListener('keydown', this.handleKeydown);
        this.updateHostAttributes();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('click', this.handleClick);
        this.removeEventListener('keydown', this.handleKeydown);
    }
    initialize() {
        this.tab = (0, headless_namespaceObject.buildTab)(this.bindings.engine, {
            options: {
                expression: this.expression,
                id: this.label
            },
            initialState: {
                isActive: this.active
            }
        });
        (0, store_cjs_namespaceObject.createAppLoadedListener)(this.bindings.store, (isAppLoaded)=>{
            this.isAppLoaded = isAppLoaded;
        });
    }
    select() {
        this.tab?.select();
    }
    updated() {
        if (this.tabState) {
            this.active = this.tabState.isActive;
            this.updateHostAttributes();
        }
        (0, tab_common_cjs_namespaceObject.dispatchTabLoaded)(this);
    }
    updateHostAttributes() {
        this.setAttribute('role', 'tab');
        this.setAttribute('aria-selected', this.active ? 'true' : 'false');
        this.tabIndex = this.active ? 0 : -1;
    }
    render() {
        return (0, external_lit_namespaceObject.html)`<span part="tab" title=${this.label}
      >${(0, when_js_namespaceObject.when)(this.isAppLoaded, ()=>this.label)}</span
    >`;
    }
    constructor(...args){
        super(...args), this.label = 'no-label', this.active = false, this.isAppLoaded = false, this.handleClick = ()=>{
            this.tab?.select();
        }, this.handleKeydown = (event)=>{
            if ('Enter' === event.key || ' ' === event.key) {
                event.preventDefault();
                this.tab?.select();
                return;
            }
            const tablist = this.closest('[role="tablist"]');
            if (!tablist) return;
            const tabs = Array.from(tablist.querySelectorAll('[role="tab"]'));
            const currentIndex = tabs.indexOf(this);
            if (-1 === currentIndex) return;
            let nextIndex = null;
            if ('ArrowRight' === event.key) nextIndex = (currentIndex + 1) % tabs.length;
            else if ('ArrowLeft' === event.key) nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
            else if ('Home' === event.key) nextIndex = 0;
            else if ('End' === event.key) nextIndex = tabs.length - 1;
            if (null !== nextIndex) {
                event.preventDefault();
                tabs.forEach((tab, index)=>{
                    tab.tabIndex = index === nextIndex ? 0 : -1;
                });
                tabs[nextIndex].focus();
            }
        };
    }
}
AtomicIpxTab.styles = (0, external_lit_namespaceObject.css)`
    @reference '../../../utils/tailwind.global.tw.css';

    :host {
      display: flex;
      @apply cursor-pointer;
      @apply focus-visible:outline-none;
    }

    [part='tab'] {
      @apply relative mt-1 mr-6 pb-3 font-semibold;
      @apply text-on-background;
      max-width: 150px;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    :host(:hover) [part='tab'],
    :host(:focus-visible) [part='tab'] {
      @apply text-primary;
    }

    :host([active]) [part='tab']::after {
      @apply bg-primary absolute bottom-0 block h-1 w-full rounded;
      content: '';
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true
    })
], AtomicIpxTab.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        attribute: 'active'
    })
], AtomicIpxTab.prototype, "active", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicIpxTab.prototype, "expression", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicIpxTab.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicIpxTab.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('tab'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof TabState ? Object : TabState)
], AtomicIpxTab.prototype, "tabState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicIpxTab.prototype, "isAppLoaded", void 0);
AtomicIpxTab = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-ipx-tab'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicIpxTab);
exports.AtomicIpxTab = __webpack_exports__.AtomicIpxTab;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicIpxTab"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
