"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__, {
    AtomicIpxRefineToggle: ()=>AtomicIpxRefineToggle
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const icon_button_cjs_namespaceObject = require("../../common/icon-button.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 filter_cjs_namespaceObject = require("../../../images/filter.cjs");
var filter_cjs_default = /*#__PURE__*/ __webpack_require__.n(filter_cjs_namespaceObject);
require("../atomic-ipx-refine-modal/atomic-ipx-refine-modal.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 AtomicIpxRefineToggle extends external_lit_namespaceObject.LitElement {
    get numberOfBreadcrumbs() {
        const state = this.breadcrumbManagerState;
        return state.facetBreadcrumbs.length + state.categoryFacetBreadcrumbs.length + state.numericFacetBreadcrumbs.length + state.dateFacetBreadcrumbs.length + state.staticFilterBreadcrumbs.length + state.automaticFacetBreadcrumbs.length;
    }
    initialize() {
        this.breadcrumbManager = (0, headless_namespaceObject.buildBreadcrumbManager)(this.bindings.engine);
        this.searchStatus = (0, headless_namespaceObject.buildSearchStatus)(this.bindings.engine);
    }
    loadModal() {
        if (this.modalLoaded) return;
        this.modalLoaded = true;
        this.modalRef = document.createElement('atomic-ipx-refine-modal');
        this.insertAdjacentElement('beforebegin', this.modalRef);
        this.modalRef.openButton = this.buttonRef;
        this.modalRef.collapseFacetsAfter = this.collapseFacetsAfter;
    }
    openModal() {
        if (this.modalRef) this.modalRef.isOpen = true;
    }
    handleClick() {
        this.bindings.store.waitUntilAppLoaded(()=>{
            this.openModal();
        });
    }
    render() {
        return (0, icon_button_cjs_namespaceObject.renderIconButton)({
            props: {
                partPrefix: 'ipx-refine-toggle',
                class: 'icon-button',
                style: 'outline-neutral',
                title: this.bindings.i18n.t('filters'),
                icon: filter_cjs_default(),
                disabled: !this.searchStatusState.hasResults && !this.numberOfBreadcrumbs,
                ariaLabel: this.bindings.i18n.t('filters'),
                onClick: ()=>this.handleClick(),
                buttonRef: (button)=>{
                    if (!button) return;
                    this.buttonRef = button;
                    this.loadModal();
                },
                badge: this.breadcrumbManagerState.hasBreadcrumbs ? (0, external_lit_namespaceObject.html)`<slot>${this.numberOfBreadcrumbs}</slot>` : void 0
            }
        });
    }
    constructor(...args){
        super(...args), this.collapseFacetsAfter = 0, this.modalLoaded = false;
    }
}
AtomicIpxRefineToggle.styles = (0, external_lit_namespaceObject.css)`
    @reference '../../../utils/tailwind.global.tw.css';

    :host {
      [part='ipx-refine-toggle-button'] {
        @apply h-full w-auto;
      }

      [part='ipx-refine-toggle-badge'] {
        @apply h-5 w-5 text-xs leading-5;
      }

      [part='ipx-refine-toggle-icon'] {
        @apply h-5 w-5;
      }
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'collapse-facets-after'
    })
], AtomicIpxRefineToggle.prototype, "collapseFacetsAfter", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicIpxRefineToggle.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicIpxRefineToggle.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('breadcrumbManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof BreadcrumbManagerState ? Object : BreadcrumbManagerState)
], AtomicIpxRefineToggle.prototype, "breadcrumbManagerState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('searchStatus'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof SearchStatusState ? Object : SearchStatusState)
], AtomicIpxRefineToggle.prototype, "searchStatusState", void 0);
_ts_decorate([
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicIpxRefineToggle.prototype, "render", null);
AtomicIpxRefineToggle = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-ipx-refine-toggle'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicIpxRefineToggle);
exports.AtomicIpxRefineToggle = __webpack_exports__.AtomicIpxRefineToggle;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicIpxRefineToggle"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
