import { defineComponent as B, inject as E, ref as z, onMounted as I, resolveComponent as M, createBlock as O, openBlock as Q, mergeProps as R, withCtx as b, createVNode as k, unref as G, createTextVNode as V, toDisplayString as F } from "vue";
import { a as o, c as S, m, s as v, g as w, b as h, n as d, d as H, e as $ } from "./contacts-BuM4ADEC.js";
import "./index-CX-np8_F.js";
import "lodash-es";
import U from "@aliasedDeps/api-services/axios";
import { B as W, ao as J } from "./install-DJFUeaKV.js";
const _ = (
  // --- title end
  ((e = U) => ({
    searchAgent: (s, t) => e.get("/call_center/agents", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    }),
    createAgent: (s, t) => e.post(
      "/call_center/agents",
      s,
      t
    ),
    searchAgentCallStatistics: (s, t) => e.get("/call_center/agents/reports/call", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    }),
    searchAgentStatusStatistic: (s, t) => e.get("/call_center/agents/reports/status", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    }),
    searchAgentStatusStatisticItem: (s, t, c) => e.get(
      `/call_center/agents/reports/status/${s}`,
      {
        ...c,
        params: {
          ...t,
          ...c?.params
        }
      }
    ),
    searchAgentStateHistory: (s, t) => e.get("/call_center/agents/states/history", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    }),
    searchPauseCauseForAgent: (s, t, c) => e.get(
      `/call_center/agents/${s}/pause_causes`,
      {
        ...c,
        params: {
          ...t,
          ...c?.params
        }
      }
    ),
    agentStateHistory: (s, t, c) => e.get(
      `/call_center/agents/${s}/states/history`,
      {
        ...c,
        params: {
          ...t,
          ...c?.params
        }
      }
    ),
    agentSetState: (s, t, c) => e.patch(
      `/call_center/agents/${s}/states/waiting`,
      t,
      c
    ),
    searchAgentInQueueStatistics: (s, t, c) => e.get(
      `/call_center/agents/${s}/statistics/queues`,
      {
        ...c,
        params: {
          ...t,
          ...c?.params
        }
      }
    ),
    agentTodayStatistics: (s, t, c) => e.get(
      `/call_center/agents/${s}/statistics/today`,
      {
        ...c,
        params: {
          ...t,
          ...c?.params
        }
      }
    ),
    deleteAgent: (s, t, c) => e.delete(`/call_center/agents/${s}`, {
      ...c,
      params: {
        ...t,
        ...c?.params
      }
    }),
    readAgent: (s, t, c) => e.get(`/call_center/agents/${s}`, {
      ...c,
      params: {
        ...t,
        ...c?.params
      }
    }),
    patchAgent: (s, t, c) => e.patch(
      `/call_center/agents/${s}`,
      t,
      c
    ),
    updateAgent: (s, t, c) => e.put(
      `/call_center/agents/${s}`,
      t,
      c
    ),
    searchAgentInQueue: (s, t, c) => e.get(`/call_center/agents/${s}/queues`, {
      ...c,
      params: {
        ...t,
        ...c?.params
      }
    }),
    updateAgentStatus: (s, t, c) => e.patch(
      `/call_center/agents/${s}/status`,
      t,
      c
    ),
    searchAgentInTeam: (s, t, c) => e.get(`/call_center/agents/${s}/teams`, {
      ...c,
      params: {
        ...t,
        ...c?.params
      }
    }),
    searchLookupUsersAgentNotExists: (s, t) => e.get("/call_center/lookups/agents/users", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    }),
    searchUserStatus: (s, t) => e.get("/call_center/users", {
      ...t,
      params: {
        ...s,
        ...t?.params
      }
    })
  }))
), j = (
  // --- title end
  ((e = U) => ({
    messagesServiceBroadcastMessage: (g, u) => e.post(
      "/chat/broadcast",
      g,
      u
    ),
    catalogGetCustomers: (g, u) => e.get("/chat/customers", {
      ...u,
      params: {
        ...g,
        ...u?.params
      }
    }),
    catalogGetDialogs: (g, u) => e.get("/chat/dialogs", {
      ...u,
      params: {
        ...g,
        ...u?.params
      }
    }),
    catalogGetMembers: (g, u, p) => e.get(`/chat/dialogs/${g}/members`, {
      ...p,
      params: {
        ...u,
        ...p?.params
      }
    }),
    catalogGetHistory: (g, u, p) => e.get(`/chat/dialogs/${g}/messages`, {
      ...p,
      params: {
        ...u,
        ...p?.params
      }
    }),
    catalogGetHistory2: (g, u) => e.get("/chat/peer.type}/peer.id}/messages", {
      ...u,
      params: {
        ...g,
        ...u?.params
      }
    })
  }))
), K = (e) => {
  if (!e) return "00:00:00";
  let r = `${Math.floor(e / 3600)}`, a = `${Math.floor(e % 3600 / 60)}`, n = `${Math.floor(e % 3600 % 60)}`;
  return r.length === 1 && (r = `0${r}`), a.length === 1 && (a = `0${a}`), n.length === 1 && (n = `0${n}`), `${r}:${a}:${n}`;
}, X = (e) => e > 3600 * 24 ? ">24:00:00" : K(e), C = async (e) => {
  const r = (i) => i.map((l) => ({
    ...l,
    statusDuration: X(l.statusDuration)
  })), a = [
    "page",
    "size",
    "q",
    "sort",
    "fields",
    "id",
    "allow_channels",
    "team",
    "region_id",
    "auditor_id",
    "skill",
    "queue_id",
    "is_supervisor",
    "is_not_Supervisor",
    "user_id",
    "not_team_id",
    "supervisor_id",
    "not_skill_id",
    "not_user_id"
  ], n = o(e, [
    S(),
    m(w()),
    (i) => ({
      ...i,
      q: i.search
    }),
    v(a)
  ]);
  try {
    const i = await _().searchAgent(n), { items: l, next: y } = o(i.data, [
      h(),
      m(w())
    ]);
    return {
      items: o(l, [
        r
      ]),
      next: y
    };
  } catch (i) {
    throw o(i, [
      d
    ]);
  }
}, Y = async ({ itemId: e }) => {
  const r = {
    user: {},
    team: {},
    supervisor: [],
    auditor: [],
    region: {},
    progressiveCount: 0,
    chatCount: 0,
    taskCount: 0,
    isSupervisor: !1,
    description: "",
    greetingMedia: {}
  };
  try {
    const a = await _().readAgent(e);
    return o(a.data, [
      h(),
      m(r)
    ]);
  } catch (a) {
    throw o(a, [
      d
    ]);
  }
}, q = [
  "user",
  "team",
  "supervisor",
  "auditor",
  "region",
  "greetingMedia",
  "progressiveCount",
  "chatCount",
  "taskCount",
  "isSupervisor"
], Z = async ({ itemInstance: e }) => {
  const r = o(e, [
    v(q),
    S()
  ]);
  try {
    const a = await _().createAgent(r);
    return o(a.data, [
      h()
    ]);
  } catch (a) {
    throw o(a, [
      d
    ]);
  }
}, x = async ({ changes: e, id: r }) => {
  const a = o(e, [
    v(q),
    S()
  ]);
  try {
    const n = await _().patchAgent(r, a);
    return o(n.data, [
      h()
    ]);
  } catch (n) {
    throw o(n, [
      d
    ]);
  }
}, ee = async ({ itemInstance: e, itemId: r }) => {
  const a = o(e, [
    v(q),
    S()
  ]);
  try {
    const n = await _().updateAgent(r, a);
    return o(n.data, [
      h()
    ]);
  } catch (n) {
    throw o(n, [
      d
    ]);
  }
}, te = async ({ id: e }) => {
  try {
    const r = await _().deleteAgent(e);
    return o(r.data, []);
  } catch (r) {
    throw o(r, [
      d
    ]);
  }
}, se = (e) => C({
  ...e,
  fields: e.fields || [
    "id",
    "name"
  ]
}), ae = async (e) => {
  const {
    parentId: r,
    from: a,
    to: n,
    page: i,
    size: l,
    sort: y = "-joined_at"
  } = o(e, [
    m($()),
    H("search")
  ]);
  try {
    const g = await _().searchAgentStateHistory({
      page: i,
      size: l,
      from: a,
      to: n,
      parentId: r,
      sort: y
    }), { items: u, next: p } = o(g.data, [
      h(),
      m(w())
    ]);
    return {
      items: u,
      next: p
    };
  } catch (g) {
    throw o(g, [
      d
    ]);
  }
}, re = async (e) => {
  const { page: r, size: a, search: n, sort: i, fields: l, id: y } = o(e, [
    m($()),
    H("search")
  ]);
  try {
    const g = await _().searchLookupUsersAgentNotExists({
      page: r,
      size: a,
      q: n
    }), { items: u, next: p } = o(g.data, [
      h(),
      m(w())
    ]);
    return {
      items: u,
      next: p
    };
  } catch (g) {
    throw o(g, [
      d
    ]);
  }
}, ne = async (e) => {
  const r = [
    "page",
    "size",
    "q",
    "sort",
    "fields",
    "not_user_id"
  ], a = o(e, [
    S(),
    m($()),
    H("search"),
    (n) => ({
      ...n,
      q: n.search
    }),
    v(r)
  ]);
  try {
    const n = await _().searchUserStatus(a), { items: i, next: l } = o(n.data, [
      h(),
      m(w())
    ]);
    return {
      items: i,
      next: l
    };
  } catch (n) {
    throw o(n, [
      d
    ]);
  }
}, ce = async (e) => C({
  ...e,
  isSupervisor: !0
}), oe = async (e) => C({
  ...e,
  isNotSupervisor: !0
}), ge = {
  getList: C,
  get: Y,
  add: Z,
  patch: x,
  update: ee,
  delete: te,
  getLookup: se,
  getAgentHistory: ae,
  getRegularAgentsOptions: oe,
  getAgentUsersOptions: re,
  getSupervisorOptions: ce,
  getUsersStatus: ne
}, ue = async (e) => {
  const r = o(e, [
    S()
  ]);
  try {
    const a = await j().messagesServiceBroadcastMessage(r);
    return o(a.data, [
      h()
    ]);
  } catch (a) {
    throw o(a, [
      d
    ]);
  }
}, ie = async ({ chatId: e, ...r }) => {
  const a = o(r, [
    m($()),
    S()
  ]);
  try {
    const n = await j().catalogGetHistory(e, a), { messages: i, peers: l, next: y } = o(n.data, [
      h(),
      m(w())
    ]);
    return {
      messages: i,
      peers: l,
      next: y
    };
  } catch (n) {
    throw o(n, [
      d
    ]);
  }
}, le = {
  patch: ue,
  getChatHistory: ie
}, ve = /* @__PURE__ */ B({
  __name: "wt-send-message-popup",
  props: {
    chatItem: {},
    userId: {}
  },
  emits: [
    "close"
  ],
  setup(e, { emit: r }) {
    const a = e, n = r, i = E("$eventBus"), { t: l } = W(), g = z({
      gateway: a.chatItem?.app || {},
      provider: a.chatItem?.protocol || "",
      message: "",
      agentId: null
    });
    async function u(A) {
      const { items: f } = await ge.getList({
        ...A,
        userId: a.userId
      });
      g.value.agentId = f[0]?.id;
    }
    const p = async () => {
      const A = await le.patch({
        peers: [
          {
            via: g.value.gateway.id,
            id: a.chatItem?.externalId,
            type: g.value.provider
          }
        ],
        variables: {
          agentId: g.value.agentId
        },
        message: {
          text: g.value.message
        }
      });
      A.failure && i.$emit("notification", {
        type: "error",
        text: A.failure[0].error.message
      }), n("close");
    }, D = (A) => {
      g.value.message += A, document.querySelector("textarea").focus();
    };
    return I(async () => await u()), (A, f) => {
      const P = M("wt-textarea"), L = M("wt-button"), N = M("wt-popup");
      return Q(), O(N, R(A.$attrs, {
        class: "wt-send-message-popup",
        overflow: "",
        onClose: f[1] || (f[1] = (T) => n("close"))
      }), {
        header: b(() => [
          V(F(G(l)("reusable.sendMessage")), 1)
        ]),
        main: b(() => [
          k(P, {
            "model-value": g.value.message,
            "onUpdate:modelValue": f[0] || (f[0] = (T) => g.value.message = T),
            placeholder: G(l)("objects.chat.draftPlaceholder"),
            onEnter: p
          }, null, 8, ["model-value", "placeholder"])
        ]),
        actions: b(() => [
          k(G(J), {
            filled: "",
            rounded: !1,
            class: "wt-send-message-popup__emoji",
            onInsertEmoji: D
          }),
          k(L, {
            icon: "chat-send",
            color: "secondary",
            disabled: !g.value.message,
            wide: "",
            onClick: p
          }, null, 8, ["disabled"])
        ]),
        _: 1
      }, 16);
    };
  }
});
export {
  ve as default
};
