{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"boarding-pass-call-to-action-that-tears-along-its-perforation-when-you-book-and-drops-the-stub","type":"registry:block","title":"Boarding Pass Call to Action That Tears along Its Perforation When You Book and Drops the Stub","description":"Call to action shaped as a boarding pass: press it or pull the stub and it rips along the perforation and drops. Copy the React code or the HTML free.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/boarding-pass-call-to-action-that-tears-along-its-perforation-when-you-book-and-drops-the-stub.tsx","type":"registry:component","content":"import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { MutableRefObject, PointerEvent as ReactPointerEvent } from \"react\";\nimport { AnimatePresence, animate, motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring, useTransform } from \"framer-motion\";\n\n/** The airline and the flights on offer. Each press books the one on show, the next press deals the next pass. */\nconst airline = \"Ostrel Air\";\nconst flights = [\n  {\n    number: \"OS 417\",\n    from: { code: \"PCW\", city: \"Port Callow\" },\n    to: { code: \"SEV\", city: \"Saint Elvary\" },\n    date: \"14 MAR\",\n    boards: \"09:40\",\n    gate: \"B12\",\n    seat: \"14A\",\n    fare: \"184\",\n    photo: { src: \"https://images.pexels.com/photos/8633909/pexels-photo-8633909.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Turquoise cove under orange sea cliffs seen from the air\", tone: \"#1c8f96\", focus: \"42% 60%\" },\n  },\n  {\n    number: \"OS 652\",\n    from: { code: \"SEV\", city: \"Saint Elvary\" },\n    to: { code: \"KSB\", city: \"Kossu Bay\" },\n    date: \"21 MAR\",\n    boards: \"16:05\",\n    gate: \"A3\",\n    seat: \"22F\",\n    fare: \"129\",\n    photo: { src: \"https://images.pexels.com/photos/15048076/pexels-photo-15048076.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"White surf breaking on pale cliffs above green water\", tone: \"#3f9c94\", focus: \"70% 60%\" },\n  },\n];\n\n// Design pixels. The pass is drawn at this size and the whole scene is scaled to fit.\nconst SCENE_W = 900;\nconst SCENE_H = 500;\nconst H = 264;\nconst MAIN_W = 478;\nconst STUB_W = 176;\nconst R = 16; // corner radius\nconst NOTCH = 12; // the half-moon bites where the perforation meets the edges\nconst HOLE = 2.3; // radius of each perforation\nconst PITCH = 9.5;\nconst OPEN = 17; // degrees the stub swings open before the last tooth lets go\nconst REST = { x: 26, y: 40, r: 8 }; // where the loose stub comes to rest, relative to where it hung\nconst INK = \"#14213f\";\nconst PAPER = \"#f6f3ec\";\n\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\n\n/** The two outlines. They share the same ragged teeth, so the halves mate exactly until they are torn apart. */\nfunction outlines() {\n  const ys: number[] = [];\n  for (let y = NOTCH + 8; y <= H - NOTCH - 8 + 0.01; y += PITCH) ys.push(y);\n  const jag = (i: number, k: number) => {\n    const n = Math.sin((i + 1) * 91.7 + k * 37.3) * 43758.5453;\n    return (n - Math.floor(n) - 0.5) * 2.1;\n  };\n  let down = \"\";\n  ys.forEach((y, i) => {\n    down += ` L ${MAIN_W} ${(y - HOLE).toFixed(2)} A ${HOLE} ${HOLE} 0 0 0 ${MAIN_W} ${(y + HOLE).toFixed(2)}`;\n    if (i < ys.length - 1) down += ` L ${(MAIN_W + jag(i, 1)).toFixed(2)} ${(y + PITCH * 0.4).toFixed(2)} L ${(MAIN_W + jag(i, 2)).toFixed(2)} ${(y + PITCH * 0.62).toFixed(2)}`;\n  });\n  let up = \"\";\n  [...ys].reverse().forEach((y, r) => {\n    const i = ys.length - 1 - r;\n    if (i < ys.length - 1) up += ` L ${jag(i, 2).toFixed(2)} ${(y + PITCH * 0.62).toFixed(2)} L ${jag(i, 1).toFixed(2)} ${(y + PITCH * 0.4).toFixed(2)}`;\n    up += ` L 0 ${(y + HOLE).toFixed(2)} A ${HOLE} ${HOLE} 0 0 0 0 ${(y - HOLE).toFixed(2)}`;\n  });\n  const main = `M ${R} 0 H ${MAIN_W - NOTCH} A ${NOTCH} ${NOTCH} 0 0 0 ${MAIN_W} ${NOTCH}${down} L ${MAIN_W} ${H - NOTCH} A ${NOTCH} ${NOTCH} 0 0 0 ${MAIN_W - NOTCH} ${H} H ${R} A ${R} ${R} 0 0 1 0 ${H - R} V ${R} A ${R} ${R} 0 0 1 ${R} 0 Z`;\n  const stub = `M ${NOTCH} 0 H ${STUB_W - R} A ${R} ${R} 0 0 1 ${STUB_W} ${R} V ${H - R} A ${R} ${R} 0 0 1 ${STUB_W - R} ${H} H ${NOTCH} A ${NOTCH} ${NOTCH} 0 0 0 0 ${H - NOTCH}${up} L 0 ${NOTCH} A ${NOTCH} ${NOTCH} 0 0 0 ${NOTCH} 0 Z`;\n  return { main, stub };\n}\n\nfunction bars(seed: number, count: number) {\n  const out: { x: number; w: number }[] = [];\n  let x = 0;\n  for (let i = 0; i < count; i++) {\n    const n = Math.sin((i + 1) * 12.9898 + seed * 78.233) * 43758.5453;\n    const f = n - Math.floor(n);\n    const w = f < 0.5 ? 1.2 : f < 0.82 ? 2.4 : 3.6;\n    if (i % 2 === 0) out.push({ x, w });\n    x += w;\n  }\n  return { list: out, total: x };\n}\n\nconst flecks = [\n  { y: 34, s: 3.2, dx: 16, dy: 22, spin: 140 },\n  { y: 78, s: 2.4, dx: 30, dy: 12, spin: -200 },\n  { y: 118, s: 3.6, dx: 12, dy: 40, spin: 90 },\n  { y: 150, s: 2.2, dx: 26, dy: 30, spin: 260 },\n  { y: 188, s: 3, dx: 9, dy: 26, spin: -120 },\n  { y: 222, s: 2.6, dx: 22, dy: 20, spin: 180 },\n];\nconst paperLight = \"linear-gradient(128deg, rgba(255,255,255,0.75) 0%, rgba(255,255,255,0) 32%, rgba(0,0,0,0) 62%, rgba(40,20,0,0.09) 100%)\";\nconst label = \"font-mono text-[8.5px] font-semibold uppercase leading-none tracking-[0.2em] text-[#5b6680]\";\n\ntype Flight = (typeof flights)[number];\ntype Api = { tear: () => void };\n\nfunction Plane({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className={className} fill=\"currentColor\">\n      <path d=\"M19 10c0 .8-.9 1.3-2 1.3h-4.2l-3.6 6.2H7.5l1.9-6.2H5.5l-1.4 1.9H2.8L3.6 10l-.8-3.2h1.3l1.4 1.9h3.9L7.5 2.5h1.7l3.6 6.2H17c1.1 0 2 .5 2 1.3z\" />\n    </svg>\n  );\n}\n\nfunction Pass({ flight, reduce, startTorn, torn, scale, api, onTorn, onPress }: { flight: Flight; reduce: boolean; startTorn: boolean; torn: boolean; scale: MutableRefObject<number>; api: MutableRefObject<Api | null>; onTorn: () => void; onPress: () => void }) {\n  const shapes = useMemo(outlines, []);\n  const code = useMemo(() => bars(flight.number.length + flight.seat.charCodeAt(0), 74), [flight]);\n  const done = useRef(startTorn);\n  const [burst, setBurst] = useState(false);\n  const drag = useRef({ on: false, x: 0, y: 0, moved: 0, sx: 0, sy: 0, loose: false });\n\n  const tear = useMotionValue(startTorn ? 1 : 0);\n  const sx = useMotionValue(startTorn ? REST.x : 0);\n  const sy = useMotionValue(startTorn ? REST.y : 0);\n  const sr = useMotionValue(startTorn ? REST.r - OPEN : 0);\n  const lift = useMotionValue(0);\n  const pull = useMotionValue(0);\n  const recoil = useSpring(pull, { stiffness: 320, damping: 9, mass: 0.7 });\n\n  const stubRot = useTransform([tear, sr], (v) => (v[0] as number) * OPEN + (v[1] as number));\n  const stubScale = useTransform(lift, (v) => 1 + v * 0.035);\n  const mainRot = useTransform(recoil, (v) => -v * 1.5);\n  const mainX = useTransform(recoil, (v) => -v * 4);\n  const shOx = useTransform(lift, (v) => 5 + v * 13);\n  const shOy = useTransform(lift, (v) => 9 + v * 20);\n  const shBl = useTransform(lift, (v) => 9 + v * 14);\n  const shA = useTransform(lift, (v) => 0.42 - v * 0.14);\n  const stubShadow = useMotionTemplate`drop-shadow(0 1px 0.5px rgba(70,20,0,0.5)) drop-shadow(${shOx}px ${shOy}px ${shBl}px rgba(84,22,0,${shA}))`;\n\n  const detach = useCallback(() => {\n    if (done.current) return;\n    done.current = true;\n    pull.set(0);\n    if (reduce) {\n      tear.set(1);\n      sx.set(REST.x);\n      sy.set(REST.y);\n      sr.set(REST.r - OPEN);\n      lift.set(0);\n    } else {\n      animate(sx, REST.x, { type: \"spring\", stiffness: 90, damping: 15, velocity: 120 });\n      animate(sy, REST.y, { type: \"spring\", stiffness: 80, damping: 12 });\n      animate(sr, REST.r - OPEN, { type: \"spring\", stiffness: 70, damping: 8, velocity: 60 });\n      animate(lift, [lift.get(), 1, 0], { duration: 0.62, times: [0, 0.35, 1], ease: \"easeInOut\" });\n      setBurst(true);\n    }\n    onTorn();\n  }, [lift, onTorn, pull, reduce, sr, sx, sy, tear]);\n\n  // while the stub is still attached, how far it has opened also lifts it and tugs the pass\n  useEffect(\n    () =>\n      tear.on(\"change\", (v) => {\n        if (done.current) return;\n        lift.set(Math.min(1, v * 1.5));\n        pull.set(v);\n      }),\n    [lift, pull, tear],\n  );\n\n  const run = useCallback(() => {\n    if (done.current) return;\n    if (reduce) return detach();\n    // the teeth let go in fits and starts, never in one smooth pull\n    const from = tear.get();\n    animate(tear, [from, 0.2, 0.16, 0.48, 0.43, 0.8, 0.76, 1].map((v) => Math.max(v, from)), { duration: 0.9, times: [0, 0.16, 0.22, 0.42, 0.5, 0.72, 0.8, 1], ease: \"easeInOut\" }).then(detach);\n  }, [detach, reduce, tear]);\n\n  useEffect(() => {\n    api.current = { tear: run };\n    return () => {\n      api.current = null;\n    };\n  }, [api, run]);\n\n  const onDown = (e: ReactPointerEvent<HTMLDivElement>) => {\n    if (e.button !== 0) return;\n    drag.current = { on: true, x: e.clientX, y: e.clientY, moved: 0, sx: sx.get(), sy: sy.get(), loose: done.current };\n    e.currentTarget.setPointerCapture(e.pointerId);\n  };\n  const onMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n    const d = drag.current;\n    if (!d.on) return;\n    const dx = (e.clientX - d.x) / scale.current;\n    const dy = (e.clientY - d.y) / scale.current;\n    d.moved = Math.max(d.moved, Math.hypot(dx, dy));\n    if (done.current) {\n      // once it is loose the stub is just a piece of paper you can push around the counter\n      if (d.moved < 5) return;\n      sx.set(clamp(d.sx + dx, -40, 150));\n      sy.set(clamp(d.sy + dy, -120, 130));\n      lift.set(0.6);\n      return;\n    }\n    const t = clamp(Math.max(dx, dx * 0.6 + dy * 0.6) / 120, 0, 1);\n    tear.set(t);\n    if (t >= 1) detach();\n  };\n  const onUp = () => {\n    const d = drag.current;\n    if (!d.on) return;\n    d.on = false;\n    if (d.moved < 5) return onPress();\n    if (d.loose) {\n      animate(lift, 0, { duration: 0.25 });\n      return;\n    }\n    if (done.current) return;\n    if (tear.get() > 0.5) run();\n    else animate(tear, 0, { type: \"spring\", stiffness: 260, damping: 18 });\n  };\n\n  return (\n    <motion.div\n      className=\"absolute\"\n      style={{ left: SCENE_W / 2 - (MAIN_W + STUB_W) / 2 - 16, top: SCENE_H / 2 - H / 2 - 14, width: MAIN_W + STUB_W, height: H }}\n      initial={reduce ? false : { opacity: 0, y: -70, rotate: -11, scale: 1.05 }}\n      animate={{ opacity: 1, y: 0, rotate: -5, scale: 1, transition: { type: \"spring\", stiffness: 170, damping: 17 } }}\n      exit={reduce ? { opacity: 0, transition: { duration: 0.01 } } : { opacity: 0, x: -150, y: 26, rotate: -13, transition: { duration: 0.36, ease: \"easeIn\" } }}\n    >\n      {/* the part the airline keeps */}\n      <motion.div className=\"absolute left-0 top-0\" style={{ width: MAIN_W + 4, height: H, rotate: mainRot, x: mainX, transformOrigin: \"0% 50%\", filter: \"drop-shadow(0 1px 0.5px rgba(70,20,0,0.5)) drop-shadow(5px 9px 9px rgba(84,22,0,0.42)) drop-shadow(14px 30px 34px rgba(84,22,0,0.28))\" }}>\n        <button\n          type=\"button\"\n          onClick={onPress}\n          aria-label={torn ? `Booked. Show the next ${airline} flight` : `Book seat ${flight.seat} on ${airline} ${flight.number} from ${flight.from.city} to ${flight.to.city}, from ${flight.fare} dollars`}\n          className=\"group absolute inset-0 block cursor-pointer text-left outline-none\"\n          style={{ clipPath: `path('${shapes.main}')`, background: PAPER, color: INK }}\n        >\n          {/* destination photograph, printed to the left edge */}\n          <span className=\"absolute inset-y-0 left-0 block w-[150px] overflow-hidden\" style={{ background: flight.photo.tone }}>\n            <img src={flight.photo.src} alt={flight.photo.alt} draggable={false} className=\"h-full w-full object-cover\" style={{ objectPosition: flight.photo.focus }} />\n            <span aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(180deg, rgba(8,20,45,0.5) 0%, rgba(8,20,45,0) 34%, rgba(8,20,45,0) 62%, rgba(8,20,45,0.55) 100%)\" }} />\n            <span className=\"absolute left-[16px] top-[15px] flex items-center gap-[7px] text-white\">\n              <span className=\"grid h-[20px] w-[20px] place-items-center rounded-full bg-white text-[#14213f]\">\n                <Plane className=\"h-[11px] w-[11px] -rotate-45\" />\n              </span>\n              <span className=\"text-[12.5px] font-extrabold uppercase leading-none tracking-[0.14em]\">{airline}</span>\n            </span>\n            <span className=\"absolute bottom-[15px] left-[16px] block text-white\">\n              <span className=\"block font-mono text-[8px] font-semibold uppercase leading-none tracking-[0.22em] text-white/80\">Flight</span>\n              <span className=\"mt-[5px] block text-[20px] font-black leading-none tracking-[-0.01em]\">{flight.number}</span>\n            </span>\n          </span>\n\n          {/* fine security rings, as on any printed ticket */}\n          <span aria-hidden=\"true\" className=\"absolute inset-y-0 left-[150px] right-0\" style={{ background: \"repeating-radial-gradient(circle at 104% -8%, rgba(20,33,63,0.06) 0 1px, rgba(20,33,63,0) 1px 7px)\" }} />\n\n          <span className=\"absolute left-[172px] right-[40px] top-[20px] flex items-center justify-between\">\n            <span className={label}>Boarding pass</span>\n            <span className={label}>Economy</span>\n          </span>\n\n          <span className=\"absolute left-[172px] right-[40px] top-[44px] flex items-end justify-between\">\n            <span className=\"block\">\n              <span className=\"block text-[50px] font-black leading-[0.86] tracking-[-0.035em]\">{flight.from.code}</span>\n              <span className=\"mt-[7px] block text-[10.5px] font-semibold leading-none text-[#3b4763]\">{flight.from.city}</span>\n            </span>\n            <span aria-hidden=\"true\" className=\"relative mb-[26px] block h-[22px] flex-1 px-[10px] text-[#e4572e]\">\n              <svg viewBox=\"0 0 100 22\" preserveAspectRatio=\"none\" className=\"absolute inset-x-[10px] top-0 h-full w-[calc(100%-20px)] overflow-visible\">\n                <path d=\"M0 19 Q50 -12 100 19\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeDasharray=\"2 4\" strokeLinecap=\"round\" vectorEffect=\"non-scaling-stroke\" />\n              </svg>\n              <Plane className=\"absolute left-1/2 top-[-6px] h-[17px] w-[17px] -translate-x-1/2\" />\n            </span>\n            <span className=\"block text-right\">\n              <span className=\"block text-[50px] font-black leading-[0.86] tracking-[-0.035em]\">{flight.to.code}</span>\n              <span className=\"mt-[7px] block text-[10.5px] font-semibold leading-none text-[#3b4763]\">{flight.to.city}</span>\n            </span>\n          </span>\n\n          <span className=\"absolute left-[172px] right-[40px] top-[136px] grid grid-cols-[1.35fr_1.2fr_1fr_0.8fr] gap-x-[8px] whitespace-nowrap border-t border-dashed border-[#14213f]/25 pt-[13px]\">\n            {[\n              [\"Date\", flight.date],\n              [\"Boards\", flight.boards],\n              [\"Gate\", flight.gate],\n              [\"Seat\", flight.seat],\n            ].map(([k, v]) => (\n              <span key={k} className=\"block\">\n                <span className={label}>{k}</span>\n                <span className=\"mt-[6px] block text-[17px] font-extrabold leading-none tracking-[-0.01em]\">{v}</span>\n              </span>\n            ))}\n          </span>\n\n          {/* the offer, printed where a gate agent would look */}\n          <span className=\"absolute bottom-[19px] left-[172px] right-[40px] flex items-center justify-between rounded-full py-[9px] pl-[15px] pr-[9px] text-white\" style={{ background: INK }}>\n            <span className=\"text-[11.5px] font-bold leading-none tracking-[0.01em]\">{torn ? `Booked. Seat ${flight.seat} is yours` : `Tear the stub to book, from $${flight.fare}`}</span>\n            <span className=\"grid h-[22px] w-[22px] place-items-center rounded-full bg-[#e4572e]\">\n              <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className=\"h-[12px] w-[12px]\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                {torn ? <path d=\"M4.5 10.5l3.6 3.6 7.4-8\" /> : <path d=\"M4 10h11M11 5.5l4.5 4.5-4.5 4.5\" />}\n              </svg>\n            </span>\n          </span>\n\n          {/* foil strip beside the perforation */}\n          <span aria-hidden=\"true\" className=\"boarding-pass-tear-foil absolute bottom-[19px] right-[15px] top-[20px] w-[9px] rounded-[2px]\" />\n\n          <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 h-full w-full opacity-60 mix-blend-multiply\"><rect width=\"100%\" height=\"100%\" filter=\"url(#boarding-pass-tear-fibre)\" /></svg>\n          <span aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: paperLight, boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1.5px 0 rgba(60,30,0,0.2)\" }} />\n          <span aria-hidden=\"true\" className=\"absolute inset-y-0 right-0 w-[26px]\" style={{ background: \"linear-gradient(270deg, rgba(60,30,0,0.1), rgba(60,30,0,0) 40%, rgba(255,255,255,0.5) 75%, rgba(255,255,255,0))\" }} />\n          <span aria-hidden=\"true\" className=\"absolute inset-[5px] rounded-[12px] opacity-0 ring-[3px] ring-[#14213f] group-focus-visible:opacity-100\" />\n        </button>\n      </motion.div>\n\n      {/* crumbs of paper shaken out of the perforation as it gives */}\n      {burst &&\n        flecks.map((f, i) => (\n          <motion.span\n            key={i}\n            aria-hidden=\"true\"\n            className=\"absolute block rounded-[1px]\"\n            style={{ left: MAIN_W + 2, top: f.y, width: f.s, height: f.s * 0.7, background: PAPER, boxShadow: \"0 1px 1px rgba(70,20,0,0.45)\" }}\n            initial={{ x: 0, y: 0, rotate: 0, opacity: 1 }}\n            animate={{ x: f.dx, y: f.dy, rotate: f.spin, opacity: [1, 1, 0] }}\n            transition={{ duration: 0.75, ease: \"easeOut\", opacity: { duration: 1.5, times: [0, 0.7, 1] } }}\n          />\n        ))}\n\n      {/* the stub you keep */}\n      <motion.div\n        onPointerDown={onDown}\n        onPointerMove={onMove}\n        onPointerUp={onUp}\n        onPointerCancel={onUp}\n        className=\"absolute top-0 cursor-grab touch-none active:cursor-grabbing\"\n        style={{ left: MAIN_W, width: STUB_W, height: H, x: sx, y: sy, rotate: stubRot, scale: stubScale, transformOrigin: `0px ${H - NOTCH}px`, filter: stubShadow }}\n      >\n        <div className=\"absolute inset-0\" style={{ clipPath: `path('${shapes.stub}')`, background: PAPER, color: INK }}>\n          <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"repeating-radial-gradient(circle at -10% 108%, rgba(20,33,63,0.06) 0 1px, rgba(20,33,63,0) 1px 7px)\" }} />\n          <div className=\"absolute left-[24px] right-[18px] top-[20px] flex items-center justify-between\">\n            <span className={label}>Your stub</span>\n            <span className={label}>{flight.number}</span>\n          </div>\n          <div className=\"absolute left-[24px] right-[18px] top-[44px]\">\n            <div className=\"flex items-center gap-[6px] text-[25px] font-black leading-none tracking-[-0.03em]\">\n              <span>{flight.from.code}</span>\n              <Plane className=\"h-[13px] w-[13px] text-[#e4572e]\" />\n              <span>{flight.to.code}</span>\n            </div>\n            <div className=\"mt-[15px] grid grid-cols-2 gap-x-[8px] gap-y-[11px]\">\n              {[\n                [\"Seat\", flight.seat],\n                [\"Gate\", flight.gate],\n                [\"Boards\", flight.boards],\n                [\"Date\", flight.date],\n              ].map(([k, v]) => (\n                <div key={k}>\n                  <div className={label}>{k}</div>\n                  <div className=\"mt-[5px] text-[14px] font-extrabold leading-none\">{v}</div>\n                </div>\n              ))}\n            </div>\n          </div>\n          <div aria-hidden=\"true\" className=\"absolute bottom-[32px] left-[24px] right-[18px] h-[40px] overflow-hidden\">\n            <svg viewBox={`0 0 ${code.total} 40`} preserveAspectRatio=\"none\" className=\"h-full w-full\">\n              {code.list.map((b, i) => (\n                <rect key={i} x={b.x} y={0} width={b.w} height={40} fill={INK} />\n              ))}\n            </svg>\n          </div>\n          <div className=\"absolute bottom-[17px] left-[24px] right-[18px] flex justify-between font-mono text-[7.5px] font-semibold uppercase leading-none tracking-[0.24em] text-[#5b6680]\">\n            <span>{flight.number.replace(\" \", \"\")}</span>\n            <span>{flight.seat}</span>\n            <span>{flight.gate}</span>\n          </div>\n          <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 h-full w-full opacity-60 mix-blend-multiply\"><rect width=\"100%\" height=\"100%\" filter=\"url(#boarding-pass-tear-fibre)\" /></svg>\n          <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: paperLight, boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1.5px 0 rgba(60,30,0,0.2)\" }} />\n          <div aria-hidden=\"true\" className=\"absolute inset-y-0 left-0 w-[22px]\" style={{ background: \"linear-gradient(90deg, rgba(255,255,255,0.75), rgba(255,255,255,0) 45%, rgba(60,30,0,0.06) 70%, rgba(60,30,0,0))\" }} />\n        </div>\n      </motion.div>\n    </motion.div>\n  );\n}\n\nexport default function BoardingPassTearCallToAction() {\n  const reduce = !!useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const sceneRef = useRef<HTMLDivElement>(null);\n  const scale = useRef(1);\n  const api = useRef<Api | null>(null);\n  const live = useRef({ touched: false, paused: false, clock: 0, torn: false });\n  const [idx, setIdx] = useState(0);\n  const [torn, setTorn] = useState(false);\n  useEffect(() => {\n    if (!reduce) return;\n    live.current.torn = true;\n    setTorn(true);\n  }, [reduce]);\n  const flight = flights[idx % flights.length];\n\n  const px = useMotionValue(0);\n  const py = useMotionValue(0);\n  const tiltY = useSpring(useTransform(px, (v) => v * 7), { stiffness: 70, damping: 15 });\n  const tiltX = useSpring(useTransform(py, (v) => -v * 6), { stiffness: 70, damping: 15 });\n\n  const onTorn = useCallback(() => {\n    live.current.torn = true;\n    live.current.clock = 0;\n    setTorn(true);\n  }, []);\n  const next = useCallback(() => {\n    live.current.torn = false;\n    live.current.clock = 0;\n    setTorn(false);\n    setIdx((i) => i + 1);\n  }, []);\n  const press = useCallback(() => {\n    live.current.touched = true;\n    if (live.current.torn) next();\n    else api.current?.tear();\n  }, [next]);\n\n  // the demo: tear the pass shortly after it lands, admire it, deal the next one\n  useEffect(() => {\n    if (reduce) return;\n    const s = live.current;\n    const tick = window.setInterval(() => {\n      if (s.touched || s.paused || document.hidden) return;\n      s.clock += 100;\n      if (!s.torn && s.clock === 800) api.current?.tear();\n      if (s.torn && s.clock >= 3600) next();\n    }, 100);\n    return () => window.clearInterval(tick);\n  }, [next, reduce]);\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    const scene = sceneRef.current;\n    if (!wrap || !scene) return;\n    const measure = () => {\n      const sc = clamp(wrap.clientWidth / (SCENE_W - 170), 0.4, 1.3);\n      scale.current = sc;\n      wrap.style.height = `${Math.round(Math.max(SCENE_H * sc, 360) + 56)}px`;\n      scene.style.transform = `translate(-50%, -50%) scale(${sc.toFixed(4)})`;\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(wrap);\n    return () => ro.disconnect();\n  }, []);\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#e4572e]\">\n      <style>{`\n        .boarding-pass-tear-foil { background: linear-gradient(180deg, #ffd9a8, #ff9fd0 16%, #9fd8ff 34%, #b6ffd9 50%, #fff3a6 66%, #ffa9c4 82%, #a9c8ff); background-size: 100% 260%; box-shadow: inset 0 0 0 0.5px rgba(20,33,63,0.35), inset 2px 0 1px rgba(255,255,255,0.7); animation: boarding-pass-tear-foil 5s ease-in-out infinite alternate; }\n        @keyframes boarding-pass-tear-foil { from { background-position: 0 0; } to { background-position: 0 100%; } }\n        @media (prefers-reduced-motion: reduce) { .boarding-pass-tear-foil { animation: none; } }\n      `}</style>\n      <svg aria-hidden=\"true\" width=\"0\" height=\"0\" className=\"absolute\">\n        <filter id=\"boarding-pass-tear-fibre\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n          <feTurbulence type=\"fractalNoise\" baseFrequency=\"0.9 0.55\" numOctaves=\"3\" seed=\"7\" />\n          <feColorMatrix type=\"matrix\" values=\"0 0 0 0 0.36  0 0 0 0 0.29  0 0 0 0 0.2  0.85 0 0 0 -0.3\" />\n        </filter>\n      </svg>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"radial-gradient(70% 66% at 42% 36%, #f47a4c 0%, #e4572e 48%, #c13f1b 100%)\" }} />\n      <div\n        ref={wrapRef}\n        onPointerMove={(e) => {\n          if (reduce || e.pointerType === \"touch\") return;\n          const r = e.currentTarget.getBoundingClientRect();\n          px.set(((e.clientX - r.left) / r.width) * 2 - 1);\n          py.set(((e.clientY - r.top) / r.height) * 2 - 1);\n        }}\n        onPointerEnter={() => (live.current.paused = true)}\n        onPointerLeave={() => {\n          live.current.paused = false;\n          px.set(0);\n          py.set(0);\n        }}\n        className=\"relative mx-auto w-full overflow-hidden\"\n        style={{ height: SCENE_H * 1.3 + 56 }}\n      >\n        <div ref={sceneRef} className=\"absolute left-1/2 top-[47%] select-none\" style={{ width: SCENE_W, height: SCENE_H, transform: \"translate(-50%, -50%)\", perspective: \"1500px\" }}>\n          <motion.div className=\"absolute inset-0\" style={{ rotateX: tiltX, rotateY: tiltY }}>\n            <AnimatePresence initial={!reduce}>\n              <Pass key={idx} flight={flight} reduce={reduce} startTorn={reduce && idx === 0} torn={torn} scale={scale} api={api} onTorn={onTorn} onPress={press} />\n            </AnimatePresence>\n          </motion.div>\n        </div>\n\n        <p className=\"absolute bottom-5 left-5 font-mono text-[11px] uppercase leading-relaxed tracking-[0.18em] text-[#3a0f00] sm:bottom-8 sm:left-8\">\n          <span className=\"font-semibold text-white\">\n            {airline} {flight.number}\n          </span>\n          <span className=\"block\">{torn ? \"Stub is yours. Press for the next flight\" : \"Press the pass or pull the stub\"}</span>\n        </p>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {torn ? `Booked: seat ${flight.seat}, ${flight.from.city} to ${flight.to.city}.` : \"\"}\n        </p>\n      </div>\n    </section>\n  );\n}\n"}]}
