"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__, {
    AtomicQuickviewModal: ()=>AtomicQuickviewModal
});
require("../../common/atomic-modal/atomic-modal.cjs");
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const export_parts_cjs_namespaceObject = require("../../common/atomic-modal/export-parts.cjs");
const button_cjs_namespaceObject = require("../../common/button.cjs");
const icon_button_cjs_namespaceObject = require("../../common/icon-button.cjs");
const item_link_cjs_namespaceObject = require("../../common/item-link/item-link.cjs");
const atomic_quickview_sidebar_cjs_namespaceObject = require("../result-template-components/atomic-quickview-sidebar/atomic-quickview-sidebar.cjs");
const quickview_iframe_cjs_namespaceObject = require("../result-template-components/quickview-iframe/quickview-iframe.cjs");
const quickview_preview_bar_cjs_namespaceObject = require("../result-template-components/quickview-preview-bar/quickview-preview-bar.cjs");
const quickview_word_highlight_cjs_namespaceObject = require("../result-template-components/quickview-word-highlight/quickview-word-highlight.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 event_utils_cjs_namespaceObject = require("../../../utils/event-utils.cjs");
const close_cjs_namespaceObject = require("../../../images/close.cjs");
var close_cjs_default = /*#__PURE__*/ __webpack_require__.n(close_cjs_namespaceObject);
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 AtomicQuickviewModal extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.minimizeSidebar = this.bindings.store.isMobile();
    }
    async reset() {
        this.highlightKeywords = {
            highlightNone: false,
            keywords: {}
        };
        this.minimizeSidebar = false;
        this.iframeRef = void 0;
        this.content = void 0;
        this.result = void 0;
        this.interactiveResult = void 0;
        this.highlightStyleSheets.clear();
    }
    willUpdate(changedProperties) {
        if (changedProperties.has('highlightKeywords')) this.handleHighlightsScripts();
    }
    renderHeader() {
        if (!this.result) return (0, external_lit_namespaceObject.html)`<div slot="header"></div>`;
        this.interactiveResult = (0, headless_namespaceObject.buildInteractiveResult)(this.bindings.engine, {
            options: {
                result: this.result
            }
        });
        return (0, external_lit_namespaceObject.html)`
      <div slot="header" class="flex w-full items-center justify-between">
        ${(0, item_link_cjs_namespaceObject.renderLinkWithItemAnalytics)({
            props: {
                href: this.result.clickUri,
                onSelect: ()=>this.interactiveResult?.select(),
                onBeginDelayedSelect: ()=>this.interactiveResult?.beginDelayedSelect(),
                onCancelPendingSelect: ()=>this.interactiveResult?.cancelPendingSelect(),
                className: 'truncate',
                part: 'quickview-modal-header-title'
            }
        })((0, external_lit_namespaceObject.html)`${this.result.title}`)}
        ${(0, icon_button_cjs_namespaceObject.renderIconButton)({
            props: {
                partPrefix: 'quickview-modal-header',
                icon: close_cjs_default(),
                onClick: ()=>this.onClose(),
                ariaLabel: this.bindings.i18n.t('close'),
                style: 'text-transparent',
                title: this.bindings.i18n.t('close')
            }
        })}
      </div>
    `;
    }
    renderBody() {
        return (0, external_lit_namespaceObject.html)`
      <div slot="body" class="grid h-full grid-cols-[min-content_auto]">
        <div
          class="h-full overflow-y-auto"
          style="background-color: var(--atomic-neutral-light)"
        >
          ${(0, atomic_quickview_sidebar_cjs_namespaceObject.renderQuickviewSidebar)({
            props: {
                words: this.words,
                i18n: this.bindings.i18n,
                highlightKeywords: this.highlightKeywords,
                onHighlightKeywords: (highlight)=>{
                    this.highlightKeywords = highlight;
                },
                minimized: this.minimizeSidebar,
                onMinimize: (minimize)=>{
                    this.minimizeSidebar = minimize;
                }
            }
        })}
        </div>
        <div class="relative overflow-auto">
          ${(0, quickview_iframe_cjs_namespaceObject.renderQuickviewIframe)({
            props: {
                title: this.result?.title ?? this.bindings.i18n.t('preview-modal-title'),
                logger: this.logger,
                src: this.quickviewSrc,
                sandbox: this.sandbox,
                uniqueIdentifier: this.quickviewUniqueIdentifier,
                content: this.content,
                onSetIframeRef: async (ref)=>{
                    this.iframeRef = ref;
                    this.words = (0, quickview_word_highlight_cjs_namespaceObject.getWordsHighlights)(this.termsToHighlight, this.iframeRef);
                    this.handleHighlightsScripts();
                }
            }
        })}
          ${(0, quickview_preview_bar_cjs_namespaceObject.buildQuickviewPreviewBar)(this.words, this.highlightKeywords, this.iframeRef)}
        </div>
      </div>
    `;
    }
    renderFooter() {
        return (0, external_lit_namespaceObject.html)`
      <div slot="footer" class="flex items-center gap-2">
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                class: 'p-2',
                style: 'square-neutral',
                onClick: ()=>{
                    this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('atomic/quickview/previous'));
                },
                disabled: 1 === this.current,
                text: this.bindings.i18n.t('quickview-previous')
            }
        })(external_lit_namespaceObject.nothing)}
        <p class="text-center text-on-background">
          ${this.bindings.i18n.t('showing-results-of', {
            first: this.current,
            total: this.total
        })}
        </p>
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                class: 'p-2',
                style: 'square-neutral',
                onClick: ()=>{
                    this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('atomic/quickview/next'));
                },
                disabled: this.current === this.total,
                text: this.bindings.i18n.t('quickview-next')
            }
        })(external_lit_namespaceObject.nothing)}
      </div>
    `;
    }
    onClose() {
        this.content = void 0;
        this.result = void 0;
        this.modalCloseCallback?.();
    }
    get isOpen() {
        return !!this.content && !!this.result;
    }
    get logger() {
        return this.bindings.engine.logger;
    }
    get quickviewSrc() {
        return this.bindings.engine.state.resultPreview?.contentURL;
    }
    enableHighlights() {
        this.removeDisableHighlightStyleSheet();
    }
    enableHighlightsSpecificKeyword(identifier) {
        this.removeDisableHighlightStyleSheet(identifier);
    }
    disableHighlights() {
        this.createDisableHighlightStyleSheet();
    }
    disableHighlightsSpecificKeyword(identifier) {
        this.createDisableHighlightStyleSheet(identifier);
    }
    removeDisableHighlightStyleSheet(identifier) {
        const doc = this.iframeRef?.contentWindow?.document;
        if (!doc) return;
        const key = identifier ?? '';
        const sheet = this.highlightStyleSheets.get(key);
        if (!sheet) return;
        doc.adoptedStyleSheets = doc.adoptedStyleSheets.filter((s)=>s !== sheet);
        this.highlightStyleSheets.delete(key);
    }
    createDisableHighlightStyleSheet(identifier) {
        const doc = this.iframeRef?.contentWindow?.document;
        if (!doc) return;
        const key = identifier ?? '';
        if (this.highlightStyleSheets.has(key)) return;
        const sheet = new CSSStyleSheet();
        sheet.replaceSync(`[id^="${quickview_word_highlight_cjs_namespaceObject.HIGHLIGHT_PREFIX}${identifier ? `:${identifier}` : ''}"] {
        background-color: inherit !important;
        color: inherit !important;
      }`);
        this.highlightStyleSheets.set(key, sheet);
        doc.adoptedStyleSheets = [
            ...doc.adoptedStyleSheets,
            sheet
        ];
    }
    get termsToHighlight() {
        const flatPhrasesToHighlight = {};
        const phrasesToHighlight = this.bindings.engine.state.search.response.phrasesToHighlight;
        Object.entries(phrasesToHighlight).forEach(([phrase, keywords])=>{
            flatPhrasesToHighlight[phrase] = Object.entries(keywords).flatMap(([keywordEntry, keywordStemming])=>[
                    keywordEntry,
                    ...keywordStemming
                ]);
        });
        return {
            ...this.bindings.engine.state.search.response.termsToHighlight,
            ...flatPhrasesToHighlight
        };
    }
    get requestId() {
        return this.bindings.engine.state.search.requestId;
    }
    get quickviewUniqueIdentifier() {
        if (!this.result?.uniqueId) return this.requestId;
        return this.result.uniqueId + this.requestId;
    }
    handleHighlightsScripts() {
        if (this.highlightKeywords.highlightNone) this.disableHighlights();
        else this.enableHighlights();
        Object.values(this.highlightKeywords.keywords).forEach((word)=>{
            if (word.enabled) this.enableHighlightsSpecificKeyword(word.indexIdentifier);
            else this.disableHighlightsSpecificKeyword(word.indexIdentifier);
        });
    }
    render() {
        return (0, external_lit_namespaceObject.html)`
      <atomic-modal
        .fullscreen=${this.bindings.store.isMobile()}
        class="atomic-quickview-modal"
        .isOpen=${this.isOpen}
        .close=${()=>this.onClose()}
        exportparts=${export_parts_cjs_namespaceObject.ATOMIC_MODAL_EXPORT_PARTS}
      >
        ${this.renderHeader()} ${this.renderBody()} ${this.renderFooter()}
      </atomic-modal>
    `;
    }
    constructor(...args){
        super(...args), this.highlightKeywords = {
            highlightNone: false,
            keywords: {}
        }, this.minimizeSidebar = false, this.words = {}, this.highlightStyleSheets = new Map();
    }
}
AtomicQuickviewModal.styles = (0, external_lit_namespaceObject.css)`
    @reference '../../../utils/tailwind.global.tw.css';
    @reference '../../../utils/tailwind-utilities/link-style.css';

    .atomic-quickview-modal {
      &::part(backdrop) {
        grid-template-columns: 1fr max(80vw, 30rem) 1fr;
      }
      &::part(body),
      &::part(header),
      &::part(footer) {
        @apply max-w-full;
      }

      &::part(footer) {
        @apply flex justify-center;
      }

      &::part(body-wrapper) {
        @apply h-full overflow-hidden p-0;
      }

      &::part(body) {
        @apply h-full;
      }

      &::part(backdrop) {
        grid-template-rows: 1fr 100% 3fr;
      }

      &::part(header-wrapper) {
        @apply bg-neutral-light;
      }

      a {
        @apply link-style;
      }
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicQuickviewModal.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicQuickviewModal.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof HighlightKeywords ? Object : HighlightKeywords)
], AtomicQuickviewModal.prototype, "highlightKeywords", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicQuickviewModal.prototype, "minimizeSidebar", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicQuickviewModal.prototype, "words", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: false
    }),
    _ts_metadata("design:type", String)
], AtomicQuickviewModal.prototype, "content", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof Result ? Object : Result)
], AtomicQuickviewModal.prototype, "result", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number
    }),
    _ts_metadata("design:type", Number)
], AtomicQuickviewModal.prototype, "current", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number
    }),
    _ts_metadata("design:type", Number)
], AtomicQuickviewModal.prototype, "total", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicQuickviewModal.prototype, "sandbox", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: false
    }),
    _ts_metadata("design:type", Function)
], AtomicQuickviewModal.prototype, "modalCloseCallback", 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)
], AtomicQuickviewModal.prototype, "render", null);
AtomicQuickviewModal = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-quickview-modal'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicQuickviewModal);
exports.AtomicQuickviewModal = __webpack_exports__.AtomicQuickviewModal;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicQuickviewModal"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
