"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const LucideIcons = require('lucide-react');
const card = require('../../../../../../../ui/src/components/card.cjs');
const context = require('@btst/stack/context');
const emptyState = require('../shared/empty-state.cjs');
const pageWrapper = require('../shared/page-wrapper.cjs');
const index = require('../../localization/index.cjs');
const useRouteLifecycle = require('../../../../../../../ui/src/hooks/use-route-lifecycle.cjs');
const cmsHooks = require('../../hooks/cms-hooks.cjs');

function DashboardPage() {
  const overrides = context.usePluginOverrides("cms");
  const { navigate } = overrides;
  const localization = { ...index.CMS_LOCALIZATION, ...overrides.localization };
  const basePath = context.useBasePath();
  useRouteLifecycle.useRouteLifecycle({
    routeName: "dashboard",
    context: {
      path: "/cms",
      isSSR: typeof window === "undefined"
    },
    overrides,
    beforeRenderHook: (overrides2, context) => {
      if (overrides2.onBeforeDashboardRendered) {
        return overrides2.onBeforeDashboardRendered(context);
      }
      return true;
    }
  });
  const { contentTypes } = cmsHooks.useSuspenseContentTypes();
  if (contentTypes.length === 0) {
    return /* @__PURE__ */ jsxRuntime.jsx(pageWrapper.PageWrapper, { testId: "cms-dashboard-page", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-5xl space-y-6", children: [
      /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-bold tracking-tight", children: localization.CMS_DASHBOARD_TITLE }),
        /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: localization.CMS_DASHBOARD_SUBTITLE })
      ] }),
      /* @__PURE__ */ jsxRuntime.jsx(
        emptyState.EmptyState,
        {
          title: localization.CMS_DASHBOARD_NO_TYPES,
          description: localization.CMS_DASHBOARD_NO_TYPES_DESCRIPTION
        }
      )
    ] }) });
  }
  const formatItemCount = (count) => {
    if (count === 0) return localization.CMS_DASHBOARD_ITEMS_COUNT_ZERO;
    if (count === 1) return localization.CMS_DASHBOARD_ITEMS_COUNT_ONE;
    return localization.CMS_DASHBOARD_ITEMS_COUNT.replace(
      "{count}",
      String(count)
    );
  };
  return /* @__PURE__ */ jsxRuntime.jsx(pageWrapper.PageWrapper, { testId: "cms-dashboard-page", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-5xl space-y-6", children: [
    /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
      /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-bold tracking-tight", children: localization.CMS_DASHBOARD_TITLE }),
      /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: localization.CMS_DASHBOARD_SUBTITLE })
    ] }),
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid gap-4 md:grid-cols-2 lg:grid-cols-3", children: contentTypes.map((ct) => /* @__PURE__ */ jsxRuntime.jsxs(
      card.Card,
      {
        className: "hover:border-primary/50 transition-colors cursor-pointer",
        onClick: () => navigate(`${basePath}/cms/${ct.slug}`),
        children: [
          /* @__PURE__ */ jsxRuntime.jsxs(card.CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [
            /* @__PURE__ */ jsxRuntime.jsx(card.CardTitle, { className: "text-lg font-medium", children: ct.name }),
            /* @__PURE__ */ jsxRuntime.jsx(LucideIcons.FileText, { className: "h-5 w-5 text-muted-foreground" })
          ] }),
          /* @__PURE__ */ jsxRuntime.jsxs(card.CardContent, { children: [
            /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-2xl font-bold", children: ct.itemCount }),
            /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: formatItemCount(ct.itemCount) }),
            ct.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground mt-2 line-clamp-2", children: ct.description })
          ] })
        ]
      },
      ct.id
    )) })
  ] }) });
}

exports.DashboardPage = DashboardPage;
