import { n as e, r as t } from "./clients-IxWZVjVW.js";
import { n } from "./components-DaDed2hn.js";
import { t as r } from "./vue-i18n-Db_oYfO8.js";
import { createBlock as i, createTextVNode as a, createVNode as o, defineComponent as s, inject as c, mergeProps as l, onMounted as u, openBlock as d, ref as f, resolveComponent as p, toDisplayString as m, unref as h, withCtx as g } from "vue";
//#endregion
//#region src/components/on-demand/wt-send-message-popup/wt-send-message-popup.vue
var _ = /* @__PURE__ */ s({
	__name: "wt-send-message-popup",
	props: {
		chatItem: {},
		userId: {}
	},
	emits: ["close"],
	setup(s, { emit: _ }) {
		let v = s, y = _, b = c("$eventBus"), { t: x } = r(), S = f({
			gateway: v.chatItem?.app || {},
			provider: v.chatItem?.protocol || "",
			message: "",
			agentId: null
		});
		async function C(e) {
			let { items: n } = await t.getList({
				...e,
				userId: v.userId
			});
			S.value.agentId = n[0]?.id;
		}
		let w = async () => {
			let t = await e.patch({
				peers: [{
					via: S.value.gateway.id,
					id: v.chatItem?.externalId,
					type: S.value.provider
				}],
				variables: { agentId: S.value.agentId },
				message: { text: S.value.message }
			});
			t.failure && b.$emit("notification", {
				type: "error",
				text: t.failure[0].error.message
			}), y("close");
		}, T = (e) => {
			S.value.message += e, document.querySelector("textarea").focus();
		};
		return u(async () => await C()), (e, t) => {
			let r = p("wt-textarea"), s = p("wt-button"), c = p("wt-popup");
			return d(), i(c, l(e.$attrs, {
				class: "wt-send-message-popup",
				overflow: "",
				onClose: t[1] ||= (e) => y("close")
			}), {
				header: g(() => [a(m(h(x)("reusable.sendMessage")), 1)]),
				main: g(() => [o(r, {
					"model-value": S.value.message,
					"onUpdate:modelValue": t[0] ||= (e) => S.value.message = e,
					placeholder: h(x)("objects.chat.draftPlaceholder"),
					onEnter: w
				}, null, 8, ["model-value", "placeholder"])]),
				actions: g(() => [o(h(n), {
					filled: "",
					rounded: !1,
					class: "wt-send-message-popup__emoji",
					onInsertEmoji: T
				}), o(s, {
					icon: "chat-send",
					color: "secondary",
					disabled: !S.value.message,
					wide: "",
					onClick: w
				}, null, 8, ["disabled"])]),
				_: 1
			}, 16);
		};
	}
});
//#endregion
export { _ as default };
