{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "smart-app-banner",
  "title": "Smart App Banner",
  "description": "An app install bar for mobile visitors: icon, rating and an Open button that links to the right store for their device, and it stays away once closed.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/smart-app-banner/smart-app-banner.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SmartAppBannerProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  theme?: \"dark\" | \"light\";\n  name?: string;\n  /** Second line, usually the maker. */\n  publisher?: string;\n  /** Out of five. Pass null to hide the stars. */\n  rating?: number | null;\n  /** Number of ratings beside the stars. */\n  reviews?: string;\n  /** App icon. Leave it out for a simple drawn one. */\n  icon?: string;\n  iosUrl?: string;\n  androidUrl?: string;\n  /** Used when the platform isn't iOS or Android. */\n  fallbackUrl?: string;\n  /** Force a platform instead of reading the browser. */\n  platform?: \"ios\" | \"android\" | \"other\";\n  actionLabel?: string;\n  /** Days to stay away after being closed. 0 never remembers. */\n  rememberDays?: number;\n  /** Key used to remember that it was closed. */\n  storageKey?: string;\n  onDismiss?: () => void;\n}\n\nconst PALETTES = {\n  dark: {\n    bar: \"#0F1011\",\n    surface: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.06)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 32px rgba(0,0,0,0.45)\",\n  },\n  light: {\n    bar: \"#FFFFFF\",\n    surface: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 28px rgba(8,9,10,0.12)\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\n\nfunction CloseButton({\n  label,\n  pal,\n  onClick,\n}: {\n  label: string;\n  pal: Palette;\n  onClick: () => void;\n}) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      onClick={onClick}\n      className=\"grid size-7 shrink-0 cursor-pointer place-items-center rounded-full transition-colors outline-none hover:bg-[var(--chip)] focus-visible:ring-2\"\n      style={{ \"--chip\": pal.chip, color: pal.sub } as React.CSSProperties}\n    >\n      <svg\n        width=\"10\"\n        height=\"10\"\n        viewBox=\"0 0 10 10\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.6\"\n        strokeLinecap=\"round\"\n        aria-hidden=\"true\"\n      >\n        <path d=\"m1 1 8 8M9 1 1 9\" />\n      </svg>\n    </button>\n  );\n}\n\n/** Folds its content away when closed, so a dismissed bar doesn't leave a gap. */\nfunction Collapse({\n  open,\n  onGone,\n  children,\n}: {\n  open: boolean;\n  onGone?: () => void;\n  children: React.ReactNode;\n}) {\n  return (\n    <div\n      className=\"grid motion-safe:transition-[grid-template-rows,opacity] motion-safe:duration-300\"\n      style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", opacity: open ? 1 : 0 }}\n      onTransitionEnd={(e) => {\n        if (!open && e.propertyName === \"grid-template-rows\") onGone?.();\n      }}\n    >\n      <div className=\"min-h-0 overflow-hidden\">{children}</div>\n    </div>\n  );\n}\n\nconst DAY = 86400000;\n\nfunction detect(): \"ios\" | \"android\" | \"other\" {\n  const agent = navigator.userAgent;\n  if (/iPad|iPhone|iPod/.test(agent)) return \"ios\";\n  if (/Android/.test(agent)) return \"android\";\n  return \"other\";\n}\n\nconst STORE = {\n  ios: \"Free on the App Store\",\n  android: \"Free on Google Play\",\n  other: \"Free for iPhone and Android\",\n};\n\nfunction Stars({ value, color }: { value: number; color: string }) {\n  return (\n    <span\n      className=\"relative inline-block text-[11px] leading-none tracking-[1px]\"\n      aria-label={`Rated ${value} out of 5`}\n      role=\"img\"\n    >\n      <span aria-hidden=\"true\" style={{ color, opacity: 0.28 }}>\n        ★★★★★\n      </span>\n      <span\n        aria-hidden=\"true\"\n        className=\"absolute inset-y-0 left-0 overflow-hidden whitespace-nowrap\"\n        style={{ width: `${(value / 5) * 100}%`, color }}\n      >\n        ★★★★★\n      </span>\n    </span>\n  );\n}\n\nexport function SmartAppBanner({\n  theme = \"dark\",\n  name = \"Tempo\",\n  publisher = \"Tempo Labs\",\n  rating = 4.8,\n  reviews = \"12k\",\n  icon,\n  iosUrl = \"#\",\n  androidUrl = \"#\",\n  fallbackUrl = \"#\",\n  platform,\n  actionLabel = \"Open\",\n  rememberDays = 14,\n  storageKey = \"smart-app-banner\",\n  onDismiss,\n  className,\n  style,\n  ...props\n}: SmartAppBannerProps) {\n  const pal = PALETTES[theme];\n  // Closed until checked: the platform and any earlier dismissal are only known in the browser.\n  const [open, setOpen] = React.useState(false);\n  const [device, setDevice] = React.useState<\"ios\" | \"android\" | \"other\">(\n    platform ?? \"other\",\n  );\n\n  React.useEffect(() => {\n    const frame = requestAnimationFrame(() => {\n      setDevice(platform ?? detect());\n      let until = 0;\n      try {\n        until = Number(window.localStorage.getItem(storageKey)) || 0;\n      } catch {\n        // Private windows can block storage, so the banner just shows.\n      }\n      setOpen(!rememberDays || Date.now() > until);\n    });\n    return () => cancelAnimationFrame(frame);\n  }, [platform, storageKey, rememberDays]);\n\n  const close = () => {\n    setOpen(false);\n    if (!rememberDays) return;\n    try {\n      window.localStorage.setItem(\n        storageKey,\n        String(Date.now() + rememberDays * DAY),\n      );\n    } catch {\n      // Nothing to do: it will simply show again next time.\n    }\n  };\n\n  const href =\n    device === \"ios\" ? iosUrl : device === \"android\" ? androidUrl : fallbackUrl;\n\n  return (\n    <Collapse open={open} onGone={onDismiss}>\n      <div\n        role=\"region\"\n        aria-label={`Get the ${name} app`}\n        className={`flex w-full items-center gap-3 px-3 py-2.5 ${className ?? \"\"}`}\n        style={{\n          background: pal.bar,\n          boxShadow: `inset 0 -1px 0 ${pal.border}`,\n          color: pal.text,\n          fontFamily: FONT,\n          ...style,\n        }}\n        {...props}\n      >\n        <CloseButton label=\"Close\" pal={pal} onClick={close} />\n        {icon ? (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img\n            src={icon}\n            alt=\"\"\n            className=\"size-12 shrink-0 rounded-[11px] object-cover\"\n          />\n        ) : (\n          <span\n            aria-hidden=\"true\"\n            className=\"grid size-12 shrink-0 place-items-center rounded-[11px] text-[22px] font-[590] text-white\"\n            style={{\n              background: \"linear-gradient(145deg,#7A84E0,#5E6AD2 55%,#3E47A8)\",\n            }}\n          >\n            {name.charAt(0)}\n          </span>\n        )}\n        <div className=\"min-w-0 flex-1\">\n          <p className=\"m-0 truncate text-[14px] leading-tight font-[590] tracking-[-0.011em]\">\n            {name}\n          </p>\n          <p\n            className=\"m-0 mt-0.5 truncate text-[12px] leading-tight\"\n            style={{ color: pal.sub }}\n          >\n            {publisher}\n          </p>\n          <p\n            className=\"m-0 mt-1 flex items-center gap-1.5 truncate text-[11px] leading-none\"\n            style={{ color: pal.sub }}\n          >\n            {rating !== null ? (\n              <>\n                <Stars value={rating} color={pal.soft} />\n                {reviews}\n              </>\n            ) : (\n              STORE[device]\n            )}\n          </p>\n        </div>\n        <a\n          href={href}\n          aria-label={`${actionLabel} ${name}, ${STORE[device]}`}\n          className=\"inline-flex h-8 shrink-0 items-center rounded-full px-4 text-[13px] font-[510] no-underline transition-opacity hover:opacity-90\"\n          style={{ background: pal.btn, color: pal.btnText }}\n        >\n          {actionLabel}\n        </a>\n      </div>\n    </Collapse>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}