/* empty css                                       */
import { d as createAstro, c as createComponent, r as renderComponent, a as renderTemplate, m as maybeRenderHead, u as unescapeHTML } from '../../chunks/astro/server_5mFihzcn.mjs';
import { $ as $$PaginationTab } from '../../chunks/PaginationTab_CeD0cUyT.mjs';
import { $ as $$Card } from '../../chunks/Card_CIZXu6HZ.mjs';
import { $ as $$MessageHeader } from '../../chunks/MessageHeader_Cbxh23zH.mjs';
import { $ as $$Layout, s as slugify } from '../../chunks/Layout_v67TeP9G.mjs';
import { a as getAllMessages, b as getUnreadMessages } from '../../chunks/message_DAReJ7u_.mjs';
/* empty css                                    */
export { renderers } from '../../renderers.mjs';

const $$Astro = createAstro("https://new.sambekiel.com");
const $$Index = createComponent(async ($$result, $$props, $$slots) => {
  const Astro2 = $$result.createAstro($$Astro, $$props, $$slots);
  Astro2.self = $$Index;
  const { searchParams } = Astro2.url;
  const getAll = async ({
    pageNo: pageNo2 = 1,
    tab: tab2
  }) => {
    try {
      return tab2 !== "unread" ? await getAllMessages(pageNo2) : await getUnreadMessages(pageNo2);
    } catch (error) {
      console.log(error);
    }
  };
  const tab = searchParams.get("tab") ?? void 0;
  const page = searchParams.get("page");
  const pageNo = Number(page) >= 1 && Number(page).toString().toLowerCase() !== "nan" ? Number(page) : 1;
  const messages = await getAll({ pageNo, tab });
  return renderTemplate`${renderComponent($$result, "Layout", $$Layout, { "title": "Messages", "data-astro-cid-affluur2": true }, { "default": async ($$result2) => renderTemplate` ${renderComponent($$result2, "MessageHeader", $$MessageHeader, { "tab": tab, "data-astro-cid-affluur2": true })} ${maybeRenderHead()}<section class="message-cards mb-[2rem]" data-astro-cid-affluur2> ${messages?.chats?.map((msg) => renderTemplate`${renderComponent($$result2, "Card", $$Card, { "className": "border-blue-900/5 border rounded-lg hover:shadow-md hover:scale-105 ", "title": msg.subject, "body": `${msg.name} - ${msg.email}`, "lines": 3, "href": `/dashboard/messages/${slugify(msg.subject)}-msg-${msg.id}`, "data-astro-cid-affluur2": true }, { "default": async ($$result3) => renderTemplate` <div data-astro-cid-affluur2>${unescapeHTML(msg.message)}</div> ` })}`)} </section> ${renderComponent($$result2, "PaginationTab", $$PaginationTab, { "total_pages": messages?.total_pages ?? 0, "data-astro-cid-affluur2": true })} ` })} `;
}, "C:/projects/sambekiel_front/src/pages/dashboard/messages/index.astro", void 0);

const $$file = "C:/projects/sambekiel_front/src/pages/dashboard/messages/index.astro";
const $$url = "/dashboard/messages";

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  default: $$Index,
  file: $$file,
  url: $$url
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
