import { buildAttachToCase } from "@coveo/headless/insight";
import { LitElement, html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { ItemContextController } from "../../common/item-list/context/item-context-controller.js";
import { bindStateToController } from "../../../decorators/bind-state.js";
import { bindingGuard } from "../../../decorators/binding-guard.js";
import { bindings } from "../../../decorators/bindings.js";
import { errorGuard } from "../../../decorators/error-guard.js";
import { withTailwindStyles } from "../../../decorators/with-tailwind-styles.js";
import attach from "../../../images/attach.js";
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 AtomicInsightResultAttachToCaseIndicator extends LitElement {
    initialize() {
        const result = this.itemContextController.item;
        if (!result) return;
        const caseId = this.bindings.engine.state.insightCaseContext?.caseId || '';
        this.attachToCase = buildAttachToCase(this.bindings.engine, {
            options: {
                result,
                caseId
            }
        });
    }
    render() {
        if (!this.attachToCase?.isAttached()) return nothing;
        return html`
      <atomic-icon
        part="icon"
        class="flex w-5 justify-center"
        .icon=${attach}
        title=${this.bindings.i18n.t('result-is-attached')}
      ></atomic-icon>
    `;
    }
    constructor(){
        super();
        this.itemContextController = new ItemContextController(this, {
            parentName: 'atomic-insight-result'
        });
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightResultAttachToCaseIndicator.prototype, "bindings", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightResultAttachToCaseIndicator.prototype, "error", void 0);
_ts_decorate([
    bindStateToController('attachToCase'),
    state(),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicInsightResultAttachToCaseIndicator.prototype, "attachToCaseState", void 0);
_ts_decorate([
    errorGuard(),
    bindingGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightResultAttachToCaseIndicator.prototype, "render", null);
AtomicInsightResultAttachToCaseIndicator = _ts_decorate([
    customElement('atomic-insight-result-attach-to-case-indicator'),
    bindings(),
    withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightResultAttachToCaseIndicator);
export { AtomicInsightResultAttachToCaseIndicator };
