import Component from "@glimmer/component"; import { concat } from "@ember/helper"; import { getOwner } from "@ember/owner"; import { service } from "@ember/service"; import { modifier } from "ember-modifier"; import { and } from "truth-helpers"; import concatClass from "discourse/helpers/concat-class"; import icon from "discourse-common/helpers/d-icon"; import DFloatBody from "float-kit/components/d-float-body"; import { TOOLTIP } from "float-kit/lib/constants"; import DTooltipInstance from "float-kit/lib/d-tooltip-instance"; export default class DTooltip extends Component { @service tooltip; @service internalTooltip; tooltipInstance = new DTooltipInstance(getOwner(this), { ...this.allowedProperties, autoUpdate: true, listeners: true, }); registerTrigger = modifier((element) => { this.tooltipInstance.trigger = element; this.options.onRegisterApi?.(this.tooltipInstance); return () => { this.tooltipInstance.destroy(); }; }); get options() { return this.tooltipInstance?.options; } get componentArgs() { return { close: this.tooltip.close, data: this.options.data, }; } get allowedProperties() { const properties = {}; for (const [key, value] of Object.entries(TOOLTIP.options)) { properties[key] = this.args[key] ?? value; } return properties; } }