{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "connectors",
  "type": "registry:block",
  "title": "Connectors",
  "description": "Browse every app your product plugs into, grouped by category in tidy two-up cards, with a sticky search, filters that glide, connect buttons that spin and settle into a quiet connected state, and a slide-over for permissions and settings.",
  "categories": [
    "screen",
    "Product"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/badge.json",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input.json",
    "https://coss.com/ui/r/kbd.json",
    "https://coss.com/ui/r/menu.json",
    "https://coss.com/ui/r/select.json",
    "https://coss.com/ui/r/spinner.json",
    "https://coss.com/ui/r/switch.json"
  ],
  "files": [
    {
      "path": "registry/devl/connectors.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ActivityIcon,\n  BugIcon,\n  CheckIcon,\n  CircleAlertIcon,\n  DatabaseIcon,\n  EllipsisIcon,\n  FileTextIcon,\n  GitBranchIcon,\n  type LucideIcon,\n  LifeBuoyIcon,\n  LayoutGridIcon,\n  MailIcon,\n  MegaphoneIcon,\n  MessagesSquareIcon,\n  PaletteIcon,\n  PenToolIcon,\n  PiggyBankIcon,\n  PlugIcon,\n  ReceiptIcon,\n  RocketIcon,\n  RotateCwIcon,\n  SearchIcon,\n  SearchXIcon,\n  Settings2Icon,\n  ShieldCheckIcon,\n  SparklesIcon,\n  TableIcon,\n  UnplugIcon,\n  VideoIcon,\n  XIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type KeyboardEvent, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from \"@/components/ui/menu\";\nimport { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { Spinner } from \"@/components/ui/spinner\";\nimport { Switch } from \"@/components/ui/switch\";\n\n// Stays false until mounted so the server render and the first client render match.\nfunction useSafeReducedMotion() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && !!prefers;\n}\n\nexport type AppTone = \"orange\" | \"teal\" | \"violet\" | \"amber\" | \"rose\" | \"info\" | \"success\" | \"warning\";\n\nexport interface ConnectorApp {\n  id: string;\n  name: string;\n  blurb: string;\n  description: string;\n  category: string;\n  icon: LucideIcon;\n  tone: AppTone;\n  tag?: \"Popular\" | \"New\" | \"Beta\";\n  installs: number;\n  addedDaysAgo: number;\n  connected?: boolean;\n  authError?: string;\n  permissions: string[];\n}\n\nconst toneClass: Record<AppTone, string> = {\n  orange: \"bg-orange-500/12 text-orange-700 dark:bg-orange-400/14 dark:text-orange-300\",\n  teal: \"bg-teal-500/12 text-teal-700 dark:bg-teal-400/14 dark:text-teal-300\",\n  violet: \"bg-violet-500/12 text-violet-700 dark:bg-violet-400/14 dark:text-violet-300\",\n  amber: \"bg-amber-500/12 text-amber-700 dark:bg-amber-400/14 dark:text-amber-300\",\n  rose: \"bg-rose-500/12 text-rose-700 dark:bg-rose-400/14 dark:text-rose-300\",\n  info: \"bg-info/12 text-info-foreground\",\n  success: \"bg-success/12 text-success-foreground\",\n  warning: \"bg-warning/14 text-warning-foreground\",\n};\n\nconst tagVariant = { Popular: \"info\", New: \"success\", Beta: \"warning\" } as const;\n\nconst defaultApps: ConnectorApp[] = [\n  {\n    id: \"relay\",\n    name: \"Relay\",\n    blurb: \"Team chat with threads and huddles.\",\n    description: \"Post agent summaries to channels, reply in threads and turn messages into tasks without leaving chat.\",\n    category: \"Communication\",\n    icon: MessagesSquareIcon,\n    tone: \"info\",\n    tag: \"Popular\",\n    installs: 48200,\n    addedDaysAgo: 400,\n    connected: true,\n    permissions: [\"Read public channels\", \"Post messages as the app\", \"Read user profiles\"],\n  },\n  {\n    id: \"postbox\",\n    name: \"Postbox\",\n    blurb: \"Shared inboxes for the whole team.\",\n    description: \"Triage shared inboxes, draft replies with your agents and sync labels both ways.\",\n    category: \"Communication\",\n    icon: MailIcon,\n    tone: \"orange\",\n    installs: 21900,\n    addedDaysAgo: 210,\n    permissions: [\"Read and label conversations\", \"Create drafts\", \"Send on your behalf\"],\n  },\n  {\n    id: \"huddle\",\n    name: \"Huddle\",\n    blurb: \"Video calls with live transcripts.\",\n    description: \"Pull transcripts into your workspace after every call and let agents write the follow-up.\",\n    category: \"Communication\",\n    icon: VideoIcon,\n    tone: \"rose\",\n    tag: \"New\",\n    installs: 3400,\n    addedDaysAgo: 9,\n    permissions: [\"Read meeting transcripts\", \"Read calendar events\"],\n  },\n  {\n    id: \"forge\",\n    name: \"Forge\",\n    blurb: \"Git hosting, reviews and pipelines.\",\n    description: \"Link pull requests to tasks, summarise diffs and post review checklists automatically.\",\n    category: \"Developer\",\n    icon: GitBranchIcon,\n    tone: \"violet\",\n    tag: \"Popular\",\n    installs: 39100,\n    addedDaysAgo: 520,\n    connected: true,\n    permissions: [\"Read repositories\", \"Comment on pull requests\", \"Read pipeline status\"],\n  },\n  {\n    id: \"tracer\",\n    name: \"Tracer\",\n    blurb: \"Error tracking that groups the noise.\",\n    description: \"Open an incident when a new error spikes and hand the stack trace to a debugging agent.\",\n    category: \"Developer\",\n    icon: BugIcon,\n    tone: \"rose\",\n    installs: 12800,\n    addedDaysAgo: 160,\n    permissions: [\"Read issues and events\", \"Resolve issues\"],\n  },\n  {\n    id: \"launchpad\",\n    name: \"Launchpad\",\n    blurb: \"Preview deploys for every branch.\",\n    description: \"Get a preview link on every branch and let agents check it before you merge.\",\n    category: \"Developer\",\n    icon: RocketIcon,\n    tone: \"teal\",\n    tag: \"Beta\",\n    installs: 1900,\n    addedDaysAgo: 21,\n    permissions: [\"Read deployments\", \"Trigger redeploys\"],\n  },\n  {\n    id: \"tally\",\n    name: \"Tally\",\n    blurb: \"Invoices that chase themselves.\",\n    description: \"Draft invoices from closed deals and send polite reminders when they slip past due.\",\n    category: \"Finance\",\n    icon: ReceiptIcon,\n    tone: \"success\",\n    installs: 8700,\n    addedDaysAgo: 300,\n    permissions: [\"Read customers\", \"Create and send invoices\"],\n  },\n  {\n    id: \"coffer\",\n    name: \"Coffer\",\n    blurb: \"Expense cards and receipt matching.\",\n    description: \"Match receipts to card spend and flag anything that breaks policy.\",\n    category: \"Finance\",\n    icon: PiggyBankIcon,\n    tone: \"amber\",\n    tag: \"New\",\n    installs: 2600,\n    addedDaysAgo: 14,\n    permissions: [\"Read transactions\", \"Upload receipts\"],\n  },\n  {\n    id: \"inkwell\",\n    name: \"Inkwell\",\n    blurb: \"Collaborative design files.\",\n    description: \"Attach frames to specs, collect feedback and export assets straight into tasks.\",\n    category: \"Design\",\n    icon: PenToolIcon,\n    tone: \"orange\",\n    tag: \"Popular\",\n    installs: 30500,\n    addedDaysAgo: 610,\n    permissions: [\"Read files and comments\", \"Export images\"],\n  },\n  {\n    id: \"swatch\",\n    name: \"Swatch\",\n    blurb: \"One home for brand assets.\",\n    description: \"Keep logos, colours and type in one place so agents always use the current brand.\",\n    category: \"Design\",\n    icon: PaletteIcon,\n    tone: \"amber\",\n    installs: 5200,\n    addedDaysAgo: 240,\n    permissions: [\"Read brand libraries\"],\n  },\n  {\n    id: \"silo\",\n    name: \"Silo\",\n    blurb: \"Warehouse sync on a schedule.\",\n    description: \"Query your warehouse in plain language and schedule exports into reports.\",\n    category: \"Data\",\n    icon: DatabaseIcon,\n    tone: \"violet\",\n    tag: \"Popular\",\n    installs: 17400,\n    addedDaysAgo: 450,\n    authError: \"The service account is missing the warehouse reader role.\",\n    permissions: [\"Run read-only queries\", \"Read schemas\"],\n  },\n  {\n    id: \"gridline\",\n    name: \"Gridline\",\n    blurb: \"Spreadsheets your agents can edit.\",\n    description: \"Read ranges, append rows and keep a sheet in sync with any table in your workspace.\",\n    category: \"Data\",\n    icon: TableIcon,\n    tone: \"success\",\n    installs: 26100,\n    addedDaysAgo: 380,\n    connected: true,\n    permissions: [\"Read and edit sheets\", \"Create new sheets\"],\n  },\n  {\n    id: \"beacon\",\n    name: \"Beacon\",\n    blurb: \"Product analytics and funnels.\",\n    description: \"Ask why a funnel dropped and get a chart back, with the events that explain it.\",\n    category: \"Data\",\n    icon: ActivityIcon,\n    tone: \"info\",\n    installs: 9800,\n    addedDaysAgo: 120,\n    permissions: [\"Read events and cohorts\"],\n  },\n  {\n    id: \"harbor\",\n    name: \"Harbor Desk\",\n    blurb: \"Support tickets with SLAs.\",\n    description: \"Let a triage agent tag, prioritise and draft first replies on every new ticket.\",\n    category: \"Support\",\n    icon: LifeBuoyIcon,\n    tone: \"teal\",\n    tag: \"Popular\",\n    installs: 14300,\n    addedDaysAgo: 330,\n    permissions: [\"Read tickets\", \"Add internal notes\", \"Change ticket status\"],\n  },\n  {\n    id: \"murmur\",\n    name: \"Murmur\",\n    blurb: \"Public feedback boards and voting.\",\n    description: \"Cluster feature requests by theme and post a weekly digest to your team.\",\n    category: \"Support\",\n    icon: MegaphoneIcon,\n    tone: \"warning\",\n    tag: \"Beta\",\n    installs: 1200,\n    addedDaysAgo: 30,\n    permissions: [\"Read posts and votes\", \"Change post status\"],\n  },\n  {\n    id: \"lumen\",\n    name: \"Lumen Search\",\n    blurb: \"Semantic search over every doc.\",\n    description: \"Index your docs and wikis so agents can cite the exact paragraph they used.\",\n    category: \"AI\",\n    icon: SparklesIcon,\n    tone: \"amber\",\n    tag: \"New\",\n    installs: 6100,\n    addedDaysAgo: 5,\n    permissions: [\"Read indexed documents\", \"Create embeddings\"],\n  },\n  {\n    id: \"scribe\",\n    name: \"Scribe\",\n    blurb: \"Meeting notes that write themselves.\",\n    description: \"Turn any recording into notes, decisions and owners, then file them where they belong.\",\n    category: \"AI\",\n    icon: FileTextIcon,\n    tone: \"orange\",\n    installs: 11200,\n    addedDaysAgo: 190,\n    permissions: [\"Read recordings\", \"Create documents\"],\n  },\n];\n\ntype Status = \"idle\" | \"connecting\" | \"connected\" | \"error\";\ntype Filter = \"all\" | \"connected\" | \"available\";\ntype Sort = \"popular\" | \"name\" | \"newest\";\n\nconst sortItems = { popular: \"Most popular\", name: \"Name A–Z\", newest: \"Newest\" };\nconst filters: Filter[] = [\"all\", \"connected\", \"available\"];\n\nconst easeOut = [0.23, 1, 0.32, 1] as const;\nconst quick = { duration: 0.18, ease: easeOut };\nconst glide = { type: \"spring\", duration: 0.3, bounce: 0 } as const;\nconst drawer = { duration: 0.28, ease: [0.32, 0.72, 0, 1] } as const;\n\nconst press = \"transition-[scale,box-shadow,background-color,color] duration-150 ease-out active:scale-[0.97]\";\n\nfunction formatInstalls(n: number) {\n  return n >= 1000 ? `${(n / 1000).toFixed(n >= 10000 ? 0 : 1)}k` : String(n);\n}\n\nfunction RollingNumber({ value }: { value: number }) {\n  const reduce = useSafeReducedMotion();\n  return (\n    <span className=\"relative inline-flex overflow-hidden tabular-nums\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ y: 0, opacity: 1 }}\n          exit={reduce ? { opacity: 0 } : { y: \"-100%\", opacity: 0 }}\n          initial={reduce ? { opacity: 0 } : { y: \"100%\", opacity: 0 }}\n          key={value}\n          transition={quick}\n        >\n          {value}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction useSwap() {\n  const reduce = useSafeReducedMotion();\n  return reduce\n    ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n    : {\n        initial: { opacity: 0, scale: 0.96, filter: \"blur(2px)\" },\n        animate: { opacity: 1, scale: 1, filter: \"blur(0px)\" },\n        exit: { opacity: 0, scale: 0.96, filter: \"blur(2px)\" },\n      };\n}\n\nconst menuMotion =\n  \"min-w-40 transition-[scale,opacity] duration-150 ease-out data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0 motion-reduce:data-ending-style:scale-100 motion-reduce:data-starting-style:scale-100\";\n\nfunction ConnectButton({\n  status,\n  name,\n  onConnect,\n  onCancel,\n  onDisconnect,\n  onConfigure,\n}: {\n  status: Status;\n  name: string;\n  onConnect: () => void;\n  onCancel: () => void;\n  onDisconnect: () => void;\n  onConfigure: () => void;\n}) {\n  const variants = useSwap();\n  const connected = status === \"connected\";\n  const triggerRef = useRef<HTMLButtonElement>(null);\n  const keepFocus = useRef(false);\n\n  useEffect(() => {\n    if (connected && keepFocus.current) triggerRef.current?.focus();\n    if (status !== \"connecting\") keepFocus.current = false;\n  }, [connected, status]);\n\n  return (\n    <div className=\"flex h-8 min-w-24 items-center justify-end\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        {connected ? (\n          <motion.div\n            animate=\"animate\"\n            className=\"flex items-center gap-0.5\"\n            exit=\"exit\"\n            initial=\"initial\"\n            key=\"connected\"\n            transition={quick}\n            variants={variants}\n          >\n            <span className=\"inline-flex items-center gap-1.5 font-medium text-success-foreground text-xs\">\n              <span className=\"flex size-4 items-center justify-center rounded-full bg-success/16\">\n                <CheckIcon className=\"size-3\" />\n              </span>\n              Connected\n            </span>\n            <Menu>\n              <MenuTrigger\n                render={\n                  <Button\n                    aria-label={`${name} options`}\n                    className={cn(\"size-8 text-muted-foreground hover:text-foreground sm:size-8\", press)}\n                    ref={triggerRef}\n                    size=\"icon\"\n                    variant=\"ghost\"\n                  />\n                }\n              >\n                <EllipsisIcon />\n              </MenuTrigger>\n              <MenuPopup align=\"end\" className={menuMotion}>\n                <MenuItem onClick={onConfigure}>\n                  <Settings2Icon />\n                  Configure\n                </MenuItem>\n                <MenuSeparator />\n                <MenuItem onClick={onDisconnect} variant=\"destructive\">\n                  <UnplugIcon />\n                  Disconnect\n                </MenuItem>\n              </MenuPopup>\n            </Menu>\n          </motion.div>\n        ) : (\n          <motion.div animate=\"animate\" exit=\"exit\" initial=\"initial\" key=\"action\" transition={quick} variants={variants}>\n            <Button\n              aria-label={\n                status === \"connecting\" ? `Cancel connecting ${name}` : status === \"error\" ? `Retry connecting ${name}` : `Connect ${name}`\n              }\n              className={cn(\"group/connect h-8 min-w-24 text-xs sm:h-8 sm:text-xs\", press)}\n              onClick={(e) => {\n                if (status === \"connecting\") return onCancel();\n                keepFocus.current = e.currentTarget === document.activeElement;\n                onConnect();\n              }}\n              variant=\"outline\"\n            >\n              <span className=\"relative flex size-3.5 items-center justify-center\">\n                {status === \"connecting\" ? (\n                  <>\n                    <Spinner className=\"size-3.5 transition-opacity duration-150 group-hover/connect:opacity-0 group-focus-visible/connect:opacity-0\" />\n                    <XIcon className=\"absolute size-3.5 opacity-0 transition-opacity duration-150 group-hover/connect:opacity-80 group-focus-visible/connect:opacity-80\" />\n                  </>\n                ) : status === \"error\" ? (\n                  <RotateCwIcon className=\"size-3.5\" />\n                ) : (\n                  <PlugIcon className=\"size-3.5\" />\n                )}\n              </span>\n              {status === \"connecting\" ? \"Cancel\" : status === \"error\" ? \"Retry\" : \"Connect\"}\n            </Button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport interface ConnectorsProps {\n  apps?: ConnectorApp[];\n  title?: string;\n  connectDelay?: number;\n  className?: string;\n}\n\nexport function Connectors({\n  apps = defaultApps,\n  title = \"Integrations\",\n  connectDelay = 1400,\n  className,\n}: ConnectorsProps) {\n  const uid = useId();\n  const reduce = useSafeReducedMotion();\n  const [status, setStatus] = useState<Record<string, Status>>(() =>\n    Object.fromEntries(apps.map((a) => [a.id, a.connected ? \"connected\" : \"idle\"])),\n  );\n  const [category, setCategory] = useState(\"All\");\n  const [filter, setFilter] = useState<Filter>(\"all\");\n  const [sort, setSort] = useState<Sort>(\"popular\");\n  const [query, setQuery] = useState(\"\");\n  const [openId, setOpenId] = useState<string | null>(null);\n  const [requested, setRequested] = useState<string[]>([]);\n  const timers = useRef(new Map<string, number>());\n  const failedOnce = useRef(new Set<string>());\n  const searchRef = useRef<HTMLInputElement>(null);\n  const panelRef = useRef<HTMLDivElement>(null);\n  const scrollRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const map = timers.current;\n    return () => map.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  useEffect(() => {\n    if (openId) panelRef.current?.focus();\n  }, [openId]);\n\n  useEffect(() => {\n    scrollRef.current?.scrollTo({ top: 0, behavior: reduce ? \"auto\" : \"smooth\" });\n  }, [category, filter]);\n\n  const clearTimer = (id: string) => {\n    const t = timers.current.get(id);\n    if (t) window.clearTimeout(t);\n    timers.current.delete(id);\n  };\n\n  const connect = (id: string) => {\n    clearTimer(id);\n    setStatus((s) => ({ ...s, [id]: \"connecting\" }));\n    const app = apps.find((a) => a.id === id);\n    const fail = Boolean(app?.authError) && !failedOnce.current.has(id);\n    timers.current.set(\n      id,\n      window.setTimeout(() => {\n        timers.current.delete(id);\n        if (fail) failedOnce.current.add(id);\n        setStatus((s) => ({ ...s, [id]: fail ? \"error\" : \"connected\" }));\n      }, connectDelay),\n    );\n  };\n  const reset = (id: string) => {\n    clearTimer(id);\n    setStatus((s) => ({ ...s, [id]: \"idle\" }));\n  };\n\n  const categories = useMemo(() => {\n    const names = Array.from(new Set(apps.map((a) => a.category)));\n    return [\n      { name: \"All\", count: apps.length },\n      ...names.map((name) => ({ name, count: apps.filter((a) => a.category === name).length })),\n    ];\n  }, [apps]);\n\n  const connectedCount = Object.values(status).filter((s) => s === \"connected\").length;\n\n  const visible = useMemo(() => {\n    const q = query.trim().toLowerCase();\n    return apps\n      .filter((a) => category === \"All\" || a.category === category)\n      .filter((a) => {\n        if (filter === \"connected\") return status[a.id] === \"connected\";\n        if (filter === \"available\") return status[a.id] !== \"connected\";\n        return true;\n      })\n      .filter((a) => !q || `${a.name} ${a.blurb} ${a.category}`.toLowerCase().includes(q))\n      .sort((a, b) =>\n        sort === \"name\"\n          ? a.name.localeCompare(b.name)\n          : sort === \"newest\"\n            ? a.addedDaysAgo - b.addedDaysAgo\n            : b.installs - a.installs,\n      );\n  }, [apps, category, filter, query, sort, status]);\n\n  const sections = useMemo(() => {\n    if (sort !== \"popular\" || category !== \"All\" || query.trim()) return [{ title: null as string | null, apps: visible }];\n    return categories\n      .slice(1)\n      .map((c) => ({ title: c.name as string | null, apps: visible.filter((a) => a.category === c.name) }))\n      .filter((g) => g.apps.length > 0);\n  }, [visible, sort, category, query, categories]);\n\n  const open = apps.find((a) => a.id === openId) ?? null;\n\n  const onRootKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n    if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"k\") {\n      e.preventDefault();\n      searchRef.current?.focus();\n      searchRef.current?.select();\n    }\n  };\n\n  const resetFilters = () => {\n    setQuery(\"\");\n    setCategory(\"All\");\n    setFilter(\"all\");\n  };\n\n  return (\n    <div\n      className={cn(\n        \"@container/screen relative isolate flex h-[760px] w-full overflow-hidden bg-background text-foreground text-sm\",\n        className,\n      )}\n      onKeyDown={onRootKeyDown}\n    >\n      <aside className=\"hidden w-56 shrink-0 flex-col gap-1 border-e bg-muted/40 p-3 @3xl/screen:flex\">\n        <div className=\"flex items-center gap-2 px-2 pt-1 pb-4\">\n          <span className=\"flex size-7 items-center justify-center rounded-lg bg-primary text-primary-foreground\">\n            <LayoutGridIcon className=\"size-4\" />\n          </span>\n          <div className=\"min-w-0\">\n            <p className=\"truncate font-medium\">Northwind</p>\n            <p className=\"truncate text-muted-foreground text-xs\">Workspace settings</p>\n          </div>\n        </div>\n        <p className=\"px-2 pb-1 font-medium text-muted-foreground text-xs\">Categories</p>\n        <nav aria-label=\"Categories\" className=\"flex flex-col gap-0.5\">\n          {categories.map((c) => {\n            const active = c.name === category;\n            return (\n              <button\n                aria-current={active ? \"true\" : undefined}\n                className={cn(\n                  \"relative flex h-8 cursor-pointer items-center justify-between rounded-lg px-2.5 text-start outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-ring\",\n                  active ? \"font-medium text-foreground\" : \"text-muted-foreground hover:bg-accent/60 hover:text-foreground\",\n                )}\n                key={c.name}\n                onClick={() => setCategory(c.name)}\n                type=\"button\"\n              >\n                {active && (\n                  <motion.span\n                    className=\"absolute inset-0 -z-10 rounded-lg border bg-card shadow-xs/5\"\n                    layoutId={`${uid}-rail`}\n                    transition={reduce ? { duration: 0 } : glide}\n                  />\n                )}\n                <span>{c.name}</span>\n                <span className=\"text-muted-foreground text-xs tabular-nums\">{c.count}</span>\n              </button>\n            );\n          })}\n        </nav>\n        <div className=\"mt-auto rounded-xl border bg-card p-3\">\n          <div className=\"flex items-center gap-2 font-medium text-xs\">\n            <ShieldCheckIcon className=\"size-4 text-success-foreground\" />\n            Reviewed apps only\n          </div>\n          <p className=\"mt-1 text-pretty text-muted-foreground text-xs\">\n            Every app here passed a security review. Admins approve new connections.\n          </p>\n        </div>\n      </aside>\n\n      <div className=\"@container relative flex min-w-0 flex-1 flex-col\">\n        <div className=\"min-h-0 flex-1 overflow-y-auto\" ref={scrollRef}>\n          <header className=\"sticky top-0 z-10 border-b bg-background/85 backdrop-blur-md\">\n            <div className=\"flex flex-col gap-3 px-4 pt-4 pb-3 @2xl:px-6\">\n              <div className=\"flex flex-wrap items-end justify-between gap-x-4 gap-y-2\">\n                <div className=\"min-w-0\">\n                  <h2 className=\"text-balance font-heading font-semibold text-lg tracking-tight\">{title}</h2>\n                  <p className=\"text-muted-foreground text-xs\">\n                    <RollingNumber value={visible.length} /> apps ·{\" \"}\n                    <RollingNumber value={connectedCount} /> connected\n                  </p>\n                </div>\n                <div className=\"relative w-full @xl:w-72\">\n                  <SearchIcon className=\"pointer-events-none absolute start-2.5 top-1/2 z-10 size-4 -translate-y-1/2 text-muted-foreground\" />\n                  <Input\n                    aria-label=\"Search apps\"\n                    className=\"[&_input]:ps-8 [&_input]:pe-12\"\n                    onChange={(e) => setQuery(e.target.value)}\n                    placeholder=\"Search apps\"\n                    ref={searchRef}\n                    type=\"search\"\n                    value={query}\n                  />\n                  <span className=\"absolute end-1.5 top-1/2 -translate-y-1/2\">\n                    {query ? (\n                      <Button\n                        aria-label=\"Clear search\"\n                        className={cn(\"size-7 rounded-full text-muted-foreground sm:size-7\", press)}\n                        onClick={() => {\n                          setQuery(\"\");\n                          searchRef.current?.focus();\n                        }}\n                        size=\"icon-sm\"\n                        variant=\"ghost\"\n                      >\n                        <XIcon className=\"size-3.5\" />\n                      </Button>\n                    ) : (\n                      <Kbd className=\"me-0.5\">⌘K</Kbd>\n                    )}\n                  </span>\n                </div>\n              </div>\n\n              <div className=\"-mx-4 flex gap-1.5 overflow-x-auto px-4 py-0.5 [scrollbar-width:none] @3xl/screen:hidden\">\n                {categories.map((c) => {\n                  const active = c.name === category;\n                  return (\n                    <button\n                      aria-pressed={active}\n                      className={cn(\n                        \"relative flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-full border px-3 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                        press,\n                        active ? \"border-transparent text-primary-foreground\" : \"text-muted-foreground hover:text-foreground\",\n                      )}\n                      key={c.name}\n                      onClick={() => setCategory(c.name)}\n                      type=\"button\"\n                    >\n                      {active && (\n                        <motion.span\n                          className=\"absolute -inset-px -z-10 rounded-full bg-primary\"\n                          layoutId={`${uid}-chip`}\n                          transition={reduce ? { duration: 0 } : glide}\n                        />\n                      )}\n                      {c.name}\n                      <span className={cn(\"tabular-nums\", active ? \"opacity-70\" : \"opacity-60\")}>{c.count}</span>\n                    </button>\n                  );\n                })}\n              </div>\n\n              <div className=\"flex items-center justify-between gap-2\">\n                <div\n                  aria-label=\"Connection filter\"\n                  className=\"flex rounded-lg bg-muted p-0.5\"\n                  onKeyDown={(e) => {\n                    const step = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : 0;\n                    if (!step) return;\n                    e.preventDefault();\n                    const next = filters[(filters.indexOf(filter) + step + filters.length) % filters.length];\n                    setFilter(next);\n                    e.currentTarget.querySelector<HTMLButtonElement>(`[data-value=\"${next}\"]`)?.focus();\n                  }}\n                  role=\"radiogroup\"\n                >\n                  {filters.map((f) => (\n                    <button\n                      aria-checked={filter === f}\n                      className={cn(\n                        \"relative h-7 cursor-pointer rounded-md px-2.5 font-medium text-xs capitalize outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-ring\",\n                        filter === f ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n                      )}\n                      data-value={f}\n                      key={f}\n                      onClick={() => setFilter(f)}\n                      role=\"radio\"\n                      tabIndex={filter === f ? 0 : -1}\n                      type=\"button\"\n                    >\n                      {filter === f && (\n                        <motion.span\n                          className=\"absolute inset-0 -z-10 rounded-md bg-background shadow-xs/5 dark:bg-input\"\n                          layoutId={`${uid}-filter`}\n                          transition={reduce ? { duration: 0 } : glide}\n                        />\n                      )}\n                      {f}\n                    </button>\n                  ))}\n                </div>\n                <Select items={sortItems} onValueChange={(v) => v && setSort(v as Sort)} value={sort}>\n                  <SelectTrigger aria-label=\"Sort apps\" className=\"w-auto min-w-36 text-sm\" size=\"sm\">\n                    <SelectValue />\n                  </SelectTrigger>\n                  <SelectPopup>\n                    {Object.entries(sortItems).map(([value, label]) => (\n                      <SelectItem key={value} value={value}>\n                        {label}\n                      </SelectItem>\n                    ))}\n                  </SelectPopup>\n                </Select>\n              </div>\n            </div>\n          </header>\n\n          <div className=\"p-4 @2xl:p-6\">\n            {visible.length === 0 ? (\n              <motion.div\n                animate={{ opacity: 1, y: 0 }}\n                className=\"flex flex-col items-center rounded-2xl border border-dashed bg-muted/24 px-6 py-14 text-center\"\n                initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6 }}\n                transition={quick}\n              >\n                <div aria-hidden className=\"relative mb-5 h-14 w-32\">\n                  <span className=\"absolute start-0 top-3 flex size-10 -rotate-8 items-center justify-center rounded-xl border bg-card text-muted-foreground/60 shadow-xs/5\">\n                    <MailIcon className=\"size-4\" />\n                  </span>\n                  <span className=\"absolute end-0 top-3 flex size-10 rotate-8 items-center justify-center rounded-xl border bg-card text-muted-foreground/60 shadow-xs/5\">\n                    <DatabaseIcon className=\"size-4\" />\n                  </span>\n                  <span className=\"absolute start-1/2 top-0 flex size-12 -translate-x-1/2 items-center justify-center rounded-xl border bg-card text-foreground shadow-sm/5\">\n                    <SearchXIcon className=\"size-5\" />\n                  </span>\n                </div>\n                <p className=\"text-balance font-medium\">\n                  {query ? (\n                    <>\n                      No apps match <span className=\"text-foreground\">“{query.trim()}”</span>\n                    </>\n                  ) : filter === \"connected\" ? (\n                    \"Nothing connected here yet\"\n                  ) : (\n                    \"Every app here is connected\"\n                  )}\n                </p>\n                <p className=\"mt-1 max-w-72 text-pretty text-muted-foreground text-xs\">\n                  {query\n                    ? \"Try another name or category. Missing an app your team uses? Ask us to add it.\"\n                    : \"Try another category, or browse the full directory.\"}\n                </p>\n                <div className=\"mt-5 flex flex-wrap justify-center gap-2\">\n                  <Button className={press} onClick={resetFilters} size=\"sm\" variant=\"outline\">\n                    Clear filters\n                  </Button>\n                  {query && (\n                    requested.includes(query.trim().toLowerCase()) ? (\n                      <Button aria-live=\"polite\" disabled size=\"sm\" variant=\"ghost\">\n                        <CheckIcon />\n                        Requested · we'll email you\n                      </Button>\n                    ) : (\n                      <Button\n                        className={press}\n                        onClick={() => setRequested((r) => [...r, query.trim().toLowerCase()])}\n                        size=\"sm\"\n                        variant=\"ghost\"\n                      >\n                        <MegaphoneIcon />\n                        Request “{query.trim().slice(0, 18)}”\n                      </Button>\n                    )\n                  )}\n                </div>\n              </motion.div>\n            ) : (\n              <div className=\"flex flex-col gap-8\">\n                {sections.map((section) => (\n                  <section aria-label={section.title ?? \"Apps\"} key={section.title ?? \"all\"}>\n                    {section.title && (\n                      <h3 className=\"mb-2.5 flex items-baseline gap-2 font-medium text-sm\">\n                        {section.title}\n                        <span className=\"font-normal text-muted-foreground text-xs tabular-nums\">{section.apps.length}</span>\n                      </h3>\n                    )}\n                    <motion.ul className=\"grid grid-cols-1 gap-2.5 @2xl:grid-cols-2\" layout={!reduce} transition={glide}>\n                      <AnimatePresence initial={false} mode=\"popLayout\">\n                        {section.apps.map((app) => (\n                          <AppCard\n                            app={app}\n                            key={app.id}\n                            onCancel={() => reset(app.id)}\n                            onConnect={() => connect(app.id)}\n                            onDisconnect={() => reset(app.id)}\n                            onOpen={() => setOpenId(app.id)}\n                            reduce={reduce}\n                            status={status[app.id] ?? \"idle\"}\n                          />\n                        ))}\n                      </AnimatePresence>\n                    </motion.ul>\n                  </section>\n                ))}\n              </div>\n            )}\n          </div>\n        </div>\n      </div>\n\n      <AnimatePresence>\n        {open && (\n          <>\n            <motion.div\n              animate={{ opacity: 1 }}\n              aria-hidden\n              className=\"absolute inset-0 z-20 bg-black/32\"\n              exit={{ opacity: 0 }}\n              initial={{ opacity: 0 }}\n              onClick={() => setOpenId(null)}\n              transition={{ duration: 0.2, ease: easeOut }}\n            />\n            <motion.div\n              animate={{ x: 0 }}\n              aria-label={`${open.name} details`}\n              aria-modal=\"true\"\n              className=\"absolute inset-y-0 end-0 z-30 flex w-full flex-col border-s bg-card outline-none @md:w-[400px] @md:rounded-s-2xl\"\n              exit={reduce ? { opacity: 0 } : { x: \"100%\" }}\n              initial={reduce ? { opacity: 0 } : { x: \"100%\" }}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\") {\n                  e.stopPropagation();\n                  setOpenId(null);\n                }\n              }}\n              ref={panelRef}\n              role=\"dialog\"\n              tabIndex={-1}\n              transition={drawer}\n            >\n              <DetailPanel\n                app={open}\n                onCancel={() => reset(open.id)}\n                onClose={() => setOpenId(null)}\n                onConnect={() => connect(open.id)}\n                onDisconnect={() => reset(open.id)}\n                status={status[open.id] ?? \"idle\"}\n              />\n            </motion.div>\n          </>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction AppCard({\n  app,\n  status: s,\n  reduce,\n  onOpen,\n  onConnect,\n  onCancel,\n  onDisconnect,\n}: {\n  app: ConnectorApp;\n  status: Status;\n  reduce: boolean;\n  onOpen: () => void;\n  onConnect: () => void;\n  onCancel: () => void;\n  onDisconnect: () => void;\n}) {\n  const Icon = app.icon;\n  return (\n    <motion.li\n      animate={{ opacity: 1, scale: 1 }}\n      className={cn(\n        \"group relative flex items-start gap-3 rounded-xl border bg-card p-3.5 transition-[border-color,background-color,scale] duration-150 ease-out has-[[data-card-trigger]:active]:scale-[0.985] [@media(hover:hover)]:hover:border-foreground/16\",\n        s === \"error\" && \"border-destructive/24\",\n      )}\n      exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.97 }}\n      initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.97 }}\n      layout={!reduce}\n      transition={quick}\n    >\n      <span className={cn(\"flex size-9 shrink-0 items-center justify-center rounded-lg\", toneClass[app.tone])}>\n        <Icon className=\"size-4.5\" />\n      </span>\n      <div className=\"min-w-0 flex-1\">\n        <div className=\"flex h-5 items-center gap-1.5\">\n          <button\n            className=\"truncate text-start font-medium outline-none after:absolute after:inset-0 after:rounded-xl focus-visible:after:ring-2 focus-visible:after:ring-ring\"\n            data-card-trigger\n            onClick={onOpen}\n            type=\"button\"\n          >\n            {app.name}\n          </button>\n          {app.tag && (\n            <Badge size=\"sm\" variant={tagVariant[app.tag]}>\n              {app.tag}\n            </Badge>\n          )}\n        </div>\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {s === \"error\" ? (\n            <motion.p\n              animate={{ opacity: 1, y: 0 }}\n              className=\"mt-0.5 flex min-w-0 items-center gap-1.5 text-destructive-foreground text-xs\"\n              exit={{ opacity: 0 }}\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n              key=\"error\"\n              role=\"status\"\n              transition={quick}\n            >\n              <CircleAlertIcon className=\"size-3.5 shrink-0\" />\n              <span className=\"truncate\">Authorization failed. Retry to try again.</span>\n            </motion.p>\n          ) : (\n            <motion.p\n              animate={{ opacity: 1 }}\n              className=\"mt-0.5 line-clamp-2 text-pretty text-muted-foreground text-xs @2xl:line-clamp-1\"\n              exit={{ opacity: 0 }}\n              initial={{ opacity: 0 }}\n              key=\"blurb\"\n              transition={quick}\n            >\n              {app.blurb}\n            </motion.p>\n          )}\n        </AnimatePresence>\n      </div>\n      <div className=\"relative z-[1] -my-0.5 shrink-0\">\n        <ConnectButton\n          name={app.name}\n          onCancel={onCancel}\n          onConfigure={onOpen}\n          onConnect={onConnect}\n          onDisconnect={onDisconnect}\n          status={s}\n        />\n      </div>\n    </motion.li>\n  );\n}\n\nconst statusCopy: Record<Status, { title: string; dot: string }> = {\n  idle: { title: \"Not connected\", dot: \"bg-muted-foreground/40\" },\n  connecting: { title: \"Authorizing…\", dot: \"bg-info\" },\n  connected: { title: \"Connected\", dot: \"bg-success\" },\n  error: { title: \"Authorization failed\", dot: \"bg-destructive\" },\n};\n\nfunction DetailPanel({\n  app,\n  status,\n  onConnect,\n  onCancel,\n  onDisconnect,\n  onClose,\n}: {\n  app: ConnectorApp;\n  status: Status;\n  onConnect: () => void;\n  onCancel: () => void;\n  onDisconnect: () => void;\n  onClose: () => void;\n}) {\n  const Icon = app.icon;\n  const reduce = useSafeReducedMotion();\n  const [options, setOptions] = useState({ sync: true, notify: true, agents: false });\n  const optionList = [\n    { key: \"sync\" as const, label: \"Sync every 15 minutes\", hint: \"Keep records fresh in the background.\" },\n    { key: \"notify\" as const, label: \"Notify on errors\", hint: \"Post to #ops when a sync fails.\" },\n    { key: \"agents\" as const, label: \"Allow agents to write\", hint: \"Agents can create and edit records.\" },\n  ];\n  const subtitle =\n    status === \"connected\"\n      ? \"Synced just now · by you\"\n      : status === \"connecting\"\n        ? `Approve in the ${app.name} window`\n        : status === \"error\"\n          ? (app.authError ?? `${app.name} didn’t grant access. Try again.`)\n          : \"An admin approves new connections\";\n  const action = status === \"connected\" ? \"Disconnect\" : status === \"connecting\" ? \"Cancel\" : status === \"error\" ? \"Retry\" : \"Connect\";\n\n  return (\n    <>\n      <div className=\"flex items-center justify-between border-b px-4 py-2.5\">\n        <p className=\"font-medium text-muted-foreground text-xs\">App details</p>\n        <Button aria-label=\"Close details\" className={press} onClick={onClose} size=\"icon\" variant=\"ghost\">\n          <XIcon />\n        </Button>\n      </div>\n      <div className=\"min-h-0 flex-1 overflow-y-auto p-5\">\n        <motion.div\n          animate={{ opacity: 1, y: 0 }}\n          className=\"flex items-start gap-3\"\n          initial={reduce ? false : { opacity: 0, y: 6 }}\n          transition={{ ...quick, delay: 0.06 }}\n        >\n          <span className={cn(\"flex size-12 shrink-0 items-center justify-center rounded-xl\", toneClass[app.tone])}>\n            <Icon className=\"size-6\" />\n          </span>\n          <div className=\"min-w-0 flex-1\">\n            <div className=\"flex items-center gap-1.5\">\n              <h3 className=\"truncate font-heading font-semibold text-base\">{app.name}</h3>\n              {app.tag && (\n                <Badge size=\"sm\" variant={tagVariant[app.tag]}>\n                  {app.tag}\n                </Badge>\n              )}\n            </div>\n            <p className=\"text-muted-foreground text-xs tabular-nums\">\n              {app.category} · {formatInstalls(app.installs)} workspaces\n            </p>\n          </div>\n        </motion.div>\n\n        <p className=\"mt-4 text-pretty text-muted-foreground\">{app.description}</p>\n\n        <div\n          className={cn(\n            \"mt-4 flex min-h-14 items-center gap-3 rounded-xl border py-2 ps-3 pe-2 transition-colors duration-200\",\n            status === \"error\" ? \"border-destructive/24 bg-destructive/4\" : \"bg-background\",\n          )}\n          role=\"status\"\n        >\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            <motion.div\n              animate={{ opacity: 1, y: 0 }}\n              className=\"flex min-w-0 flex-1 items-center gap-2.5\"\n              exit={reduce ? { opacity: 0 } : { opacity: 0, y: -4 }}\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: 4 }}\n              key={status}\n              transition={quick}\n            >\n              <span className={cn(\"relative flex size-2 shrink-0 rounded-full\", statusCopy[status].dot)}>\n                {status === \"connecting\" && !reduce && (\n                  <span className=\"absolute inset-0 animate-ping rounded-full bg-info/60\" />\n                )}\n              </span>\n              <span className=\"min-w-0\">\n                <span className=\"block font-medium text-sm\">{statusCopy[status].title}</span>\n                <span className=\"block text-pretty text-muted-foreground text-xs\">{subtitle}</span>\n              </span>\n            </motion.div>\n          </AnimatePresence>\n          <Button\n            className={cn(\"min-w-30 text-sm\", press)}\n            onClick={() => {\n              if (status === \"connected\") onDisconnect();\n              else if (status === \"connecting\") onCancel();\n              else onConnect();\n            }}\n            variant={status === \"connected\" ? \"destructive-outline\" : status === \"connecting\" ? \"outline\" : \"default\"}\n          >\n            <span className=\"relative flex size-4 items-center justify-center\">\n              {status === \"connected\" ? (\n                <UnplugIcon />\n              ) : status === \"connecting\" ? (\n                <Spinner className=\"size-3.5\" />\n              ) : status === \"error\" ? (\n                <RotateCwIcon />\n              ) : (\n                <PlugIcon />\n              )}\n            </span>\n            {action}\n          </Button>\n        </div>\n\n        <section className=\"mt-6\">\n          <h4 className=\"mb-2 font-medium text-xs\">This app will be able to</h4>\n          <ul className=\"flex flex-col gap-1.5 rounded-xl border bg-background p-3\">\n            {app.permissions.map((p, i) => (\n              <motion.li\n                animate={{ opacity: 1, x: 0 }}\n                className=\"flex items-center gap-2\"\n                initial={reduce ? false : { opacity: 0, x: 6 }}\n                key={p}\n                transition={{ ...quick, delay: 0.08 + i * 0.03 }}\n              >\n                <span className=\"flex size-4 items-center justify-center rounded-full bg-success/16 text-success-foreground\">\n                  <CheckIcon className=\"size-3\" />\n                </span>\n                {p}\n              </motion.li>\n            ))}\n          </ul>\n        </section>\n\n        <section className=\"mt-6\">\n          <h4 className=\"mb-2 font-medium text-xs\">Settings</h4>\n          <div\n            className={cn(\n              \"flex flex-col divide-y rounded-xl border transition-opacity duration-200\",\n              status !== \"connected\" && \"opacity-56\",\n            )}\n          >\n            {optionList.map((o) => (\n              <label className=\"flex cursor-pointer items-center justify-between gap-3 p-3\" key={o.key}>\n                <span className=\"min-w-0\">\n                  <span className=\"block font-medium\">{o.label}</span>\n                  <span className=\"block text-muted-foreground text-xs\">{o.hint}</span>\n                </span>\n                <Switch\n                  checked={options[o.key]}\n                  disabled={status !== \"connected\"}\n                  onCheckedChange={(v) => setOptions((s) => ({ ...s, [o.key]: v }))}\n                />\n              </label>\n            ))}\n          </div>\n          {status !== \"connected\" && (\n            <p className=\"mt-2 text-muted-foreground text-xs\">Connect {app.name} to change its settings.</p>\n          )}\n        </section>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}