import { ref as u } from "vue";
function h({ props: e, emit: l }) {
  const r = u("");
  return {
    filter: r,
    getSortedAndFilteredChats: () => !e.chats || e.chats.length === 0 ? [] : e.chats.slice().filter((t) => {
      var n;
      const i = e.activeTabId || "all";
      if (i !== "all") {
        if (i === "countUnread") {
          if (t.countUnread <= 0) return !1;
        } else if (i.startsWith("tag_") && (!((n = t.contact) != null && n.tags) || !t.contact.tags.some((s) => s.tagId === i)))
          return !1;
      }
      return e.searchQuery && e.searchQuery.trim() !== "" ? !0 : e.filterQuery ? t.name.includes(e.filterQuery) || t.metadata.includes(e.filterQuery) : t.name.includes(r.value) || t.metadata.includes(r.value);
    }),
    getFilter: (a) => {
      r.value = a, a.trim() !== "" ? l("search", a) : l("clear-search");
    }
  };
}
export {
  h as useChatListFilter
};
