"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../ui/card.js";
import { Badge } from "../../ui/badge.js";
import { CalendarDays, Eye } from "lucide-react";
function PublicEntityCard({ entityConfig, entitySlug, data, className }) {
  const entityId = data.id;
  let title;
  let description;
  let displayFields = [];
  let entityDisplayName;
  if (entityConfig) {
    const titleField = entityConfig.fields.find(
      (field) => ["title", "name"].includes(field.name) && field.display.showInList
    );
    const descriptionField = entityConfig.fields.find(
      (field) => ["description", "summary", "excerpt"].includes(field.name) && field.display.showInList
    );
    displayFields = entityConfig.fields.filter(
      (field) => field.display.showInList && !["id", "userId", "createdAt", "updatedAt"].includes(field.name) && field.name !== (titleField == null ? void 0 : titleField.name) && field.name !== (descriptionField == null ? void 0 : descriptionField.name)
    ).slice(0, 3);
    title = titleField ? data[titleField.name] : `${entityConfig.names.singular} ${entityId}`;
    description = descriptionField ? data[descriptionField.name] : void 0;
    entityDisplayName = entityConfig.names.singular;
  } else {
    title = data.title || data.name || `Item ${entityId}`;
    description = data.description;
    entityDisplayName = entitySlug.charAt(0).toUpperCase() + entitySlug.slice(1);
  }
  const createdAt = data.createdAt;
  const formatDate = (dateString) => {
    try {
      return new Date(dateString).toLocaleDateString("en-US", {
        year: "numeric",
        month: "short",
        day: "numeric"
      });
    } catch {
      return dateString;
    }
  };
  const formatFieldValue = (field, value) => {
    var _a;
    if (value === null || value === void 0) return "N/A";
    switch (field.type) {
      case "date":
      case "datetime":
        return formatDate(value);
      case "boolean":
        return value ? "Yes" : "No";
      case "number":
        return typeof value === "number" ? value.toLocaleString() : String(value);
      case "select":
        const option = (_a = field.options) == null ? void 0 : _a.find((opt) => opt.value === value);
        return (option == null ? void 0 : option.label) || String(value);
      default:
        return String(value);
    }
  };
  return /* @__PURE__ */ jsx(Card, { className: `group hover:shadow-lg transition-all duration-200 ${className}`, children: /* @__PURE__ */ jsxs(Link, { href: `/${entitySlug}/${entityId}`, className: "block", children: [
    /* @__PURE__ */ jsx(CardHeader, { className: "pb-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
      /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
        /* @__PURE__ */ jsx(CardTitle, { className: "text-lg font-semibold group-hover:text-primary transition-colors line-clamp-2", children: title }),
        description && /* @__PURE__ */ jsx(CardDescription, { className: "mt-2 line-clamp-3", children: description })
      ] }),
      /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors ml-2 flex-shrink-0" })
    ] }) }),
    /* @__PURE__ */ jsxs(CardContent, { className: "pt-0", children: [
      entityConfig && displayFields.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-2 mb-4", children: displayFields.map((field) => /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center text-sm", children: [
        /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-medium", children: [
          field.display.label,
          ":"
        ] }),
        /* @__PURE__ */ jsx("span", { className: "text-foreground font-medium", children: formatFieldValue(field, data[field.name]) })
      ] }, field.name)) }),
      /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between pt-4 border-t", children: [
        createdAt && /* @__PURE__ */ jsxs("div", { className: "flex items-center text-xs text-muted-foreground", children: [
          /* @__PURE__ */ jsx(CalendarDays, { className: "h-3 w-3 mr-1" }),
          formatDate(createdAt)
        ] }),
        /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs", children: entityDisplayName })
      ] })
    ] })
  ] }) });
}
export {
  PublicEntityCard
};
