"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__, {
    AtomicInsightUserActionsTimeline: ()=>AtomicInsightUserActionsTimeline
});
const bueno_namespaceObject = require("@coveo/bueno");
const insight_namespaceObject = require("@coveo/headless/insight");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const button_cjs_namespaceObject = require("../../common/button.cjs");
const container_cjs_namespaceObject = require("../../common/no-items/container.cjs");
const magnifying_glass_cjs_namespaceObject = require("../../common/no-items/magnifying-glass.cjs");
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.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 with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const big_arrow_down_cjs_namespaceObject = require("../../../images/big-arrow-down.cjs");
var big_arrow_down_cjs_default = /*#__PURE__*/ __webpack_require__.n(big_arrow_down_cjs_namespaceObject);
const big_arrow_up_cjs_namespaceObject = require("../../../images/big-arrow-up.cjs");
var big_arrow_up_cjs_default = /*#__PURE__*/ __webpack_require__.n(big_arrow_up_cjs_namespaceObject);
require("../../common/atomic-icon/atomic-icon.cjs");
require("../atomic-insight-user-actions-session/atomic-insight-user-actions-session.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 AtomicInsightUserActionsTimeline extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.userActions = (0, insight_namespaceObject.buildUserActions)(this.bindings.engine, {
            options: {
                ticketCreationDate: this.ticketCreationDateTime,
                excludedCustomActions: this.excludedCustomActions
            }
        });
        this.userActions.fetchUserActions(this.userId);
    }
    toggleFollowingSessions() {
        this.followingSessionsAreVisible = !this.followingSessionsAreVisible;
    }
    togglePrecedingSessions() {
        this.precedingSessionsAreVisible = !this.precedingSessionsAreVisible;
    }
    renderSessions(sessions, renderSeparator, testId) {
        if (!sessions) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <div>
        ${sessions.map(({ actions, start })=>(0, external_lit_namespaceObject.html)`
            <div class="mt-4">
              <atomic-insight-user-actions-session
                .startTimestamp=${start}
                .userActions=${actions}
                data-testid=${testId}
              ></atomic-insight-user-actions-session>
            </div>
            ${renderSeparator ? renderSeparator() : external_lit_namespaceObject.nothing}
          `)}
      </div>
    `;
    }
    renderToggleFollowingSessionsButton() {
        const btnClasses = 'flex items-center text-left p-2 text-sm max-w-full';
        const iconClasses = 'h-3 w-3 mr-1';
        const label = this.followingSessionsAreVisible ? this.bindings.i18n.t('hide-following-sessions') : this.bindings.i18n.t('show-following-sessions');
        const icon = this.followingSessionsAreVisible ? big_arrow_down_cjs_default() : big_arrow_up_cjs_default();
        return (0, external_lit_namespaceObject.html)`
      <div class="flex justify-center p-2">
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                style: 'text-primary',
                part: 'toggle-following-sessions',
                class: btnClasses,
                ariaLabel: label,
                onClick: this.toggleFollowingSessions.bind(this)
            }
        })((0, external_lit_namespaceObject.html)`
          <atomic-icon
            part="toggle-following-sessions-icon"
            class=${iconClasses}
            .icon=${icon}
          ></atomic-icon>
          <span class="truncate">${label}</span>
        `)}
      </div>
    `;
    }
    renderTogglePrecedingSessionsButton() {
        const btnClasses = 'flex items-center text-left p-2 text-sm max-w-full';
        const iconClasses = 'h-3 w-3 mr-1';
        const label = this.precedingSessionsAreVisible ? this.bindings.i18n.t('hide-preceding-sessions') : this.bindings.i18n.t('show-preceding-sessions');
        const icon = this.precedingSessionsAreVisible ? big_arrow_up_cjs_default() : big_arrow_down_cjs_default();
        return (0, external_lit_namespaceObject.html)`
      <div class="flex justify-center p-2">
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                style: 'text-primary',
                part: 'toggle-preceding-sessions',
                class: btnClasses,
                ariaLabel: label,
                onClick: this.togglePrecedingSessions.bind(this)
            }
        })((0, external_lit_namespaceObject.html)`
          <atomic-icon
            part="toggle-preceding-sessions-icon"
            class=${iconClasses}
            .icon=${icon}
          ></atomic-icon>
          <span class="truncate">${label}</span>
        `)}
      </div>
    `;
    }
    renderFollowingSessionsSection() {
        if (!this.userActionsState.timeline?.followingSessions?.length) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      ${this.renderToggleFollowingSessionsButton()}
      <div class="separator mx-1 rounded"></div>
      ${(0, when_js_namespaceObject.when)(this.followingSessionsAreVisible, ()=>this.renderSessions(this.userActionsState.timeline?.followingSessions, ()=>(0, external_lit_namespaceObject.html)`<div class="separator mx-1 mt-4 rounded"></div>`, 'following-session'))}
    `;
    }
    renderPrecedingSessionsSection() {
        if (!this.userActionsState.timeline?.precedingSessions?.length) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <div class="separator mx-1 mt-4 rounded"></div>
      ${(0, when_js_namespaceObject.when)(this.precedingSessionsAreVisible, ()=>this.renderSessions(this.userActionsState.timeline?.precedingSessions, ()=>(0, external_lit_namespaceObject.html)`<div class="separator mx-1 mt-4 rounded"></div>`, 'preceding-session'))}
      ${this.renderTogglePrecedingSessionsButton()}
    `;
    }
    renderTimeline() {
        const session = this.userActionsState.timeline?.session;
        if (!session) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <div>
        ${this.renderFollowingSessionsSection()}
        <div class="mt-4">
          <atomic-insight-user-actions-session
            .startTimestamp=${session.start}
            .userActions=${session.actions}
            data-testid="active-session"
          ></atomic-insight-user-actions-session>
        </div>
        ${this.renderPrecedingSessionsSection()}
      </div>
    `;
    }
    renderNoUserActionsScreen() {
        return (0, external_lit_namespaceObject.html)`
      <div class="my-6 py-3" data-testid="user-actions-error">
        ${(0, container_cjs_namespaceObject.renderNoItemsContainer)()((0, external_lit_namespaceObject.html)`
          ${(0, magnifying_glass_cjs_namespaceObject.renderMagnifyingGlass)()}
          <div class="my-2 max-w-full text-center text-2xl font-light">
            ${this.bindings.i18n.t('no-user-actions-available')}
          </div>
          <div class="text-neutral-dark my-2 text-center text-lg">
            ${this.bindings.i18n.t('no-user-actions-associated-with-params')}
          </div>
        `)}
      </div>
    `;
    }
    render() {
        const areUserActionsAvailable = this.userActionsState?.timeline?.session;
        const hasError = this.userActionsState?.error;
        if (areUserActionsAvailable && !hasError) return this.renderTimeline();
        return this.renderNoUserActionsScreen();
    }
    constructor(){
        super(), this.excludedCustomActions = [], this.followingSessionsAreVisible = false, this.precedingSessionsAreVisible = false;
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                userId: this.userId,
                ticketCreationDateTime: this.ticketCreationDateTime,
                excludedCustomActions: this.excludedCustomActions
            }), AtomicInsightUserActionsTimeline.propsSchema, false);
    }
}
AtomicInsightUserActionsTimeline.styles = (0, external_lit_namespaceObject.css)`
    @reference '../../../utils/tailwind.global.tw.css';

    .separator {
      height: 1px;
      background-color: var(
        --atomic-insight-user-actions-timeline-separator-background
      );
    }
  `;
AtomicInsightUserActionsTimeline.propsSchema = new bueno_namespaceObject.Schema({
    userId: new bueno_namespaceObject.StringValue({
        required: true,
        emptyAllowed: false
    }),
    ticketCreationDateTime: new bueno_namespaceObject.StringValue({
        required: true,
        emptyAllowed: false
    }),
    excludedCustomActions: new bueno_namespaceObject.ArrayValue({
        each: new bueno_namespaceObject.StringValue({}),
        required: false
    })
});
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightUserActionsTimeline.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightUserActionsTimeline.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('userActions'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightUserActionsState ? Object : InsightUserActionsState)
], AtomicInsightUserActionsTimeline.prototype, "userActionsState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'user-id'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsTimeline.prototype, "userId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'ticket-creation-date-time'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsTimeline.prototype, "ticketCreationDateTime", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'excluded-custom-actions'
    }),
    _ts_metadata("design:type", Array)
], AtomicInsightUserActionsTimeline.prototype, "excludedCustomActions", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicInsightUserActionsTimeline.prototype, "followingSessionsAreVisible", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicInsightUserActionsTimeline.prototype, "precedingSessionsAreVisible", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightUserActionsTimeline.prototype, "render", null);
AtomicInsightUserActionsTimeline = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-user-actions-timeline'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightUserActionsTimeline);
exports.AtomicInsightUserActionsTimeline = __webpack_exports__.AtomicInsightUserActionsTimeline;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicInsightUserActionsTimeline"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
