"use client";
import Image from "next/image";
import { useMemo, useState } from "react";
import type { ProductDetail, ProductVariantOption } from "@/data/product-detail";
import BilingualTitle from "@/components/ui/BilingualTitle";
type ProductBuyBoxProps = {
product: ProductDetail;
};
function OptionRow({
labelFa,
labelEn,
options,
value,
onChange,
kind,
}: {
labelFa: string;
labelEn: string;
options: ProductVariantOption[];
value: string;
onChange: (id: string) => void;
kind: "color" | "size" | "package";
}) {
if (!options.length) return null;
return (
{options.map((opt) => {
const selected = value === opt.id;
const disabled = opt.available === false;
const tip = opt.labelEn || opt.labelFa;
if (kind === "color") {
return (
);
}
return (
);
})}
);
}
export default function ProductBuyBox({ product }: ProductBuyBoxProps) {
const firstColor =
product.colors.find((c) => c.available !== false)?.id ??
product.colors[0]?.id ??
"";
const firstSize =
product.sizes.find((s) => s.available !== false)?.id ??
product.sizes[0]?.id ??
"";
const firstPackage =
product.packages.find((p) => p.available !== false)?.id ??
product.packages[0]?.id ??
"";
const [color, setColor] = useState(firstColor);
const [size, setSize] = useState(firstSize);
const [pkg, setPkg] = useState(firstPackage);
const selectedColor = useMemo(
() => product.colors.find((c) => c.id === color),
[color, product.colors],
);
return (
{/* Sizing guide frame */}
{product.sizeGuideImage ? (
) : (
Size chart
)}
);
}