import { r as reactExports, U as jsxRuntimeExports } from "./worker-entry-Xz__m-MI.js";
import { c as useQuery, e as deliverySettingsQueryOptions, f as computeShipping, D as DEFAULT_DELIVERY_SETTINGS, s as supabase, t as toast, R as Route, g as productBySlugQueryOptions, p as productsQueryOptions, L as Link } from "./router-CHpUX3w1.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CUxLKZvE.js";
import { b as Phone, S as SiteHeader, C as ChevronRight, H as Heart, P as ProductCard, a as SiteFooter } from "./site-footer-Ck1IemTj.js";
import { B as Button } from "./button-DpKP5ewx.js";
import { D as Dialog, a as DialogContent, b as DialogHeader, c as DialogTitle, d as DialogDescription } from "./dialog-Cw8a5lVd.js";
import { I as Input } from "./input-79qqvIMV.js";
import { L as Label } from "./label-BQmy2bHJ.js";
import { T as Textarea } from "./textarea-CV9jx0-G.js";
import { S as Separator, a as Smartphone } from "./separator-QYwxpaB0.js";
import { L as LoaderCircle } from "./loader-circle-ON2Oh-nH.js";
import { C as CircleCheck } from "./circle-check-B0jtwFsN.js";
import { c as createLucideIcon } from "./createLucideIcon-4cZKQB6y.js";
import { o as objectType, s as stringType } from "./types-DGfzljZx.js";
import { P as Plus } from "./plus-DhfO3J3U.js";
import { T as Truck } from "./truck-z30CqIo1.js";
import "node:events";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./index-P9m2NEcT.js";
import "./index-BGCFm29u.js";
import "./Combination-DLYpVfee.js";
import "./index-MHtqZ26n.js";
import "./index-C7lwDevP.js";
import "./utils-Bz4m9VPB.js";
import "./shopping-bag-CbDsBdXX.js";
const __iconNode$5 = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
  ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
];
const CircleAlert = createLucideIcon("circle-alert", __iconNode$5);
const __iconNode$4 = [
  ["rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2", key: "17jyea" }],
  ["path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2", key: "zix9uf" }]
];
const Copy = createLucideIcon("copy", __iconNode$4);
const __iconNode$3 = [["path", { d: "M5 12h14", key: "1ays0h" }]];
const Minus = createLucideIcon("minus", __iconNode$3);
const __iconNode$2 = [
  ["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
  ["path", { d: "M3 3v5h5", key: "1xhq8a" }]
];
const RotateCcw = createLucideIcon("rotate-ccw", __iconNode$2);
const __iconNode$1 = [
  [
    "path",
    {
      d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
      key: "oel41y"
    }
  ]
];
const Shield = createLucideIcon("shield", __iconNode$1);
const __iconNode = [
  [
    "path",
    {
      d: "M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",
      key: "1s2grr"
    }
  ],
  ["path", { d: "M20 2v4", key: "1rf3ol" }],
  ["path", { d: "M22 4h-4", key: "gwowj6" }],
  ["circle", { cx: "4", cy: "20", r: "2", key: "6kqj1y" }]
];
const Sparkles = createLucideIcon("sparkles", __iconNode);
const orderSchema = objectType({
  customer_name: stringType().trim().min(2, { message: "নাম কমপক্ষে ২ অক্ষরের হতে হবে" }).max(100),
  customer_phone: stringType().trim().regex(/^\+?[0-9]{10,15}$/, { message: "সঠিক ফোন নম্বর দিন (১০-১৫ ডিজিট)" }),
  customer_address: stringType().trim().min(5, { message: "ঠিকানা কমপক্ষে ৫ অক্ষরের হতে হবে" }).max(500),
  customer_city: stringType().trim().min(2, { message: "শহরের নাম দিন" }).max(100),
  customer_note: stringType().trim().max(500).optional()
});
const ERROR_MESSAGES = {
  invalid_name: "সঠিক নাম দিন",
  invalid_phone: "সঠিক ফোন নম্বর দিন",
  invalid_address: "সঠিক ঠিকানা দিন",
  invalid_city: "সঠিক শহরের নাম দিন",
  invalid_quantity: "পরিমাণ ১ থেকে ১০ এর মধ্যে হতে হবে",
  active_order_exists: "আপনার একটি চলমান অর্ডার রয়েছে। সেটি ডেলিভারি সম্পন্ন হলে নতুন অর্ডার দিতে পারবেন।",
  blacklisted: "এই ফোন নম্বরটি ব্লক করা হয়েছে। সাহায্যের জন্য আমাদের সাথে যোগাযোগ করুন।",
  product_not_found: "প্রোডাক্টটি পাওয়া যায়নি",
  invalid_size: "সঠিক সাইজ নির্বাচন করুন",
  invalid_variant: "সঠিক কালার নির্বাচন করুন",
  invalid_txn_id: "সঠিক Transaction ID দিন (কমপক্ষে ৬ অক্ষর)",
  invalid_sender_phone: "সঠিক বিকাশ নম্বর দিন",
  duplicate_txn_id: "এই Transaction ID আগেই ব্যবহৃত হয়েছে",
  already_paid: "এই অর্ডারের পেমেন্ট ইতিমধ্যে দেওয়া হয়েছে",
  order_not_found: "অর্ডারটি পাওয়া যায়নি"
};
function OrderFormDialog({
  open,
  onOpenChange,
  product,
  selectedColor,
  selectedSize,
  quantity
}) {
  const [formData, setFormData] = reactExports.useState({
    customer_name: "",
    customer_phone: "",
    customer_address: "",
    customer_city: "",
    customer_note: ""
  });
  const [errors, setErrors] = reactExports.useState({});
  const [submitting, setSubmitting] = reactExports.useState(false);
  const [advance, setAdvance] = reactExports.useState(null);
  const [success, setSuccess] = reactExports.useState(null);
  const { data: deliverySettings } = useQuery(deliverySettingsQueryOptions());
  const settings = deliverySettings ?? DEFAULT_DELIVERY_SETTINGS;
  const subtotal = product.price * quantity;
  const shippingCost = computeShipping(settings, formData.customer_city, subtotal);
  const isFree = shippingCost === 0;
  const total = subtotal + shippingCost;
  const updateField = (field, value) => {
    setFormData((prev) => ({ ...prev, [field]: value }));
    if (errors[field]) setErrors((prev) => ({ ...prev, [field]: void 0 }));
  };
  const handleSubmit = async (e) => {
    e.preventDefault();
    const parsed = orderSchema.safeParse(formData);
    if (!parsed.success) {
      const fieldErrors = {};
      for (const issue of parsed.error.issues) {
        const key = issue.path[0];
        if (!fieldErrors[key]) fieldErrors[key] = issue.message;
      }
      setErrors(fieldErrors);
      return;
    }
    setSubmitting(true);
    try {
      const { data, error } = await supabase.rpc("place_order", {
        _customer_name: parsed.data.customer_name,
        _customer_phone: parsed.data.customer_phone,
        _customer_address: parsed.data.customer_address,
        _customer_city: parsed.data.customer_city,
        _customer_note: parsed.data.customer_note ?? "",
        _product_id: product.id,
        _variant_id: selectedColor.id,
        _size: selectedSize,
        _quantity: quantity,
        _shipping_cost: shippingCost
      });
      if (error) {
        toast.error("অর্ডার সাবমিট করতে সমস্যা হয়েছে", { description: error.message });
        return;
      }
      const result = data?.[0];
      if (!result) {
        toast.error("অপ্রত্যাশিত ত্রুটি");
        return;
      }
      if (result.error_code) {
        toast.error(ERROR_MESSAGES[result.error_code] ?? "অর্ডার করতে সমস্যা হয়েছে");
        return;
      }
      if (result.requires_advance) {
        setAdvance({
          orderId: result.order_id,
          orderNumber: result.order_number,
          total: Number(result.total_amount),
          amount: Number(result.advance_amount),
          bkash: result.bkash_number ?? "01575646291"
        });
      } else {
        setSuccess({
          orderNumber: result.order_number,
          total: Number(result.total_amount)
        });
      }
    } catch (err) {
      toast.error("অর্ডার সাবমিট করতে সমস্যা হয়েছে", {
        description: err instanceof Error ? err.message : "অজানা ত্রুটি"
      });
    } finally {
      setSubmitting(false);
    }
  };
  const handleClose = (next) => {
    if (submitting) return;
    if (!next) {
      setTimeout(() => {
        setSuccess(null);
        setAdvance(null);
        setErrors({});
        if (success || advance) {
          setFormData({
            customer_name: "",
            customer_phone: "",
            customer_address: "",
            customer_city: "",
            customer_note: ""
          });
        }
      }, 200);
    }
    onOpenChange(next);
  };
  const handleAdvancePaid = () => {
    if (!advance) return;
    setSuccess({ orderNumber: advance.orderNumber, total: advance.total });
    setAdvance(null);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Dialog, { open, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DialogContent, { className: "max-w-lg max-h-[90vh] overflow-y-auto", children: success ? /* @__PURE__ */ jsxRuntimeExports.jsx(SuccessView, { success, onClose: () => handleClose(false) }) : advance ? /* @__PURE__ */ jsxRuntimeExports.jsx(
    AdvancePaymentView,
    {
      advance,
      customerPhone: formData.customer_phone,
      onPaid: handleAdvancePaid
    }
  ) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogHeader, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTitle, { className: "font-display text-2xl", children: "অর্ডার সম্পন্ন করুন" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(DialogDescription, { children: "আপনার তথ্য দিন — ক্যাশ অন ডেলিভারি উপলব্ধ" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-xl bg-secondary/40 p-3 flex gap-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        "img",
        {
          src: selectedColor.imageUrl,
          alt: product.name,
          className: "h-16 w-16 rounded-lg object-cover flex-shrink-0"
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-medium text-foreground line-clamp-1", children: product.name }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-muted-foreground mt-0.5", children: [
          selectedColor.name,
          " • সাইজ ",
          selectedSize,
          " • পরিমাণ ",
          quantity
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm font-semibold text-primary mt-1", children: [
          "৳",
          subtotal.toLocaleString("bn-BD")
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "name", children: [
          "পূর্ণ নাম ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Input,
          {
            id: "name",
            value: formData.customer_name,
            onChange: (e) => updateField("customer_name", e.target.value),
            placeholder: "যেমন: ফাতেমা আক্তার",
            maxLength: 100,
            disabled: submitting
          }
        ),
        errors.customer_name && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.customer_name })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "phone", children: [
          "ফোন নম্বর ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Phone, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Input,
            {
              id: "phone",
              type: "tel",
              value: formData.customer_phone,
              onChange: (e) => updateField("customer_phone", e.target.value),
              placeholder: "01XXXXXXXXX",
              className: "pl-9",
              maxLength: 15,
              disabled: submitting
            }
          )
        ] }),
        errors.customer_phone && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.customer_phone })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "city", children: [
          "শহর/জেলা ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Input,
          {
            id: "city",
            value: formData.customer_city,
            onChange: (e) => updateField("customer_city", e.target.value),
            placeholder: "ঢাকা",
            maxLength: 100,
            disabled: submitting
          }
        ),
        errors.customer_city && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.customer_city })
      ] }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "address", children: [
          "সম্পূর্ণ ঠিকানা ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Textarea,
          {
            id: "address",
            value: formData.customer_address,
            onChange: (e) => updateField("customer_address", e.target.value),
            placeholder: "বাসা/হোল্ডিং, রোড, এলাকা, থানা",
            rows: 2,
            maxLength: 500,
            disabled: submitting
          }
        ),
        errors.customer_address && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.customer_address })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "note", children: "অতিরিক্ত নোট (ঐচ্ছিক)" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Textarea,
          {
            id: "note",
            value: formData.customer_note ?? "",
            onChange: (e) => updateField("customer_note", e.target.value),
            placeholder: "ডেলিভারি সংক্রান্ত কোন বিশেষ নির্দেশনা...",
            rows: 2,
            maxLength: 500,
            disabled: submitting
          }
        )
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5 text-sm", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "সাবটোটাল" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-foreground", children: [
            "৳",
            subtotal.toLocaleString("bn-BD")
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "শিপিং চার্জ" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: isFree ? "text-green-600 font-semibold" : "text-foreground", children: isFree ? "ফ্রি" : `৳${shippingCost.toLocaleString("bn-BD")}` })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-base font-semibold pt-1.5 border-t border-border", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-foreground", children: "মোট পরিশোধ" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-primary", children: [
            "৳",
            total.toLocaleString("bn-BD")
          ] })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button,
        {
          type: "submit",
          size: "lg",
          disabled: submitting,
          className: "w-full h-12 rounded-full text-base shadow-soft",
          children: submitting ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
            "প্রসেসিং..."
          ] }) : "অর্ডার নিশ্চিত করুন"
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-center text-muted-foreground", children: "অর্ডার করার মাধ্যমে আপনি আমাদের শর্তাবলী মেনে নিচ্ছেন" })
    ] })
  ] }) }) });
}
function SuccessView({
  success,
  onClose
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-4 text-center space-y-4", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mx-auto w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CircleCheck, { className: "h-9 w-9 text-primary" }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "font-display text-2xl text-foreground", children: "অর্ডার সফল হয়েছে! 🎉" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-muted-foreground mt-1", children: "আমরা শীঘ্রই আপনার সাথে যোগাযোগ করব" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-xl bg-secondary/40 p-4 space-y-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "অর্ডার নম্বর" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono font-semibold text-foreground", children: success.orderNumber })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "মোট পরিমাণ" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-semibold text-foreground", children: [
          "৳",
          success.total.toLocaleString("bn-BD")
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: onClose, className: "w-full rounded-full", size: "lg", children: "ঠিক আছে" })
  ] });
}
function AdvancePaymentView({
  advance,
  customerPhone,
  onPaid
}) {
  const [txnId, setTxnId] = reactExports.useState("");
  const [senderPhone, setSenderPhone] = reactExports.useState("");
  const [submitting, setSubmitting] = reactExports.useState(false);
  const [errors, setErrors] = reactExports.useState({});
  const copyNumber = async () => {
    try {
      await navigator.clipboard.writeText(advance.bkash);
      toast.success("বিকাশ নম্বর কপি হয়েছে");
    } catch {
      toast.error("কপি করতে সমস্যা হয়েছে");
    }
  };
  const handleSubmit = async (e) => {
    e.preventDefault();
    const errs = {};
    if (txnId.trim().length < 6) errs.txn = "Transaction ID কমপক্ষে ৬ অক্ষর";
    if (!/^\+?[0-9]{10,15}$/.test(senderPhone.trim()))
      errs.sender = "সঠিক বিকাশ নম্বর দিন";
    if (errs.txn || errs.sender) {
      setErrors(errs);
      return;
    }
    setErrors({});
    setSubmitting(true);
    try {
      const { data, error } = await supabase.rpc("submit_advance_payment", {
        _order_id: advance.orderId,
        _customer_phone: customerPhone,
        _txn_id: txnId.trim(),
        _sender_phone: senderPhone.trim()
      });
      if (error) {
        toast.error("পেমেন্ট সাবমিট করতে সমস্যা হয়েছে", { description: error.message });
        return;
      }
      const result = data?.[0];
      if (!result?.success) {
        toast.error(ERROR_MESSAGES[result?.error_code ?? ""] ?? "পেমেন্ট সাবমিট ব্যর্থ");
        return;
      }
      toast.success("পেমেন্ট রেকর্ড হয়েছে! আমরা যাচাই করে যোগাযোগ করব।");
      onPaid();
    } finally {
      setSubmitting(false);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogHeader, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogTitle, { className: "font-display text-xl flex items-center gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Smartphone, { className: "h-5 w-5 text-pink-600" }),
        "অগ্রিম পেমেন্ট প্রয়োজন"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(DialogDescription, { children: "আপনার পূর্ববর্তী অর্ডার বাতিল হয়েছিল। নতুন অর্ডার নিশ্চিত করতে অগ্রিম ডেলিভারি চার্জ পাঠাতে হবে।" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-xl border-2 border-pink-200 bg-gradient-to-br from-pink-50 to-rose-50 p-4 space-y-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs uppercase tracking-wider text-pink-700 font-semibold", children: "বিকাশ — Send Money" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs px-2 py-0.5 rounded-full bg-pink-600 text-white font-medium", children: "Personal" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-2 bg-white rounded-lg px-3 py-2.5 border border-pink-100", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-lg font-bold tracking-wide text-pink-900", children: advance.bkash }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          Button,
          {
            type: "button",
            variant: "ghost",
            size: "sm",
            onClick: copyNumber,
            className: "text-pink-700 hover:bg-pink-100 h-8",
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Copy, { className: "h-3.5 w-3.5 mr-1" }),
              " কপি"
            ]
          }
        )
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between bg-white/70 rounded-lg px-3 py-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-muted-foreground", children: "পরিমাণ" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-bold text-lg text-pink-900", children: [
          "৳",
          advance.amount.toLocaleString("bn-BD")
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between bg-white/70 rounded-lg px-3 py-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-muted-foreground", children: "অর্ডার নম্বর" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-sm font-semibold", children: advance.orderNumber })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-lg bg-amber-50 border border-amber-200 p-3 flex gap-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(CircleAlert, { className: "h-4 w-4 text-amber-700 flex-shrink-0 mt-0.5" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-amber-800 space-y-1", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-semibold", children: "পেমেন্টের ধাপ:" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: "list-decimal list-inside space-y-0.5", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "বিকাশ অ্যাপে যান → Send Money" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
            "উপরের নম্বরে ৳",
            advance.amount,
            " পাঠান"
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "SMS-এ পাওয়া Transaction ID নিচে লিখুন" })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, className: "space-y-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "txn", children: [
          "Transaction ID (TrxID) ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Input,
          {
            id: "txn",
            value: txnId,
            onChange: (e) => setTxnId(e.target.value.toUpperCase()),
            placeholder: "যেমন: 9F4G7H2K8L",
            maxLength: 30,
            disabled: submitting,
            className: "font-mono"
          }
        ),
        errors.txn && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.txn })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "sender", children: [
          "যে নম্বর থেকে পাঠিয়েছেন ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Input,
          {
            id: "sender",
            type: "tel",
            value: senderPhone,
            onChange: (e) => setSenderPhone(e.target.value),
            placeholder: "01XXXXXXXXX",
            maxLength: 15,
            disabled: submitting
          }
        ),
        errors.sender && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-destructive", children: errors.sender })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button,
        {
          type: "submit",
          size: "lg",
          disabled: submitting,
          className: "w-full h-12 rounded-full text-base bg-pink-600 hover:bg-pink-700",
          children: submitting ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
            " যাচাই হচ্ছে..."
          ] }) : "পেমেন্ট সাবমিট করুন"
        }
      )
    ] })
  ] });
}
function ProductDetailPage() {
  const {
    slug
  } = Route.useParams();
  const {
    data: product
  } = useSuspenseQuery(productBySlugQueryOptions(slug));
  const {
    data: allProducts
  } = useSuspenseQuery(productsQueryOptions());
  const firstColor = product?.colors[0];
  const [selectedColor, setSelectedColor] = reactExports.useState(firstColor);
  const [selectedSize, setSelectedSize] = reactExports.useState(null);
  const [quantity, setQuantity] = reactExports.useState(1);
  const [orderOpen, setOrderOpen] = reactExports.useState(false);
  if (!product || !selectedColor) return null;
  const related = allProducts.filter((p) => p.id !== product.id).slice(0, 4);
  const handleOrder = () => {
    if (!selectedSize) {
      toast.error("দয়া করে একটি সাইজ নির্বাচন করুন");
      return;
    }
    setOrderOpen(true);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-h-screen bg-background", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(SiteHeader, {}),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mx-auto max-w-7xl px-4 md:px-8 py-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("nav", { className: "flex items-center gap-1.5 text-sm text-muted-foreground", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: "/", className: "hover:text-primary", children: "হোম" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "h-3.5 w-3.5" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "hover:text-primary cursor-pointer", children: product.category }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "h-3.5 w-3.5" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-foreground line-clamp-1", children: product.name })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("section", { className: "mx-auto max-w-7xl px-4 md:px-8 pb-12", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-10 lg:grid-cols-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative aspect-[4/5] overflow-hidden rounded-3xl bg-secondary/40 shadow-soft", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: selectedColor.imageUrl, alt: `${product.name} - ${selectedColor.name}`, width: 1024, height: 1280, className: "h-full w-full object-cover transition-all duration-500" }),
          product.isNew && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute top-4 left-4 rounded-full bg-background/90 backdrop-blur px-4 py-1.5 text-xs font-semibold uppercase tracking-wider text-primary", children: "নতুন" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex gap-3", children: product.colors.map((c) => /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setSelectedColor(c), className: `relative aspect-square w-20 overflow-hidden rounded-xl border-2 transition-all ${selectedColor.id === c.id ? "border-primary shadow-soft" : "border-transparent opacity-70 hover:opacity-100"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: c.imageUrl, alt: c.name, loading: "lazy", width: 200, height: 250, className: "h-full w-full object-cover" }) }, c.id)) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs uppercase tracking-[0.2em] text-primary", children: product.category }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "font-display text-4xl md:text-5xl mt-2 text-foreground", children: product.name }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-baseline gap-3 mt-4", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-3xl font-semibold text-foreground", children: [
              "৳",
              product.price.toLocaleString("bn-BD")
            ] }),
            product.oldPrice && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-lg text-muted-foreground line-through", children: [
                "৳",
                product.oldPrice.toLocaleString("bn-BD")
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-semibold text-primary", children: [
                Math.round((product.oldPrice - product.price) / product.oldPrice * 100),
                "% ছাড়"
              ] })
            ] })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-foreground/80 leading-relaxed", children: product.description }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-xl bg-secondary/40 p-4 flex items-center gap-2 text-sm", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Sparkles, { className: "h-4 w-4 text-primary flex-shrink-0" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-foreground/80", children: [
            "ফ্যাব্রিক: ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-foreground", children: product.fabric })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-semibold text-foreground", children: "কালার:" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-muted-foreground", children: selectedColor.name })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex gap-3", children: product.colors.map((c) => /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setSelectedColor(c), "aria-label": c.name, className: `h-11 w-11 rounded-full border-2 transition-all ${selectedColor.id === c.id ? "border-primary ring-2 ring-primary/30 ring-offset-2 ring-offset-background scale-110" : "border-border hover:border-primary/50"}`, style: {
            backgroundColor: c.hex
          } }, c.id)) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-semibold text-foreground", children: "সাইজ:" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "text-xs text-primary hover:underline", children: "সাইজ গাইড" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-wrap gap-2", children: product.sizes.map((size) => /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setSelectedSize(size), className: `min-w-[3rem] h-11 px-4 rounded-xl border text-sm font-medium transition-all ${selectedSize === size ? "bg-primary text-primary-foreground border-primary shadow-soft" : "bg-background border-border hover:border-primary"}`, children: size }, size)) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-semibold text-foreground block mb-3", children: "পরিমাণ:" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center rounded-xl border border-border bg-background", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setQuantity(Math.max(1, quantity - 1)), className: "h-11 w-11 flex items-center justify-center hover:bg-secondary rounded-l-xl", "aria-label": "Decrease", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Minus, { className: "h-4 w-4" }) }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-12 text-center font-medium", children: quantity }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setQuantity(quantity + 1), className: "h-11 w-11 flex items-center justify-center hover:bg-secondary rounded-r-xl", "aria-label": "Increase", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "h-4 w-4" }) })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-3 pt-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "lg", onClick: handleOrder, className: "flex-1 h-14 rounded-full text-base shadow-soft", children: "অর্ডার করুন" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "lg", variant: "outline", className: "h-14 w-14 rounded-full border-primary/30", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Heart, { className: "h-5 w-5" }) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-3 gap-3 pt-6 border-t border-border", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Truck, { className: "h-5 w-5 mx-auto text-primary mb-1.5" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "ফ্রি শিপিং" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(RotateCcw, { className: "h-5 w-5 mx-auto text-primary mb-1.5" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "৭ দিন রিটার্ন" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Shield, { className: "h-5 w-5 mx-auto text-primary mb-1.5" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "নিরাপদ পেমেন্ট" })
          ] })
        ] })
      ] })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "mx-auto max-w-7xl px-4 md:px-8 py-16 border-t border-border", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "font-display text-3xl md:text-4xl text-center mb-10", children: [
        "আপনার ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-script text-primary italic", children: "পছন্দ" }),
        " হতে পারে"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 gap-4 md:gap-6 lg:grid-cols-4", children: related.map((p) => /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { product: p }, p.id)) })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(SiteFooter, {}),
    selectedSize && /* @__PURE__ */ jsxRuntimeExports.jsx(OrderFormDialog, { open: orderOpen, onOpenChange: setOrderOpen, product, selectedColor, selectedSize, quantity })
  ] });
}
export {
  ProductDetailPage as component
};
