"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    AtomicTabManager: ()=>AtomicTabManager
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
require("../../common/atomic-tab-button/atomic-tab-button.cjs");
const boolean_converter_cjs_namespaceObject = require("../../../converters/boolean-converter.cjs");
const bind_state_cjs_namespaceObject = require("../../../decorators/bind-state.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const external_atomic_tab_manager_tw_css_cjs_namespaceObject = require("./atomic-tab-manager.tw.css.cjs");
var external_atomic_tab_manager_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_tab_manager_tw_css_cjs_namespaceObject);
require("../../common/atomic-tab-bar/atomic-tab-bar.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 AtomicTabManager extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.tabManager = (0, headless_namespaceObject.buildTabManager)(this.bindings.engine);
        const tabElements = Array.from(this.querySelectorAll('atomic-tab'));
        if (0 === tabElements.length) {
            this.error = new Error('The "atomic-tab-manager" element requires at least one "atomic-tab" child.');
            return;
        }
        tabElements.forEach((tabElement)=>{
            const name = tabElement.getAttribute('name') || '';
            const expression = tabElement.getAttribute('expression') ?? '';
            const label = tabElement.getAttribute('label') || '';
            if (!name) {
                this.error = new Error('The "name" attribute must be defined on all "atomic-tab" children.');
                return;
            }
            const tabController = (0, headless_namespaceObject.buildTab)(this.bindings.engine, {
                options: {
                    expression,
                    id: name,
                    clearFiltersOnTabChange: this.clearFiltersOnTabChange
                }
            });
            this.tabs.push({
                label,
                name,
                tabController
            });
        });
    }
    render() {
        return (0, external_lit_namespaceObject.html)`
      <atomic-tab-bar
        exportparts="popover-button, value-label, arrow-icon, backdrop, overflow-tabs, popover-tab"
      >
        <div
          role="tablist"
          aria-label="tab-area"
          part="tab-area"
          class="border-neutral mb-2 flex w-full flex-row border-b"
          @keydown=${this.handleTablistKeydown}
        >
          ${this.tabs.map((tab)=>{
            const isActive = this.tabManagerState.activeTab === tab.name;
            return (0, external_lit_namespaceObject.html)`<atomic-tab-button
              .label=${this.bindings.i18n.t(tab.label, {
                defaultValue: tab.label
            })}
              .active=${isActive}
              .select=${()=>{
                if (!tab.tabController.state.isActive) tab.tabController.select();
            }}
            ></atomic-tab-button>`;
        })}
        </div>
      </atomic-tab-bar>
    `;
    }
    handleTablistKeydown(event) {
        const tabs = Array.from(event.currentTarget.querySelectorAll('[role="tab"]'));
        const currentIndex = tabs.indexOf(event.target);
        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[nextIndex].focus();
        }
    }
    constructor(...args){
        super(...args), this.tabs = [], this.clearFiltersOnTabChange = false;
    }
}
AtomicTabManager.styles = external_atomic_tab_manager_tw_css_cjs_default();
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('tabManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof TabManagerState ? Object : TabManagerState)
], AtomicTabManager.prototype, "tabManagerState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicTabManager.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        attribute: 'clear-filters-on-tab-change'
    })
], AtomicTabManager.prototype, "clearFiltersOnTabChange", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicTabManager.prototype, "render", null);
AtomicTabManager = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-tab-manager'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicTabManager);
exports.AtomicTabManager = __webpack_exports__.AtomicTabManager;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicTabManager"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
