import { jsxs as c, jsx as t, Fragment as j } from "react/jsx-runtime";
import * as w from "react";
import { cva as O } from "../../shop-minis-react/node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js";
import { useShopNavigation as M } from "../../hooks/navigation/useShopNavigation.js";
import { useSavedProductsActions as D } from "../../hooks/user/useSavedProductsActions.js";
import { formatMoney as z } from "../../lib/formatMoney.js";
import { cn as n } from "../../lib/utils.js";
import { Touchable as T } from "../atoms/touchable.js";
import { Card as q, CardContent as B, CardAction as U } from "../ui/card.js";
import { FavoriteButton as _ } from "./favorite-button.js";
import E from "../../shop-minis-react/node_modules/.pnpm/lucide-react@0.513.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/star.js";
import { Root as G } from "../../shop-minis-react/node_modules/.pnpm/@radix-ui_react-slot@1.2.3_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-slot/dist/index.js";
const H = O("", {
  variants: {
    layout: {
      horizontal: "w-full !flex-row items-center gap-3 px-4 py-3",
      vertical: "flex-col"
    },
    discount: {
      none: "",
      small: "",
      large: ""
    }
  },
  defaultVariants: {
    layout: "horizontal",
    discount: "none"
  }
});
function J({
  className: e,
  layout: o,
  discount: r,
  asChild: a = !1,
  onPress: l,
  ...s
}) {
  return /* @__PURE__ */ t(
    T,
    {
      onClick: l,
      whileTap: { opacity: 0.7 },
      transition: {
        opacity: { type: "tween", duration: 0.08, ease: "easeInOut" }
      },
      children: /* @__PURE__ */ t(
        a ? G : q,
        {
          className: n(
            H({ layout: o, discount: r }),
            "border-0 bg-white rounded-xl shadow-lg shadow-black/10",
            e
          ),
          ...s
        }
      )
    }
  );
}
function K({
  className: e,
  layout: o = "horizontal",
  ...r
}) {
  return /* @__PURE__ */ t(
    "div",
    {
      "data-slot": "product-link-image",
      className: n(
        "overflow-hidden rounded-md bg-muted",
        o === "horizontal" ? "h-16 w-16 flex-shrink-0" : "aspect-square w-full",
        e
      ),
      ...r
    }
  );
}
function Q({
  className: e,
  layout: o = "horizontal",
  ...r
}) {
  return /* @__PURE__ */ t(
    B,
    {
      className: n(
        o === "horizontal" ? "flex-1 min-w-0 space-y-1 px-0 py-0" : "space-y-2",
        e
      ),
      ...r
    }
  );
}
function W({
  className: e,
  children: o,
  ...r
}) {
  return /* @__PURE__ */ t(
    "h3",
    {
      "data-slot": "product-link-title",
      className: n(
        "text-sm font-medium leading-tight text-gray-900 truncate overflow-hidden whitespace-nowrap text-ellipsis",
        e
      ),
      ...r,
      children: o
    }
  );
}
function X({ className: e, ...o }) {
  return /* @__PURE__ */ t(
    "div",
    {
      "data-slot": "product-link-price",
      className: n("flex items-center gap-2", e),
      ...o
    }
  );
}
function Y({
  className: e,
  ...o
}) {
  return /* @__PURE__ */ t(
    "span",
    {
      "data-slot": "product-link-current-price",
      className: n("text-sm font-semibold text-gray-900", e),
      ...o
    }
  );
}
function Z({
  className: e,
  ...o
}) {
  return /* @__PURE__ */ t(
    "span",
    {
      "data-slot": "product-link-original-price",
      className: n("text-sm text-gray-500 line-through", e),
      ...o
    }
  );
}
function $({
  className: e,
  ...o
}) {
  return /* @__PURE__ */ t(
    "span",
    {
      "data-slot": "product-link-discount-price",
      className: n("text-sm font-semibold text-red-600", e),
      ...o
    }
  );
}
function tt({ className: e, ...o }) {
  return /* @__PURE__ */ t(
    "div",
    {
      "data-slot": "product-link-rating",
      className: n(
        "flex items-center gap-1 text-xs text-muted-foreground",
        e
      ),
      ...o
    }
  );
}
function et({
  className: e,
  onPress: o,
  filled: r = !1,
  ...a
}) {
  return /* @__PURE__ */ t(
    U,
    {
      className: n("flex-shrink-0 self-center px-0 py-0", e),
      ...a,
      children: /* @__PURE__ */ t(
        T,
        {
          stopPropagation: !0,
          onClick: o,
          whileTap: { opacity: 0.7, scale: 0.95 },
          transition: {
            opacity: { type: "tween", duration: 0.08, ease: "easeInOut" },
            scale: { type: "tween", duration: 0.08, ease: "easeInOut" }
          },
          children: /* @__PURE__ */ t(_, { filled: r, onClick: o })
        }
      )
    }
  );
}
function pt({
  product: e,
  hideFavoriteAction: o = !1,
  onClick: r
}) {
  const { navigateToProduct: a } = M(), { saveProduct: l, unsaveProduct: s } = D(), {
    id: i,
    title: P,
    featuredImage: N,
    reviewAnalytics: C,
    price: m,
    compareAtPrice: p,
    isFavorited: R,
    selectedVariant: f,
    defaultVariantId: h,
    shop: g
  } = e, [x, I] = w.useState(R), y = C?.averageRating, L = C?.reviewCount, v = m?.amount ? z(m?.amount, m?.currencyCode) : void 0, b = N?.url, S = N?.altText || P, k = p?.amount ? z(p?.amount, p?.currencyCode) : void 0, A = k && k !== v, V = w.useCallback(() => {
    a({
      productId: i
    }), r?.(e);
  }, [a, i, r, e]), F = w.useCallback(async () => {
    const d = x;
    I(!d);
    try {
      d ? await s({
        productId: i,
        shopId: g.id,
        productVariantId: f?.id || h
      }) : await l({
        productId: i,
        shopId: g.id,
        productVariantId: f?.id || h
      });
    } catch {
      I(d);
    }
  }, [
    x,
    i,
    g.id,
    f?.id,
    h,
    l,
    s
  ]);
  return /* @__PURE__ */ c(
    J,
    {
      layout: "horizontal",
      discount: A ? "small" : "none",
      onPress: V,
      children: [
        /* @__PURE__ */ t(K, { layout: "horizontal", children: b ? /* @__PURE__ */ t(
          "img",
          {
            src: b,
            alt: S,
            className: "h-full w-full object-cover"
          }
        ) : /* @__PURE__ */ t("div", { className: "h-full w-full bg-muted flex items-center justify-center text-muted-foreground text-xs", children: "No Image" }) }),
        /* @__PURE__ */ c(Q, { layout: "horizontal", children: [
          /* @__PURE__ */ t(W, { children: P }),
          L && y ? /* @__PURE__ */ t(tt, { children: /* @__PURE__ */ c("div", { className: "flex items-center gap-1", children: [
            Array.from({ length: 5 }, (d, u) => /* @__PURE__ */ t(
              E,
              {
                fill: u < Math.floor(y) ? "currentColor" : "none",
                className: n(
                  "h-3 w-3",
                  u < Math.floor(y) ? "text-primary" : "text-gray-300"
                )
              },
              u
            )),
            /* @__PURE__ */ c("span", { className: "text-xs text-gray-600 ml-1", children: [
              "(",
              L,
              ")"
            ] })
          ] }) }) : null,
          /* @__PURE__ */ t(X, { children: A ? /* @__PURE__ */ c(j, { children: [
            /* @__PURE__ */ t($, { children: v }),
            /* @__PURE__ */ t(Z, { children: k })
          ] }) : /* @__PURE__ */ t(Y, { children: v }) })
        ] }),
        o ? null : /* @__PURE__ */ t(
          et,
          {
            filled: x,
            onPress: F
          }
        )
      ]
    }
  );
}
export {
  pt as ProductLink
};
//# sourceMappingURL=product-link.js.map
