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