import { ref as D, computed as u, onMounted as H, nextTick as O, onUpdated as P, onBeforeUnmount as W, createElementBlock as l, openBlock as s, renderSlot as M, createBlock as f, createCommentVNode as n, createElementVNode as c, createVNode as Q, unref as e, toDisplayString as h, createTextVNode as j, Fragment as v, renderList as k, normalizeStyle as R, Transition as Y, withCtx as G } from "vue";
import _ from "../../2_chatlist_elements/ChatItem/ChatItem.vue.js";
import J from "../../2_chatlist_elements/ChatFilter/ChatFilter.vue.js";
import K from "../../2_chatlist_elements/ChatTabs/ChatTabs.vue.js";
import X from "../../1_atoms/LoadingIndicator/LoadingIndicator.vue.js";
import { useChatListScroll as Z } from "./composables/useChatListScroll.js";
import { useChatListSelection as tt } from "./composables/useChatListSelection.js";
import { useChatListFilter as et } from "./composables/useChatListFilter.js";
import { useChatListActions as at } from "./composables/useChatListActions.js";
/* empty css              */
import st from "../../../_virtual/_plugin-vue_export-helper.js";
const ot = { class: "chat-list" }, it = {
  key: 2,
  class: "chat-list__search-indicator"
}, lt = { class: "chat-list__search-content" }, nt = { class: "chat-list__search-text" }, rt = {
  key: 0,
  class: "chat-list__search-progress"
}, ct = {
  key: 1,
  class: "chat-list__search-query"
}, dt = {
  key: 0,
  class: "chat-list__search-stats"
}, ut = {
  key: 3,
  class: "chat-list__fixed-items-top"
}, ht = { class: "chat-list__placeholder" }, gt = { class: "chat-list__placeholder-title" }, ft = {
  key: 0,
  class: "chat-list__placeholder-hint"
}, mt = {
  key: 4,
  class: "chat-list__fixed-items-bottom"
}, yt = {
  __name: "ChatList",
  props: {
    chats: {
      type: Array,
      required: !0
    },
    filterEnabled: {
      type: Boolean,
      required: !0
    },
    filterQuery: {
      type: String,
      default: null
    },
    dialogTabs: {
      type: Array,
      default: () => []
    },
    activeTabId: {
      type: String,
      default: "all"
    },
    // Props для поиска
    searchQuery: {
      type: String,
      default: ""
    },
    isSearching: {
      type: Boolean,
      default: !1
    },
    searchProgress: {
      type: String,
      default: ""
    },
    searchStats: {
      type: Object,
      default: () => ({ loaded: 0, total: "?" })
    },
    showDialogs: {
      type: Boolean,
      default: !0
    },
    isLoading: {
      type: Boolean,
      default: !1
    },
    contextMenuTrigger: {
      type: String,
      default: "hover",
      validator: (a) => ["hover", "rightClick"].includes(a)
    },
    placeholderTitle: {
      type: String,
      default: "Нет контактных данных, чтобы начать чат"
    },
    placeholderHint: {
      type: String,
      default: "Добавьте номер телефона и Имя в карточку контакта"
    }
  },
  emits: ["select", "action", "loadMoreChats", "expand", "tab-click", "search", "clear-search"],
  setup(a, { emit: I }) {
    const i = a, g = I, y = D(), T = D(0), C = u(() => i.chats), m = () => {
      var r;
      T.value = ((r = y.value) == null ? void 0 : r.offsetTop) ?? 0;
    }, $ = u(() => ({
      transform: `translateY(${-(T.value / 2)}px)`
    })), b = u(() => {
      var r, o, t;
      return ((r = i.searchQuery) == null ? void 0 : r.trim()) || ((o = i.filterQuery) == null ? void 0 : o.trim()) || ((t = V.value) == null ? void 0 : t.trim()) || "";
    }), w = u(
      () => b.value.length > 0 && !i.isSearching
    ), N = u(() => w.value ? `Не нашли чат по запросу "${b.value}"` : i.placeholderTitle), L = u(() => w.value ? "" : i.placeholderHint), {
      isShowButton: U,
      scrollToTopForce: E,
      scrollCheck: B,
      startScrollWatch: F,
      stopScrollWatch: A
    } = Z({ refChatList: y, chats: C, emit: g }), {
      selectChat: p
    } = tt({ chats: C, emit: g }), {
      filter: V,
      getSortedAndFilteredChats: d,
      getFilter: q
    } = et({ props: i, emit: g }), {
      expandChat: S,
      action: x,
      handleTabClick: z
    } = at({ emit: g });
    return H(async () => {
      await O(), m(), window.addEventListener("resize", m);
    }), P(() => {
      m();
    }), W(() => {
      window.removeEventListener("resize", m);
    }), (r, o) => (s(), l("div", ot, [
      M(r.$slots, "header", {}, void 0, !0),
      M(r.$slots, "sidebar", {}, void 0, !0),
      a.filterEnabled ? (s(), f(J, {
        key: 0,
        class: "chat-list__filter",
        onUpdate: e(q)
      }, null, 8, ["onUpdate"])) : n("", !0),
      a.dialogTabs && a.dialogTabs.length > 0 ? (s(), f(K, {
        key: 1,
        tabs: a.dialogTabs,
        onTabClick: e(z)
      }, null, 8, ["tabs", "onTabClick"])) : n("", !0),
      a.isSearching || a.searchQuery ? (s(), l("div", it, [
        c("div", lt, [
          c("div", nt, [
            a.isSearching ? (s(), l("span", rt, h(a.searchProgress || "Поиск..."), 1)) : (s(), l("span", ct, [
              j(' Поиск "' + h(a.searchQuery) + '" завершён ', 1),
              a.searchStats.loaded > 0 ? (s(), l("span", dt, " (" + h(a.searchStats.loaded) + " " + h(a.searchStats.total !== "?" ? `из ${a.searchStats.total}` : "") + ") ", 1)) : n("", !0)
            ]))
          ]),
          a.searchQuery ? (s(), l("button", {
            key: 0,
            class: "chat-list__search-clear",
            title: "Очистить поиск",
            onClick: o[0] || (o[0] = (t) => g("clear-search"))
          }, [...o[5] || (o[5] = [
            c("i", { class: "pi pi-times" }, null, -1)
          ])])) : n("", !0)
        ])
      ])) : n("", !0),
      !i.isLoading && e(d)().filter((t) => t.isFixedTop).length > 0 ? (s(), l("div", ut, [
        (s(!0), l(v, null, k(e(d)().filter((t) => t.isFixedTop), (t) => (s(), f(_, {
          key: t.chatId,
          class: "chat-list__item",
          chat: t,
          "show-dialogs": a.showDialogs,
          "context-menu-trigger": i.contextMenuTrigger,
          onSelect: e(p),
          onExpand: e(S),
          onAction: e(x)
        }, null, 8, ["chat", "show-dialogs", "context-menu-trigger", "onSelect", "onExpand", "onAction"]))), 128))
      ])) : n("", !0),
      c("div", {
        ref_key: "refChatList",
        ref: y,
        class: "chat-list__items",
        onScroll: o[1] || (o[1] = (...t) => e(B) && e(B)(...t)),
        onMousedown: o[2] || (o[2] = (...t) => e(F) && e(F)(...t)),
        onMouseup: o[3] || (o[3] = (...t) => e(A) && e(A)(...t))
      }, [
        Q(X, {
          class: "chat-list__loading-indicator",
          "is-loading": i.isLoading
        }, null, 8, ["is-loading"]),
        !i.isLoading && e(d)().length === 0 ? (s(), l("div", {
          key: 0,
          class: "chat-list__no-data",
          style: R($.value)
        }, [
          c("div", ht, [
            c("p", gt, h(N.value), 1),
            L.value ? (s(), l("p", ft, h(L.value), 1)) : n("", !0)
          ])
        ], 4)) : (s(!0), l(v, { key: 1 }, k(e(d)().filter((t) => !t.isFixedBottom && !t.isFixedTop), (t) => (s(), f(_, {
          key: t.chatId,
          class: "chat-list__item",
          chat: t,
          "show-dialogs": a.showDialogs,
          "context-menu-trigger": i.contextMenuTrigger,
          onSelect: e(p),
          onExpand: e(S),
          onAction: e(x)
        }, null, 8, ["chat", "show-dialogs", "context-menu-trigger", "onSelect", "onExpand", "onAction"]))), 128))
      ], 544),
      !i.isLoading && e(d)().filter((t) => t.isFixedBottom).length > 0 ? (s(), l("div", mt, [
        (s(!0), l(v, null, k(e(d)().filter((t) => t.isFixedBottom), (t) => (s(), f(_, {
          key: t.chatId,
          class: "chat-list__item",
          chat: t,
          "show-dialogs": a.showDialogs,
          "context-menu-trigger": i.contextMenuTrigger,
          onSelect: e(p),
          onExpand: e(S),
          onAction: e(x)
        }, null, 8, ["chat", "show-dialogs", "context-menu-trigger", "onSelect", "onExpand", "onAction"]))), 128))
      ])) : n("", !0),
      Q(Y, null, {
        default: G(() => [
          e(U) ? (s(), l("button", {
            key: 0,
            class: "chat-list__button-up",
            onClick: o[4] || (o[4] = (...t) => e(E) && e(E)(...t))
          }, [...o[6] || (o[6] = [
            c("span", { class: "pi pi-angle-up chat-list__icon-down" }, null, -1)
          ])])) : n("", !0)
        ]),
        _: 1
      })
    ]));
  }
}, Et = /* @__PURE__ */ st(yt, [["__scopeId", "data-v-20eeef36"]]);
export {
  Et as default
};
