{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shipping-estimator",
  "title": "Shipping Estimator",
  "description": "A shipping and delivery estimator: a free-shipping progress bar, country and postal code fields with per-country validation, delivery options (Standard, Express, Next day, store pickup) with prices and business-day ranges, remote-area surcharges and an animated timeline of real delivery dates for the chosen option.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/shipping-estimator/shipping-estimator.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, LayoutGroup, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ShipCountry {\n  code: string;\n  name: string;\n  postalLabel: string;\n  placeholder: string;\n  pattern: RegExp;\n  /** Business days: [min, max] per method; null = not offered. */\n  standard: [number, number];\n  express: [number, number] | null;\n  nextDay: boolean;\n  expressPrice: number;\n  /** Postal codes that start with one of these get a surcharge and no next-day. */\n  remote?: string[];\n}\nexport interface ShipOption {\n  id: string;\n  label: string;\n  price: number;\n  days: [number, number];\n  note?: string;\n}\nexport interface ShippingEstimatorProps {\n  countries?: ShipCountry[];\n  subtotal?: number;\n  freeOver?: number;\n  currency?: string;\n  store?: { name: string; address: string };\n  onSelect?: (option: ShipOption, location: { country: string; postal: string }) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    card: \"#141414\",\n    field: \"#0F0F0F\",\n    title: \"#FFFFFF\",\n    muted: \"rgba(255,255,255,0.45)\",\n    body: \"rgba(255,255,255,0.62)\",\n    line: \"rgba(255,255,255,0.12)\",\n    lineHi: \"rgba(255,255,255,0.32)\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    accentSoft: \"rgba(124,222,106,0.1)\",\n    amber: \"#F5B44A\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    error: \"#FF7A70\",\n    scheme: \"dark\" as const,\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    card: \"#F7F7F7\",\n    field: \"#FFFFFF\",\n    title: \"#111111\",\n    muted: \"rgba(0,0,0,0.45)\",\n    body: \"rgba(0,0,0,0.62)\",\n    line: \"rgba(0,0,0,0.1)\",\n    lineHi: \"rgba(0,0,0,0.3)\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    accentSoft: \"rgba(47,158,68,0.08)\",\n    amber: \"#B86E00\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    error: \"#D93025\",\n    scheme: \"light\" as const,\n  },\n};\ntype Palette = (typeof PALETTES)[keyof typeof PALETTES];\n\nconst COUNTRIES: ShipCountry[] = [\n  { code: \"US\", name: \"United States\", postalLabel: \"ZIP code\", placeholder: \"10001\", pattern: /^\\d{5}$/, standard: [3, 5], express: [1, 2], nextDay: true, expressPrice: 12, remote: [\"995\", \"996\", \"997\", \"998\", \"999\", \"967\", \"968\"] },\n  { code: \"GB\", name: \"United Kingdom\", postalLabel: \"Postcode\", placeholder: \"SW1A 1AA\", pattern: /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i, standard: [2, 4], express: [1, 2], nextDay: true, expressPrice: 14, remote: [\"HS\", \"ZE\", \"KW\"] },\n  { code: \"DE\", name: \"Germany\", postalLabel: \"Postleitzahl\", placeholder: \"10115\", pattern: /^\\d{5}$/, standard: [4, 7], express: [2, 3], nextDay: false, expressPrice: 18 },\n  { code: \"NL\", name: \"Netherlands\", postalLabel: \"Postcode\", placeholder: \"1011 AB\", pattern: /^\\d{4} ?[A-Z]{2}$/i, standard: [4, 6], express: [2, 3], nextDay: false, expressPrice: 18 },\n  { code: \"TR\", name: \"Türkiye\", postalLabel: \"Posta kodu\", placeholder: \"34000\", pattern: /^\\d{5}$/, standard: [6, 10], express: [3, 5], nextDay: false, expressPrice: 22 },\n  { code: \"CA\", name: \"Canada\", postalLabel: \"Postal code\", placeholder: \"M5V 2T6\", pattern: /^[A-Z]\\d[A-Z] ?\\d[A-Z]\\d$/i, standard: [5, 8], express: [2, 4], nextDay: false, expressPrice: 16, remote: [\"X\", \"Y\"] },\n];\nconst STORE = { name: \"Northline Soho\", address: \"112 Mercer St, New York\" };\nconst DAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nfunction addBusinessDays(from: Date, n: number) {\n  const d = new Date(from);\n  let left = n;\n  while (left > 0) {\n    d.setDate(d.getDate() + 1);\n    if (d.getDay() !== 0 && d.getDay() !== 6) left -= 1;\n  }\n  return d;\n}\nconst fmt = (d: Date) => `${DAYS[d.getDay()]}, ${MONTHS[d.getMonth()]} ${d.getDate()}`;\nconst money = (n: number, c: string) => (n === 0 ? \"Free\" : `${c}${n.toFixed(2)}`);\n\nfunction Icon({ id }: { id: string }) {\n  const common = { width: 18, height: 18, viewBox: \"0 0 24 24\", fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.8, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, \"aria-hidden\": true };\n  if (id === \"pickup\")\n    return (\n      <svg {...common}>\n        <path d=\"M4 10h16l-1.2-5H5.2zM5 10v9h14v-9M10 19v-5h4v5\" />\n      </svg>\n    );\n  if (id === \"next\")\n    return (\n      <svg {...common}>\n        <path d=\"M13 3 5 13.5h6L10 21l8-10.5h-6z\" />\n      </svg>\n    );\n  return (\n    <svg {...common}>\n      <path d=\"M3 7h11v9H3zM14 10h4l3 3v3h-7\" />\n      <circle cx=\"7\" cy=\"17.5\" r=\"1.8\" />\n      <circle cx=\"17.5\" cy=\"17.5\" r=\"1.8\" />\n    </svg>\n  );\n}\n\nfunction Timeline({ option, start, p }: { option: ShipOption; start: Date; p: Palette }) {\n  const reduce = useReducedMotion();\n  const ship = option.id === \"pickup\" ? start : addBusinessDays(start, option.days[0] > 1 ? 1 : 0);\n  const steps =\n    option.id === \"pickup\"\n      ? [\n          { k: \"Order today\", d: fmt(start) },\n          { k: \"Ready for pickup\", d: fmt(addBusinessDays(start, 1)) },\n        ]\n      : [\n          { k: \"Order today\", d: fmt(start) },\n          { k: \"Ships\", d: fmt(ship) },\n          { k: \"Arrives\", d: option.days[0] === option.days[1] ? fmt(addBusinessDays(start, option.days[0])) : `${fmt(addBusinessDays(start, option.days[0]))} – ${fmt(addBusinessDays(start, option.days[1]))}` },\n        ];\n  return (\n    <ol className=\"relative mt-1\">\n      <span className=\"absolute top-2 bottom-2 left-[7px] w-0.5 rounded-full\" style={{ background: p.line }} aria-hidden=\"true\" />\n      <motion.span\n        key={option.id}\n        className=\"absolute top-2 left-[7px] w-0.5 origin-top rounded-full\"\n        style={{ background: p.accent, height: \"calc(100% - 16px)\" }}\n        initial={reduce ? false : { scaleY: 0 }}\n        animate={{ scaleY: 1 }}\n        transition={{ duration: 0.7, ease: [0.22, 1, 0.36, 1] }}\n        aria-hidden=\"true\"\n      />\n      {steps.map((s, i) => (\n        <motion.li key={option.id + s.k} className=\"relative flex gap-3 pb-4 last:pb-0\" initial={reduce ? false : { opacity: 0, x: -6 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: reduce ? 0 : 0.15 + i * 0.22 }}>\n          <span className=\"relative mt-0.5 grid size-4 shrink-0 place-items-center rounded-full\" style={{ background: i === steps.length - 1 ? p.accent : p.card, boxShadow: `0 0 0 2px ${p.accent}` }} aria-hidden=\"true\" />\n          <span className=\"min-w-0\">\n            <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n              {s.k}\n            </span>\n            <span className=\"block text-[14px] font-medium\" style={{ color: p.title }}>\n              {s.d}\n            </span>\n          </span>\n        </motion.li>\n      ))}\n    </ol>\n  );\n}\n\nexport function ShippingEstimator({ countries = COUNTRIES, subtotal = 42, freeOver = 50, currency = \"$\", store = STORE, onSelect, theme = \"dark\", className }: ShippingEstimatorProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [code, setCode] = React.useState(countries[0].code);\n  const [postal, setPostal] = React.useState(\"\");\n  const [tried, setTried] = React.useState(false);\n  const [loading, setLoading] = React.useState(false);\n  const [result, setResult] = React.useState<{ country: ShipCountry; postal: string; remote: boolean; start: Date } | null>(null);\n  const [choice, setChoice] = React.useState(\"standard\");\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const country = countries.find((c) => c.code === code) ?? countries[0];\n  const clean = postal.trim().toUpperCase();\n  const valid = country.pattern.test(clean);\n  const err = tried && !valid ? `Enter a valid ${country.postalLabel}, like ${country.placeholder}.` : \"\";\n  const free = subtotal >= freeOver;\n  const toFree = Math.max(0, freeOver - subtotal);\n\n  const options: ShipOption[] = React.useMemo(() => {\n    if (!result) return [];\n    const c = result.country;\n    const surcharge = result.remote ? 15 : 0;\n    const list: ShipOption[] = [\n      { id: \"standard\", label: \"Standard\", price: (free ? 0 : 6.95) + surcharge, days: [c.standard[0] + (result.remote ? 2 : 0), c.standard[1] + (result.remote ? 3 : 0)], note: free ? \"Free over \" + `${currency}${freeOver}` : undefined },\n    ];\n    if (c.express) list.push({ id: \"express\", label: \"Express\", price: c.expressPrice + surcharge, days: c.express });\n    if (c.nextDay && !result.remote) list.push({ id: \"next\", label: \"Next day\", price: c.expressPrice * 2, days: [1, 1], note: \"Order by 2 pm\" });\n    if (c.code === \"US\") list.push({ id: \"pickup\", label: \"Pick up in store\", price: 0, days: [1, 1], note: store.name });\n    return list;\n  }, [result, free, currency, freeOver, store.name]);\n  const chosen = options.find((o) => o.id === choice) ?? options[0];\n\n  const estimate = (e: React.FormEvent) => {\n    e.preventDefault();\n    setTried(true);\n    if (!valid) {\n      inputRef.current?.focus();\n      return;\n    }\n    setLoading(true);\n    const remote = !!country.remote?.some((r) => clean.startsWith(r));\n    // Dates are only computed after a click, in the browser, so server and client renders never disagree.\n    setTimeout(\n      () => {\n        setResult({ country, postal: clean, remote, start: new Date() });\n        setChoice(\"standard\");\n        setLoading(false);\n      },\n      reduce ? 0 : 650,\n    );\n  };\n  const pick = (o: ShipOption) => {\n    setChoice(o.id);\n    if (result) onSelect?.(o, { country: result.country.code, postal: result.postal });\n  };\n\n  return (\n    <section className={cn(\"w-full px-4 py-12 sm:px-8 sm:py-16\", className)} style={{ background: p.bg, color: p.body, colorScheme: p.scheme }}>\n      <div className=\"mx-auto w-full max-w-[920px]\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"text-[26px] font-semibold tracking-tight sm:text-[30px]\" style={{ color: p.title }}>\n              Shipping & delivery\n            </h2>\n            <p className=\"mt-1 text-[14px]\">See costs and delivery dates before you check out.</p>\n          </div>\n        </div>\n\n        {/* Free shipping progress */}\n        <div className=\"mt-6 rounded-2xl border px-4 py-3.5\" style={{ borderColor: p.line, background: p.card }}>\n          <p className=\"text-[13px]\" aria-live=\"polite\">\n            {free ? (\n              <span style={{ color: p.accent }}>Your order ships free with Standard delivery.</span>\n            ) : (\n              <>\n                Add <span style={{ color: p.title }}>{`${currency}${toFree.toFixed(2)}`}</span> more for free Standard shipping.\n              </>\n            )}\n          </p>\n          <div className=\"mt-2 h-1.5 overflow-hidden rounded-full\" style={{ background: p.ghost }} aria-hidden=\"true\">\n            <motion.div className=\"h-full rounded-full\" style={{ background: p.accent }} initial={reduce ? false : { width: 0 }} animate={{ width: `${Math.min(100, (subtotal / freeOver) * 100)}%` }} transition={{ duration: 0.8, ease: [0.22, 1, 0.36, 1] }} />\n          </div>\n        </div>\n\n        <div className=\"mt-4 grid gap-4 md:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]\">\n          <div className=\"min-w-0 rounded-2xl border p-4 sm:p-5\" style={{ borderColor: p.line, background: p.card }}>\n            <form noValidate onSubmit={estimate} className=\"grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] sm:items-end\">\n              <div className=\"min-w-0\">\n                <label htmlFor={`${uid}-country`} className=\"mb-1.5 block text-[12px]\" style={{ color: p.muted }}>\n                  Country\n                </label>\n                <div className=\"relative\">\n                  <select\n                    id={`${uid}-country`}\n                    value={code}\n                    onChange={(e) => (setCode(e.target.value), setTried(false), setResult(null))}\n                    className=\"h-11 w-full appearance-none rounded-xl border pr-9 pl-3.5 text-[14px] outline-none focus:border-current\"\n                    style={{ background: p.field, color: p.title, borderColor: p.line }}\n                  >\n                    {countries.map((c) => (\n                      <option key={c.code} value={c.code}>\n                        {c.name}\n                      </option>\n                    ))}\n                  </select>\n                  <svg className=\"pointer-events-none absolute top-1/2 right-3 -translate-y-1/2\" width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.muted} strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    <path d=\"m6 9 6 6 6-6\" />\n                  </svg>\n                </div>\n              </div>\n              <div className=\"min-w-0\">\n                <label htmlFor={`${uid}-postal`} className=\"mb-1.5 block text-[12px]\" style={{ color: p.muted }}>\n                  {country.postalLabel}\n                </label>\n                <input\n                  ref={inputRef}\n                  id={`${uid}-postal`}\n                  value={postal}\n                  onChange={(e) => setPostal(e.target.value)}\n                  placeholder={country.placeholder}\n                  autoComplete=\"postal-code\"\n                  aria-invalid={!!err}\n                  aria-describedby={err ? `${uid}-err` : undefined}\n                  className=\"h-11 w-full rounded-xl border px-3.5 text-[14px] uppercase outline-none placeholder:normal-case placeholder:opacity-60 focus:border-current\"\n                  style={{ background: p.field, color: p.title, borderColor: err ? p.error : p.line }}\n                />\n              </div>\n              <button type=\"submit\" disabled={loading} className=\"inline-flex h-11 items-center justify-center gap-2 rounded-full px-5 text-[14px] font-semibold disabled:opacity-80\" style={{ background: p.buttonBg, color: p.buttonText }}>\n                {loading ? <motion.span className=\"size-4 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: \"linear\" }} aria-hidden=\"true\" /> : null}\n                {loading ? \"Checking…\" : result ? \"Update\" : \"Estimate\"}\n              </button>\n            </form>\n            <AnimatePresence initial={false}>\n              {err ? (\n                <motion.p id={`${uid}-err`} initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} className=\"overflow-hidden text-[12px]\" style={{ color: p.error }}>\n                  <span className=\"block pt-2\">{err}</span>\n                </motion.p>\n              ) : null}\n            </AnimatePresence>\n\n            <AnimatePresence mode=\"wait\" initial={false}>\n              {result ? (\n                <motion.div key={result.country.code + result.postal} initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -6 }} transition={{ duration: 0.25 }} className=\"mt-4\">\n                  <p className=\"mb-2.5 text-[12px]\" style={{ color: p.muted }}>\n                    Shipping to <span style={{ color: p.title }}>{result.postal}</span>, {result.country.name}\n                    {result.remote ? <span style={{ color: p.amber }}> · remote area, +{currency}15 and a little longer</span> : null}\n                  </p>\n                  <LayoutGroup id={`${uid}-opts`}>\n                    <div role=\"radiogroup\" aria-label=\"Delivery options\" className=\"flex flex-col gap-2\">\n                      {options.map((o, i) => {\n                        const on = chosen?.id === o.id;\n                        const days = o.days[0] === o.days[1] ? (o.id === \"pickup\" ? \"Ready tomorrow\" : \"Tomorrow\") : `${o.days[0]}–${o.days[1]} business days`;\n                        return (\n                          <motion.button\n                            key={o.id}\n                            type=\"button\"\n                            role=\"radio\"\n                            aria-checked={on}\n                            onClick={() => pick(o)}\n                            initial={reduce ? false : { opacity: 0, y: 8 }}\n                            animate={{ opacity: 1, y: 0 }}\n                            transition={{ delay: reduce ? 0 : i * 0.06 }}\n                            className=\"relative flex items-center gap-3 rounded-xl border px-3.5 py-3 text-left\"\n                            style={{ borderColor: on ? p.accent : p.line }}\n                          >\n                            {on ? <motion.span layoutId=\"opt-bg\" className=\"absolute inset-0 rounded-xl\" style={{ background: p.accentSoft }} transition={{ type: \"spring\", stiffness: 500, damping: 40 }} /> : null}\n                            <span className=\"relative grid size-9 shrink-0 place-items-center rounded-full\" style={{ background: p.ghost, color: on ? p.accent : p.title }}>\n                              <Icon id={o.id} />\n                            </span>\n                            <span className=\"relative min-w-0 flex-1\">\n                              <span className=\"block text-[14px] font-medium\" style={{ color: p.title }}>\n                                {o.label}\n                              </span>\n                              <span className=\"block truncate text-[12px]\" style={{ color: p.muted }}>\n                                {days}\n                                {o.note ? ` · ${o.note}` : \"\"}\n                              </span>\n                            </span>\n                            <span className=\"relative text-[14px] font-semibold tabular-nums\" style={{ color: o.price === 0 ? p.accent : p.title }}>\n                              {money(o.price, currency)}\n                            </span>\n                          </motion.button>\n                        );\n                      })}\n                    </div>\n                  </LayoutGroup>\n                </motion.div>\n              ) : (\n                <motion.p key=\"hint\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} className=\"mt-4 text-[13px]\">\n                  We ship to {countries.length} countries. Remote areas may take a little longer.\n                </motion.p>\n              )}\n            </AnimatePresence>\n          </div>\n\n          {/* Summary */}\n          <div className=\"min-w-0 rounded-2xl border p-4 sm:p-5\" style={{ borderColor: p.line, background: p.card }} aria-live=\"polite\">\n            <p className=\"text-[12px] font-medium tracking-[0.14em] uppercase\" style={{ color: p.muted }}>\n              Delivery estimate\n            </p>\n            <AnimatePresence mode=\"wait\" initial={false}>\n              {result && chosen ? (\n                <motion.div key={chosen.id + result.postal} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.2 }} className=\"mt-3\">\n                  <div className=\"mb-4 flex items-baseline justify-between gap-3\">\n                    <span className=\"text-[18px] font-semibold\" style={{ color: p.title }}>\n                      {chosen.label}\n                    </span>\n                    <span className=\"text-[18px] font-semibold tabular-nums\" style={{ color: chosen.price === 0 ? p.accent : p.title }}>\n                      {money(chosen.price, currency)}\n                    </span>\n                  </div>\n                  <Timeline option={chosen} start={result.start} p={p} />\n                  {chosen.id === \"pickup\" ? (\n                    <p className=\"mt-4 rounded-xl px-3 py-2.5 text-[12px] leading-relaxed\" style={{ background: p.ghost }}>\n                      {store.name}, {store.address}. Bring your order email and an ID.\n                    </p>\n                  ) : (\n                    <p className=\"mt-4 text-[12px] leading-relaxed\" style={{ color: p.muted }}>\n                      Estimates exclude weekends and public holidays. You’ll get tracking as soon as your order ships.\n                    </p>\n                  )}\n                </motion.div>\n              ) : (\n                <motion.div key=\"empty\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} className=\"mt-3 flex flex-col items-start gap-3\">\n                  <span className=\"grid size-10 place-items-center rounded-full\" style={{ background: p.ghost, color: p.title }}>\n                    <Icon id=\"standard\" />\n                  </span>\n                  <p className=\"text-[14px] leading-relaxed\">Enter your {country.postalLabel} to see delivery dates for every option.</p>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default ShippingEstimator;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}