"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__, {
    AtomicSegmentedFacetScrollable: ()=>AtomicSegmentedFacetScrollable
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const button_cjs_namespaceObject = require("../../common/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 arrow_left_rounded_cjs_namespaceObject = require("../../../images/arrow-left-rounded.cjs");
var arrow_left_rounded_cjs_default = /*#__PURE__*/ __webpack_require__.n(arrow_left_rounded_cjs_namespaceObject);
const arrow_right_rounded_cjs_namespaceObject = require("../../../images/arrow-right-rounded.cjs");
var arrow_right_rounded_cjs_default = /*#__PURE__*/ __webpack_require__.n(arrow_right_rounded_cjs_namespaceObject);
require("../../common/atomic-icon/atomic-icon.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 AtomicSegmentedFacetScrollable extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.searchStatus = (0, headless_namespaceObject.buildSearchStatus)(this.bindings.engine);
    }
    connectedCallback() {
        super.connectedCallback();
        this.addEventListener('wheel', this.handleScroll);
        this.addEventListener('touchmove', this.handleScroll);
        this.addEventListener('keydown', this.handleScroll);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.observer?.disconnect();
        this.removeEventListener('wheel', this.handleScroll);
        this.removeEventListener('touchmove', this.handleScroll);
        this.removeEventListener('keydown', this.handleScroll);
    }
    firstUpdated() {
        this.observer = new ResizeObserver(()=>{
            this.handleScroll();
        });
        Array.from(this.children).forEach((el)=>this.observer.observe(el));
        if (this.horizontalScrollRef.value) this.observer.observe(this.horizontalScrollRef.value);
    }
    render() {
        if (this.searchStatusState.hasError) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <div part="scrollable-container" class="relative flex">
        ${this.renderArrow('left')}
        <div
          part="horizontal-scroll"
          class="wrapper-segmented flex flex-row overflow-x-scroll scroll-smooth"
          ${(0, ref_js_namespaceObject.ref)(this.horizontalScrollRef)}
        >
          <slot></slot>
        </div>
        ${this.renderArrow('right')}
      </div>
    `;
    }
    slideHorizontally(direction) {
        const container = this.horizontalScrollRef.value;
        const arrowsWidth = 2 * this.arrowRef.value.clientWidth;
        const pixelsToScroll = (container.clientWidth - arrowsWidth) * 0.7;
        const isLeftEdge = Math.floor(container.scrollLeft - pixelsToScroll) <= 0;
        const isRightEdge = Math.ceil(container.scrollLeft + pixelsToScroll) >= container.scrollWidth - container.clientWidth;
        this.hideLeftArrow = false;
        this.hideRightArrow = false;
        if ('left' === direction) {
            container.scrollLeft -= pixelsToScroll;
            this.hideLeftArrow = isLeftEdge;
            return;
        }
        container.scrollLeft += pixelsToScroll;
        this.hideRightArrow = isRightEdge;
    }
    renderArrow(direction) {
        const hide = 'left' === direction && this.hideLeftArrow || 'right' === direction && this.hideRightArrow;
        const hiddenClass = hide ? 'invisible opacity-0' : '';
        const transitionClass = 'transition-opacity transition-[visibility] ease-in-out duration-300';
        return (0, external_lit_namespaceObject.html)`
      <div
        part="${direction}-arrow-wrapper"
        class="${hiddenClass} ${transitionClass}"
      >
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                style: 'square-neutral',
                part: `${direction}-arrow-button`,
                class: `absolute top-0 bottom-0 z-1 flex h-10 w-10 shrink-0 basis-8 items-center justify-center rounded ${'left' === direction ? 'left-0' : 'right-0'}`,
                ariaHidden: 'true',
                tabIndex: -1,
                onClick: ()=>this.slideHorizontally(direction),
                ref: this.arrowRef
            }
        })((0, external_lit_namespaceObject.html)`
          <atomic-icon
            part="${direction}-arrow-icon"
            class="w-3.5"
            .icon=${'left' === direction ? arrow_left_rounded_cjs_default() : arrow_right_rounded_cjs_default()}
          ></atomic-icon>
        `)}
        <div
          part="${direction}-fade"
          class="from-background/60 pointer-events-none absolute top-0 z-0 h-10 w-20 ${'left' === direction ? 'left-0 bg-linear-to-r' : 'right-0 bg-linear-to-l'}"
        ></div>
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.hideLeftArrow = true, this.hideRightArrow = true, this.horizontalScrollRef = (0, ref_js_namespaceObject.createRef)(), this.arrowRef = (0, ref_js_namespaceObject.createRef)(), this.handleScroll = ()=>{
            if (!this.horizontalScrollRef.value) return;
            const container = this.horizontalScrollRef.value;
            const isScrollable = container.clientWidth < container.scrollWidth;
            const isLeftEdge = Math.floor(container.scrollLeft) <= 0;
            const isRightEdge = Math.ceil(container.scrollLeft) >= container.scrollWidth - container.clientWidth;
            this.hideLeftArrow = !isScrollable || isLeftEdge;
            this.hideRightArrow = !isScrollable || isRightEdge;
        };
    }
}
AtomicSegmentedFacetScrollable.styles = (0, external_lit_namespaceObject.css)`
    .wrapper-segmented {
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    .wrapper-segmented::-webkit-scrollbar {
      display: none;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicSegmentedFacetScrollable.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicSegmentedFacetScrollable.prototype, "error", 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)
], AtomicSegmentedFacetScrollable.prototype, "searchStatusState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicSegmentedFacetScrollable.prototype, "hideLeftArrow", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicSegmentedFacetScrollable.prototype, "hideRightArrow", 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)
], AtomicSegmentedFacetScrollable.prototype, "render", null);
AtomicSegmentedFacetScrollable = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-segmented-facet-scrollable'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicSegmentedFacetScrollable);
exports.AtomicSegmentedFacetScrollable = __webpack_exports__.AtomicSegmentedFacetScrollable;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicSegmentedFacetScrollable"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
