{
  "name": "ai-schedule",
  "type": "registry:component",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "files": [
    {
      "type": "registry:component",
      "content": "\"use client\";\n\n/**\n * @author: @kokonutui\n * @description: AI Schedule\n * @version: 1.1.0\n * @date: 2026-11-05\n * @license: MIT\n * @website: https://kokonutui.com\n * @github: https://github.com/kokonut-labs/kokonutui\n */\n\nimport { Globe, Video } from \"lucide-react\";\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\";\nimport { type ReactNode, useId, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\n/** A span of hours in the day, e.g. [9.5, 11] for 9:30 to 11:00. */\ntype Span = [number, number];\n\nexport interface ScheduleSlot {\n  id: string;\n  weekday: string;\n  month: string;\n  day: number;\n  /** As shown, e.g. \"10:00 – 10:30\". */\n  time: string;\n  /** The slot itself, in hours. */\n  at: Span;\n  /** Your busy blocks that day. */\n  you: Span[];\n  /** Their busy blocks that day. */\n  them: Span[];\n  note?: string;\n}\n\nexport interface SchedulePerson {\n  name: string;\n  initials: string;\n}\n\nexport interface AIScheduleProps {\n  /** The user's message, drawn as a bubble. Only the demo draws one by default. */\n  prompt?: string;\n  /** What the assistant says above the times. */\n  message?: string;\n  /** What it says once booked, from the slot that was booked. */\n  confirmation?: (slot: ScheduleSlot) => ReactNode;\n  /** The event's name, on each slot. */\n  title?: string;\n  duration?: string;\n  timezone?: string;\n  with?: SchedulePerson;\n  me?: SchedulePerson;\n  /** The free times, usually a tool's output. Leave it out for the demo. */\n  slots?: ScheduleSlot[];\n  /**\n   * Books the slot. Resolve once the invite is out. Throw and the times come\n   * back with the error's message, e.g. when the slot was just taken.\n   */\n  onBook?: (slot: ScheduleSlot) => Promise<void>;\n  className?: string;\n}\n\ntype Status = \"pick\" | \"booking\" | \"booked\";\n\nconst EASE_OUT = [0.23, 1, 0.32, 1] as const;\n/** The day strip runs from 8:00 to 18:00. */\nconst DAY_START = 8;\nconst DAY_HOURS = 10;\n\nconst DEMO_SLOTS: ScheduleSlot[] = [\n  {\n    id: \"tue\",\n    weekday: \"Tue\",\n    month: \"Nov\",\n    day: 11,\n    time: \"10:00 – 10:30\",\n    at: [10, 10.5],\n    you: [\n      [8.5, 9.5],\n      [13, 14.5],\n    ],\n    them: [\n      [9, 10],\n      [11, 12],\n      [15, 16],\n    ],\n    note: \"Before her 11:00\",\n  },\n  {\n    id: \"wed\",\n    weekday: \"Wed\",\n    month: \"Nov\",\n    day: 12,\n    time: \"14:30 – 15:00\",\n    at: [14.5, 15],\n    you: [\n      [9, 11],\n      [15.5, 17],\n    ],\n    them: [\n      [10, 12.5],\n      [13, 14.5],\n    ],\n  },\n  {\n    id: \"thu\",\n    weekday: \"Thu\",\n    month: \"Nov\",\n    day: 13,\n    time: \"16:00 – 16:30\",\n    at: [16, 16.5],\n    you: [\n      [10, 12],\n      [14, 16],\n    ],\n    them: [\n      [8.5, 9.5],\n      [12, 15.5],\n    ],\n    note: \"End of day for both\",\n  },\n];\n\nconst wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));\n\nconst DEMO_TEXT = {\n  prompt: \"Find 30 minutes with Priya next week for the roadmap\",\n  message:\n    \"You’re both free at these times. Pick one and I’ll send the invite.\",\n  confirmation: (slot: ScheduleSlot) =>\n    `Booked for ${slot.weekday} at ${slot.time.split(\" \")[0]}. Priya has the invite with a video link, and I put the roadmap doc in the notes.`,\n};\n\n/** The chat text around the card: the demo's only when it's the demo. */\nfunction shownText(\n  text: Pick<AIScheduleProps, \"prompt\" | \"message\" | \"confirmation\">,\n  isDemo: boolean\n) {\n  if (!isDemo) {\n    return text;\n  }\n  return {\n    prompt: text.prompt ?? DEMO_TEXT.prompt,\n    message: text.message ?? DEMO_TEXT.message,\n    confirmation: text.confirmation ?? DEMO_TEXT.confirmation,\n  };\n}\n\nconst reasonOf = (error: unknown) =>\n  error instanceof Error && error.message\n    ? error.message\n    : \"Couldn’t book it. Try again.\";\n\nexport default function AISchedule({\n  prompt,\n  message,\n  confirmation,\n  title = \"Roadmap sync\",\n  duration = \"30 min\",\n  timezone = \"CET\",\n  with: guest = { name: \"Priya Shah\", initials: \"PS\" },\n  me = { name: \"You\", initials: \"M\" },\n  slots: slotsProp,\n  onBook = () => wait(900),\n  className,\n}: AIScheduleProps) {\n  const slots = slotsProp ?? DEMO_SLOTS;\n  const shown = shownText(\n    { prompt, message, confirmation },\n    slotsProp === undefined\n  );\n  const name = useId();\n  const [error, setError] = useState<string>();\n  const [selected, setSelected] = useState(slots[0]?.id);\n  const [status, setStatus] = useState<Status>(\"pick\");\n  const slot = slots.find((s) => s.id === selected) ?? slots[0];\n  const first = guest.name.split(\" \")[0];\n  const visible = status === \"booked\" ? [slot] : slots;\n\n  const book = async () => {\n    setStatus(\"booking\");\n    setError(undefined);\n    try {\n      await onBook(slot);\n      setStatus(\"booked\");\n    } catch (e) {\n      setError(reasonOf(e));\n      setStatus(\"pick\");\n    }\n  };\n\n  const select = (id: string) => {\n    setSelected(id);\n    setError(undefined);\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        className={cn(\"flex w-full max-w-md flex-col gap-4\", className)}\n        data-state={error ? \"error\" : status}\n      >\n        {shown.prompt ? (\n          <p className=\"max-w-[85%] self-end rounded-2xl rounded-br-md bg-zinc-100 px-3.5 py-2 text-[14px] text-zinc-800 leading-snug dark:bg-zinc-800 dark:text-zinc-100\">\n            {shown.prompt}\n          </p>\n        ) : null}\n        {shown.message ? (\n          <p className=\"text-[15px] text-zinc-800 leading-7 dark:text-zinc-200\">\n            {shown.message}\n          </p>\n        ) : null}\n\n        <div className=\"rounded-[22px] bg-black/[0.04] p-1 dark:bg-white/[0.06]\">\n          <div className=\"flex h-8 items-center justify-between px-3 text-[12px] text-zinc-500 dark:text-zinc-400\">\n            <span className=\"truncate\">\n              <span className=\"font-medium text-zinc-700 dark:text-zinc-300\">\n                {duration}\n              </span>{\" \"}\n              with {guest.name}\n            </span>\n            <span className=\"flex shrink-0 items-center gap-1\">\n              <Globe aria-hidden=\"true\" className=\"size-3\" />\n              Your time · {timezone}\n            </span>\n          </div>\n\n          <fieldset\n            className=\"min-w-0 rounded-[18px] bg-white p-1 shadow-[0_1px_2px_rgb(0_0_0/0.04)] ring-1 ring-black/[0.06] dark:bg-zinc-900 dark:ring-white/[0.08]\"\n            disabled={status !== \"pick\"}\n          >\n            <legend className=\"sr-only\">Pick a time</legend>\n            <AnimatePresence initial={false}>\n              {visible.map((s) => (\n                <motion.div\n                  animate={{ height: \"auto\", opacity: 1 }}\n                  className=\"overflow-hidden\"\n                  exit={{ height: 0, opacity: 0 }}\n                  initial={{ height: 0, opacity: 0 }}\n                  key={s.id}\n                  transition={{ duration: 0.35, ease: EASE_OUT }}\n                >\n                  <SlotRow\n                    booked={status === \"booked\"}\n                    checked={s.id === selected}\n                    guest={first}\n                    name={name}\n                    onSelect={() => select(s.id)}\n                    slot={s}\n                    title={title}\n                  />\n                </motion.div>\n              ))}\n            </AnimatePresence>\n          </fieldset>\n\n          <div className=\"flex h-12 items-center gap-3 pr-1.5 pl-3\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              {status === \"booked\" ? (\n                <motion.span\n                  animate={{ opacity: 1, filter: \"blur(0px)\" }}\n                  className=\"flex min-w-0 flex-1 items-center gap-2.5 text-[12.5px] text-zinc-600 dark:text-zinc-300\"\n                  initial={{ opacity: 0, filter: \"blur(3px)\" }}\n                  key=\"sent\"\n                  transition={{ duration: 0.3, ease: EASE_OUT, delay: 0.2 }}\n                >\n                  <span className=\"flex gap-0.5\">\n                    <Avatar person={me} tone=\"you\" />\n                    <Avatar person={guest} tone=\"them\" />\n                  </span>\n                  <span className=\"truncate\">Invite sent to {first}</span>\n                  <DrawnCheck />\n                </motion.span>\n              ) : (\n                <Footnote error={error} key={error ? \"error\" : \"legend\"} />\n              )}\n            </AnimatePresence>\n            {status !== \"booked\" && (\n              <BookButton\n                busy={status === \"booking\"}\n                label={`Book ${slot.weekday}`}\n                onClick={book}\n              />\n            )}\n          </div>\n        </div>\n\n        <AnimatePresence>\n          {status === \"booked\" && shown.confirmation ? (\n            <motion.p\n              animate={{ opacity: 1, filter: \"blur(0px)\", y: 0 }}\n              className=\"text-[15px] text-zinc-800 leading-7 dark:text-zinc-200\"\n              initial={{ opacity: 0, filter: \"blur(4px)\", y: 4 }}\n              transition={{ duration: 0.4, ease: EASE_OUT, delay: 0.45 }}\n            >\n              {shown.confirmation(slot)}\n            </motion.p>\n          ) : null}\n        </AnimatePresence>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {status === \"booking\" ? \"Booking\" : \"\"}\n          {status === \"booked\" ? `Booked, invite sent to ${first}` : \"\"}\n        </p>\n      </div>\n    </MotionConfig>\n  );\n}\n\n/** The colour key under the times, or why booking failed. */\nfunction Footnote({ error }: { error?: string }) {\n  if (error) {\n    return (\n      <motion.span\n        animate={{ opacity: 1 }}\n        className=\"min-w-0 flex-1 truncate text-[12px] text-rose-600 dark:text-rose-400\"\n        exit={{ opacity: 0 }}\n        initial={{ opacity: 0 }}\n        key=\"error\"\n        role=\"alert\"\n        title={error}\n        transition={{ duration: 0.2 }}\n      >\n        {error}\n      </motion.span>\n    );\n  }\n  return (\n    <motion.span\n      className=\"flex min-w-0 flex-1 items-center gap-3 text-[11.5px] text-zinc-500 dark:text-zinc-400\"\n      exit={{ opacity: 0, filter: \"blur(3px)\" }}\n      key=\"legend\"\n      transition={{ duration: 0.2 }}\n    >\n      <Key className=\"bg-zinc-300 dark:bg-zinc-600\" label=\"Busy\" />\n      <Key className=\"bg-blue-500\" label=\"Free for both\" />\n    </motion.span>\n  );\n}\n\nfunction SlotRow({\n  slot,\n  name,\n  checked,\n  booked,\n  title,\n  guest,\n  onSelect,\n}: {\n  slot: ScheduleSlot;\n  guest: string;\n  name: string;\n  checked: boolean;\n  booked: boolean;\n  title: string;\n  onSelect: () => void;\n}) {\n  return (\n    <label\n      className={cn(\n        \"relative block rounded-[14px] p-2.5 transition-colors duration-150 has-[input:focus-visible]:ring-2 has-[input:focus-visible]:ring-blue-500/40\",\n        booked ? \"cursor-default\" : \"cursor-pointer\",\n        !booked && checked && \"bg-zinc-100/80 dark:bg-white/[0.06]\",\n        !(booked || checked) && \"hover:bg-zinc-50 dark:hover:bg-white/[0.03]\"\n      )}\n    >\n      <span className=\"flex items-center gap-3\">\n        <input\n          checked={checked}\n          className=\"sr-only\"\n          name={name}\n          onChange={onSelect}\n          type=\"radio\"\n          value={slot.id}\n        />\n        <span className=\"flex w-10 shrink-0 flex-col overflow-hidden rounded-[9px] bg-white text-center ring-1 ring-black/[0.08] dark:bg-zinc-800 dark:ring-white/10\">\n          <span className=\"bg-red-500 py-px font-semibold text-[8.5px] text-white uppercase tracking-wider\">\n            {slot.month}\n          </span>\n          <span className=\"py-0.5 font-semibold text-[15px] text-zinc-900 leading-5 dark:text-zinc-100\">\n            {slot.day}\n          </span>\n        </span>\n\n        <span className=\"min-w-0 flex-1\">\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            <motion.span\n              animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n              className=\"block truncate font-medium text-[13.5px] text-zinc-900 dark:text-zinc-100\"\n              exit={{ opacity: 0, y: -4, filter: \"blur(2px)\" }}\n              initial={{ opacity: 0, y: 4, filter: \"blur(2px)\" }}\n              key={booked ? \"title\" : \"time\"}\n              transition={{ duration: 0.25, ease: EASE_OUT }}\n            >\n              {booked ? title : `${slot.weekday} · ${slot.time}`}\n            </motion.span>\n          </AnimatePresence>\n          <span className=\"mt-0.5 block truncate text-[12px] text-zinc-500 dark:text-zinc-400\">\n            {booked\n              ? `${slot.weekday} · ${slot.time}`\n              : (slot.note ?? \"Open for both\")}\n          </span>\n        </span>\n\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {booked ? (\n            <motion.span\n              animate={{ opacity: 1, x: 0 }}\n              className=\"flex h-6 shrink-0 items-center gap-1.5 rounded-full bg-blue-50 px-2.5 font-medium text-[11.5px] text-blue-700 dark:bg-blue-500/15 dark:text-blue-300\"\n              initial={{ opacity: 0, x: 6 }}\n              key=\"call\"\n              transition={{ duration: 0.3, ease: EASE_OUT, delay: 0.15 }}\n            >\n              <Video aria-hidden=\"true\" className=\"size-3\" />\n              Video call\n            </motion.span>\n          ) : (\n            <motion.span\n              aria-hidden=\"true\"\n              className={cn(\n                \"flex size-4 shrink-0 items-center justify-center rounded-full ring-1 transition-colors duration-150\",\n                checked\n                  ? \"bg-zinc-900 ring-zinc-900 dark:bg-white dark:ring-white\"\n                  : \"ring-zinc-300 dark:ring-zinc-600\"\n              )}\n              exit={{ opacity: 0 }}\n              key=\"radio\"\n              transition={{ duration: 0.15 }}\n            >\n              <motion.span\n                animate={{ scale: checked ? 1 : 0.5, opacity: checked ? 1 : 0 }}\n                className=\"size-1.5 rounded-full bg-white dark:bg-zinc-900\"\n                initial={false}\n                transition={{ duration: 0.15, ease: EASE_OUT }}\n              />\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </span>\n      <AnimatePresence initial={false}>\n        {checked && !booked && (\n          <motion.span\n            animate={{ height: \"auto\", opacity: 1 }}\n            className=\"block overflow-hidden\"\n            exit={{ height: 0, opacity: 0 }}\n            initial={{ height: 0, opacity: 0 }}\n            transition={{ duration: 0.25, ease: EASE_OUT }}\n          >\n            <DayLanes guest={guest} slot={slot} />\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </label>\n  );\n}\n\n/** Both calendars for the day, so you can see why the slot is free. */\nfunction DayLanes({ slot, guest }: { slot: ScheduleSlot; guest: string }) {\n  const pct = (h: number) => `${((h - DAY_START) / DAY_HOURS) * 100}%`;\n  const width = (a: number, b: number) => `${((b - a) / DAY_HOURS) * 100}%`;\n  const lane = (label: string, spans: Span[]) => (\n    <span className=\"flex h-3 items-center gap-2\">\n      <span className=\"w-10 shrink-0 truncate text-[10.5px] text-zinc-400 dark:text-zinc-500\">\n        {label}\n      </span>\n      <span className=\"relative h-1.5 flex-1 rounded-full bg-zinc-100 dark:bg-white/[0.06]\">\n        {spans.map(([a, b]) => (\n          <span\n            className=\"absolute inset-y-0 rounded-full bg-zinc-300 dark:bg-zinc-600\"\n            key={a}\n            style={{ left: pct(a), width: width(a, b) }}\n          />\n        ))}\n      </span>\n    </span>\n  );\n\n  return (\n    <span className=\"mt-2.5 ml-[52px] flex flex-col gap-1.5 pb-0.5\">\n      <span className=\"relative flex flex-col gap-1\">\n        {lane(\"You\", slot.you)}\n        {lane(guest, slot.them)}\n        <span className=\"pointer-events-none absolute inset-y-0 right-0 left-12\">\n          <motion.span\n            animate={{ opacity: 1, scaleY: 1 }}\n            className=\"absolute -inset-y-0.5 min-w-1 rounded-[3px] bg-blue-500\"\n            initial={{ opacity: 0, scaleY: 0.4 }}\n            style={{ left: pct(slot.at[0]), width: width(...slot.at) }}\n            transition={{ duration: 0.3, ease: EASE_OUT, delay: 0.15 }}\n          />\n        </span>\n      </span>\n      <span className=\"relative ml-12 h-3 text-[10px] text-zinc-400 tabular-nums leading-3 dark:text-zinc-500\">\n        {[9, 12, 15].map((h) => (\n          <span\n            className=\"absolute top-0 -translate-x-1/2\"\n            key={h}\n            style={{ left: pct(h) }}\n          >\n            {`${h}:00`}\n          </span>\n        ))}\n      </span>\n    </span>\n  );\n}\n\nfunction Key({ className, label }: { className: string; label: string }) {\n  return (\n    <span className=\"flex items-center gap-1.5 whitespace-nowrap\">\n      <span className={cn(\"h-1 w-2.5 rounded-full\", className)} />\n      {label}\n    </span>\n  );\n}\n\nfunction Avatar({\n  person,\n  tone,\n}: {\n  person: SchedulePerson;\n  tone: \"you\" | \"them\";\n}) {\n  return (\n    <span\n      className={cn(\n        \"flex size-6 items-center justify-center rounded-full font-semibold text-[9.5px]\",\n        tone === \"you\"\n          ? \"bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900\"\n          : \"bg-amber-100 text-amber-800 dark:bg-amber-500/20 dark:text-amber-200\"\n      )}\n      title={person.name}\n    >\n      {person.initials}\n    </span>\n  );\n}\n\nfunction DrawnCheck() {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      className=\"size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400\"\n      fill=\"none\"\n      viewBox=\"0 0 16 16\"\n    >\n      <motion.path\n        animate={{ pathLength: 1, opacity: 1 }}\n        d=\"M3.5 8.5l3 3 6-7\"\n        initial={{ pathLength: 0, opacity: 0 }}\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth=\"2\"\n        transition={{ duration: 0.35, ease: EASE_OUT, delay: 0.45 }}\n      />\n    </svg>\n  );\n}\n\nfunction BookButton({\n  busy,\n  label,\n  onClick,\n}: {\n  busy: boolean;\n  label: string;\n  onClick: () => void;\n}) {\n  return (\n    <button\n      className=\"flex h-9 min-w-[96px] items-center justify-center rounded-full bg-zinc-900 px-4 font-medium text-[13px] text-white outline-hidden transition-colors duration-150 hover:bg-zinc-800 focus-visible:ring-2 focus-visible:ring-blue-500/50 focus-visible:ring-offset-2 active:bg-zinc-700 disabled:cursor-default dark:bg-white dark:text-zinc-900 dark:active:bg-zinc-300 dark:focus-visible:ring-offset-zinc-900 dark:hover:bg-zinc-200\"\n      disabled={busy}\n      onClick={onClick}\n      type=\"button\"\n    >\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n          className=\"flex items-center\"\n          exit={{ opacity: 0, y: -6, filter: \"blur(2px)\" }}\n          initial={{ opacity: 0, y: 6, filter: \"blur(2px)\" }}\n          key={busy ? \"busy\" : label}\n          transition={{ duration: 0.18, ease: EASE_OUT }}\n        >\n          {busy ? <Spinner /> : label}\n        </motion.span>\n      </AnimatePresence>\n    </button>\n  );\n}\n\nfunction Spinner() {\n  return (\n    <motion.svg\n      animate={{ rotate: 360 }}\n      aria-hidden=\"true\"\n      className=\"size-4\"\n      fill=\"none\"\n      transition={{\n        duration: 0.6,\n        ease: \"linear\",\n        repeat: Number.POSITIVE_INFINITY,\n      }}\n      viewBox=\"0 0 16 16\"\n    >\n      <circle\n        cx=\"8\"\n        cy=\"8\"\n        opacity=\"0.25\"\n        r=\"6.25\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.75\"\n      />\n      <path\n        d=\"M8 1.75a6.25 6.25 0 0 1 6.25 6.25\"\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeWidth=\"1.75\"\n      />\n    </motion.svg>\n  );\n}\n",
      "path": "/components/kokonutui/ai-schedule.tsx",
      "target": "components/kokonutui/ai-schedule.tsx"
    }
  ]
}