"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__, {
    Actions: ()=>atomic_insight_result_action_Actions,
    AtomicInsightResultAction: ()=>AtomicInsightResultAction
});
const insight_namespaceObject = require("@coveo/headless/insight");
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 item_context_controller_cjs_namespaceObject = require("../../common/item-list/context/item-context-controller.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 light_dom_cjs_namespaceObject = require("../../../mixins/light-dom.cjs");
const attach_cjs_namespaceObject = require("../../../images/attach.cjs");
var attach_cjs_default = /*#__PURE__*/ __webpack_require__.n(attach_cjs_namespaceObject);
const copy_dark_cjs_namespaceObject = require("../../../images/copy-dark.cjs");
var copy_dark_cjs_default = /*#__PURE__*/ __webpack_require__.n(copy_dark_cjs_namespaceObject);
const email_cjs_namespaceObject = require("../../../images/email.cjs");
var email_cjs_default = /*#__PURE__*/ __webpack_require__.n(email_cjs_namespaceObject);
const preview_cjs_namespaceObject = require("../../../images/preview.cjs");
var preview_cjs_default = /*#__PURE__*/ __webpack_require__.n(preview_cjs_namespaceObject);
const share_post_cjs_namespaceObject = require("../../../images/share-post.cjs");
var share_post_cjs_default = /*#__PURE__*/ __webpack_require__.n(share_post_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);
}
var atomic_insight_result_action_Actions = /*#__PURE__*/ function(Actions) {
    Actions["CopyToClipboard"] = "copyToClipboard";
    Actions["AttachToCase"] = "attachToCase";
    Actions["Quickview"] = "quickview";
    Actions["PostToFeed"] = "postToFeed";
    Actions["SendAsEmail"] = "sendAsEmail";
    return Actions;
}({});
class AtomicInsightResultAction extends (0, light_dom_cjs_namespaceObject.LightDomMixin)(external_lit_namespaceObject.LitElement) {
    disconnectedCallback() {
        super.disconnectedCallback();
        clearTimeout(this.tooltipResetTimeout);
    }
    get result() {
        return this.itemContextController.item;
    }
    initialize() {
        this.actions = (0, insight_namespaceObject.loadInsightAnalyticsActions)(this.bindings.engine);
        this.currentTooltip = this.tooltip;
    }
    onClick() {
        if (!this.result) return;
        if (this.tooltipOnClick) {
            const originalTooltip = this.tooltip;
            this.currentTooltip = this.tooltipOnClick;
            clearTimeout(this.tooltipResetTimeout);
            this.tooltipResetTimeout = setTimeout(()=>{
                this.currentTooltip = originalTooltip;
            }, 1000);
        }
        switch(this.action){
            case "copyToClipboard":
                this.bindings.engine.dispatch(this.actions.logCopyToClipboard(this.result));
                navigator.clipboard.writeText(this.result.clickUri);
                break;
            case "postToFeed":
                this.bindings.engine.dispatch(this.actions.logFeedItemTextPost(this.result));
                break;
            case "sendAsEmail":
                this.bindings.engine.dispatch(this.actions.logCaseSendEmail(this.result));
                break;
        }
        this.dispatchEvent(new CustomEvent('atomicInsightResultActionClicked', {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail: {
                action: this.action,
                result: this.result
            }
        }));
    }
    getIcon() {
        if (this.icon) return this.icon;
        switch(this.action){
            case "copyToClipboard":
                return copy_dark_cjs_default();
            case "attachToCase":
                return attach_cjs_default();
            case "quickview":
                return preview_cjs_default();
            case "postToFeed":
                return share_post_cjs_default();
            case "sendAsEmail":
                return email_cjs_default();
            default:
                return preview_cjs_default();
        }
    }
    render() {
        if (!this.result) return null;
        return (0, icon_button_cjs_namespaceObject.renderIconButton)({
            props: {
                partPrefix: 'result-action',
                style: 'outline-neutral',
                icon: this.getIcon(),
                title: this.currentTooltip,
                onClick: ()=>this.onClick()
            }
        });
    }
    constructor(){
        super(), this.icon = '', this.tooltip = '', this.tooltipOnClick = '', this.action = '', this.currentTooltip = '';
        this.itemContextController = new item_context_controller_cjs_namespaceObject.ItemContextController(this, {
            parentName: 'atomic-insight-result',
            folded: false
        });
    }
}
AtomicInsightResultAction.styles = (0, external_lit_namespaceObject.css)`
    @reference '../../../utils/tailwind.global.tw.css';

    [part='result-action-button'] {
      @apply flex items-center justify-center;
      @apply h-8 w-8;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    })
], AtomicInsightResultAction.prototype, "icon", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    })
], AtomicInsightResultAction.prototype, "tooltip", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'tooltip-on-click'
    })
], AtomicInsightResultAction.prototype, "tooltipOnClick", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", Object)
], AtomicInsightResultAction.prototype, "action", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightResultAction.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightResultAction.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicInsightResultAction.prototype, "currentTooltip", 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)
], AtomicInsightResultAction.prototype, "render", null);
AtomicInsightResultAction = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-result-action'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightResultAction);
exports.Actions = __webpack_exports__.Actions;
exports.AtomicInsightResultAction = __webpack_exports__.AtomicInsightResultAction;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "Actions",
    "AtomicInsightResultAction"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
