{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-inline-citation",
  "type": "registry:item",
  "title": "Ai Inline Citation",
  "description": "A ai-inline-citation item.",
  "dependencies": [
    "@mui/material",
    "embla-carousel-react",
    "lucide-react",
    "@emotion/react",
    "@emotion/styled"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "components/ai-inline-citation/ai-inline-citation.tsx",
      "target": "src/mui-treasury/components/ai-inline-citation/ai-inline-citation.tsx",
      "content": "'use client';\n\nimport {\n  type ComponentProps,\n  type MouseEvent,\n  createContext,\n  memo,\n  useCallback,\n  useContext,\n  useEffect,\n  useRef,\n  useState,\n} from 'react';\n\nimport Box from '@mui/material/Box';\nimport Chip from '@mui/material/Chip';\nimport IconButton from '@mui/material/IconButton';\nimport Paper from '@mui/material/Paper';\nimport Popper from '@mui/material/Popper';\nimport Typography from '@mui/material/Typography';\nimport useEmblaCarousel from 'embla-carousel-react';\nimport { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react';\n\nexport type InlineCitationProps = ComponentProps<typeof Box>;\n\nexport const InlineCitation = ({ sx, ...props }: InlineCitationProps) => (\n  <Box\n    component=\"span\"\n    sx={{\n      display: 'inline',\n      ...sx,\n    }}\n    {...props}\n  />\n);\n\nexport type InlineCitationTextProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationText = ({\n  sx,\n  ...props\n}: InlineCitationTextProps) => (\n  <Box\n    component=\"span\"\n    sx={{\n      display: 'inline',\n      transition: 'background-color 0.2s',\n      borderRadius: 0.5,\n      px: 0.25,\n      '&:hover': {\n        bgcolor: 'action.hover',\n      },\n      ...sx,\n    }}\n    {...props}\n  />\n);\n\nexport type InlineCitationCardProps = {\n  sources: string[];\n  children: React.ReactNode;\n};\n\nexport const InlineCitationCard = ({\n  sources,\n  children,\n}: InlineCitationCardProps) => {\n  const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);\n  const hoverState = useRef({ chip: false, popover: false });\n  const closeTimer = useRef<NodeJS.Timeout | null>(null);\n\n  const checkClose = useCallback(() => {\n    if (closeTimer.current) {\n      clearTimeout(closeTimer.current);\n    }\n    closeTimer.current = setTimeout(() => {\n      if (!hoverState.current.chip && !hoverState.current.popover) {\n        setAnchorEl(null);\n      }\n    }, 150);\n  }, []);\n\n  const handleChipMouseEnter = useCallback((e: MouseEvent<HTMLDivElement>) => {\n    hoverState.current.chip = true;\n    setAnchorEl(e.currentTarget);\n    if (closeTimer.current) {\n      clearTimeout(closeTimer.current);\n    }\n  }, []);\n\n  const handleChipMouseLeave = useCallback(() => {\n    hoverState.current.chip = false;\n    checkClose();\n  }, [checkClose]);\n\n  const handlePopoverMouseEnter = useCallback(() => {\n    hoverState.current.popover = true;\n    if (closeTimer.current) {\n      clearTimeout(closeTimer.current);\n    }\n  }, []);\n\n  const handlePopoverMouseLeave = useCallback(() => {\n    hoverState.current.popover = false;\n    checkClose();\n  }, [checkClose]);\n\n  return (\n    <>\n      <InlineCitationCardTrigger\n        sources={sources}\n        onMouseEnter={handleChipMouseEnter}\n        onMouseLeave={handleChipMouseLeave}\n      />\n      <InlineCitationCardBody\n        anchorEl={anchorEl}\n        open={Boolean(anchorEl)}\n        onClose={() => setAnchorEl(null)}\n        onMouseEnter={handlePopoverMouseEnter}\n        onMouseLeave={handlePopoverMouseLeave}\n      >\n        {children}\n      </InlineCitationCardBody>\n    </>\n  );\n};\n\nexport type InlineCitationCardTriggerProps = ComponentProps<typeof Chip> & {\n  sources: string[];\n  onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void;\n  onMouseLeave?: (event: MouseEvent<HTMLDivElement>) => void;\n};\n\nexport const InlineCitationCardTrigger = ({\n  sources,\n  onMouseEnter,\n  onMouseLeave,\n  sx,\n  ...props\n}: InlineCitationCardTriggerProps) => {\n  const getHostname = (url: string) => {\n    try {\n      return new URL(url).hostname.replace('www.', '');\n    } catch {\n      return url;\n    }\n  };\n\n  return (\n    <Chip\n      component=\"span\"\n      size=\"small\"\n      color=\"secondary\"\n      onMouseEnter={onMouseEnter}\n      onMouseLeave={onMouseLeave}\n      label={\n        sources.length ? (\n          <>\n            {getHostname(sources[0])}\n            {sources.length > 1 && ` +${sources.length - 1}`}\n          </>\n        ) : (\n          'unknown'\n        )\n      }\n      sx={{\n        ml: 0.25,\n        height: 20,\n        fontSize: '0.7rem',\n        fontWeight: 400,\n        cursor: 'pointer',\n        verticalAlign: 'middle',\n        ...sx,\n      }}\n      {...props}\n    />\n  );\n};\n\nexport type InlineCitationCardBodyProps = ComponentProps<typeof Box> & {\n  anchorEl: HTMLElement | null;\n  open: boolean;\n  onClose: () => void;\n  onMouseEnter?: () => void;\n  onMouseLeave?: () => void;\n};\n\nexport const InlineCitationCardBody = ({\n  anchorEl,\n  open,\n  onClose,\n  onMouseEnter,\n  onMouseLeave,\n  children,\n  sx,\n  ...props\n}: InlineCitationCardBodyProps) => (\n  <Popper\n    open={open}\n    anchorEl={anchorEl}\n    placement=\"bottom-start\"\n    modifiers={[\n      {\n        name: 'offset',\n        options: {\n          offset: [0, 4],\n        },\n      },\n    ]}\n    sx={{ zIndex: 1300 }}\n  >\n    <Paper\n      onMouseEnter={onMouseEnter}\n      onMouseLeave={onMouseLeave}\n      sx={{\n        width: 320,\n        overflow: 'hidden',\n        boxShadow: 3,\n      }}\n    >\n      <Box sx={{ position: 'relative', ...sx }} {...props}>\n        {children}\n      </Box>\n    </Paper>\n  </Popper>\n);\n\ntype CarouselApi = ReturnType<typeof useEmblaCarousel>[1];\n\nconst CarouselApiContext = createContext<CarouselApi | undefined>(undefined);\n\nconst useCarouselApi = () => {\n  const context = useContext(CarouselApiContext);\n  return context;\n};\n\nexport type InlineCitationCarouselProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationCarousel = ({\n  children,\n  sx,\n  ...props\n}: InlineCitationCarouselProps) => {\n  const [emblaRef, emblaApi] = useEmblaCarousel({ loop: false });\n\n  return (\n    <CarouselApiContext.Provider value={emblaApi}>\n      <Box\n        ref={emblaRef}\n        sx={{\n          width: '100%',\n          overflow: 'hidden',\n          ...sx,\n        }}\n        {...props}\n      >\n        {children}\n      </Box>\n    </CarouselApiContext.Provider>\n  );\n};\n\nexport type InlineCitationCarouselContentProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationCarouselContent = ({\n  sx,\n  ...props\n}: InlineCitationCarouselContentProps) => (\n  <Box sx={{ display: 'flex', ...sx }} {...props} />\n);\n\nexport type InlineCitationCarouselItemProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationCarouselItem = ({\n  sx,\n  ...props\n}: InlineCitationCarouselItemProps) => (\n  <Box\n    sx={{\n      width: '100%',\n      flexShrink: 0,\n      p: 2,\n      pl: 4,\n      display: 'flex',\n      flexDirection: 'column',\n      gap: 1,\n      ...sx,\n    }}\n    {...props}\n  />\n);\n\nexport type InlineCitationCarouselHeaderProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationCarouselHeader = ({\n  sx,\n  ...props\n}: InlineCitationCarouselHeaderProps) => (\n  <Box\n    sx={{\n      display: 'flex',\n      alignItems: 'center',\n      justifyContent: 'space-between',\n      gap: 1,\n      bgcolor: 'action.hover',\n      p: 1,\n      borderTopLeftRadius: 8,\n      borderTopRightRadius: 8,\n      ...sx,\n    }}\n    {...props}\n  />\n);\n\nexport type InlineCitationCarouselIndexProps = ComponentProps<typeof Box>;\n\nexport const InlineCitationCarouselIndex = ({\n  children,\n  sx,\n  ...props\n}: InlineCitationCarouselIndexProps) => {\n  const api = useCarouselApi();\n  const [current, setCurrent] = useState(0);\n  const [count, setCount] = useState(0);\n\n  useEffect(() => {\n    if (!api) {\n      return;\n    }\n\n    setCount(api.scrollSnapList().length);\n    setCurrent(api.selectedScrollSnap() + 1);\n\n    api.on('select', () => {\n      setCurrent(api.selectedScrollSnap() + 1);\n    });\n  }, [api]);\n\n  return (\n    <Box\n      sx={{\n        flex: 1,\n        display: 'flex',\n        alignItems: 'center',\n        justifyContent: 'flex-end',\n        px: 1.5,\n        py: 0.5,\n        ...sx,\n      }}\n      {...props}\n    >\n      <Typography variant=\"caption\" sx={{ color: 'text.secondary' }}>\n        {children ?? `${current}/${count}`}\n      </Typography>\n    </Box>\n  );\n};\n\nexport type InlineCitationCarouselPrevProps = ComponentProps<typeof IconButton>;\n\nexport const InlineCitationCarouselPrev = ({\n  sx,\n  ...props\n}: InlineCitationCarouselPrevProps) => {\n  const api = useCarouselApi();\n\n  const handleClick = useCallback(() => {\n    if (api) {\n      api.scrollPrev();\n    }\n  }, [api]);\n\n  return (\n    <IconButton\n      size=\"small\"\n      aria-label=\"Previous\"\n      onClick={handleClick}\n      sx={{\n        p: 0.5,\n        color: 'text.secondary',\n        ...sx,\n      }}\n      {...props}\n    >\n      <ArrowLeftIcon className=\"size-4\" />\n    </IconButton>\n  );\n};\n\nexport type InlineCitationCarouselNextProps = ComponentProps<typeof IconButton>;\n\nexport const InlineCitationCarouselNext = ({\n  sx,\n  ...props\n}: InlineCitationCarouselNextProps) => {\n  const api = useCarouselApi();\n\n  const handleClick = useCallback(() => {\n    if (api) {\n      api.scrollNext();\n    }\n  }, [api]);\n\n  return (\n    <IconButton\n      size=\"small\"\n      aria-label=\"Next\"\n      onClick={handleClick}\n      sx={{\n        p: 0.5,\n        color: 'text.secondary',\n        ...sx,\n      }}\n      {...props}\n    >\n      <ArrowRightIcon className=\"size-4\" />\n    </IconButton>\n  );\n};\n\nexport type InlineCitationSourceProps = ComponentProps<typeof Box> & {\n  title?: string;\n  url?: string;\n  description?: string;\n};\n\nexport const InlineCitationSource = memo(\n  ({\n    title,\n    url,\n    description,\n    children,\n    sx,\n    ...props\n  }: InlineCitationSourceProps) => (\n    <Box\n      sx={{\n        display: 'flex',\n        flexDirection: 'column',\n        gap: 0.5,\n        ...sx,\n      }}\n      {...props}\n    >\n      {title && (\n        <Typography\n          variant=\"body2\"\n          sx={{\n            fontWeight: 500,\n            lineHeight: 1.2,\n            overflow: 'hidden',\n            textOverflow: 'ellipsis',\n            whiteSpace: 'nowrap',\n          }}\n        >\n          {title}\n        </Typography>\n      )}\n      {url && (\n        <Typography\n          variant=\"caption\"\n          sx={{\n            color: 'text.secondary',\n            overflow: 'hidden',\n            textOverflow: 'ellipsis',\n            whiteSpace: 'nowrap',\n            wordBreak: 'break-all',\n          }}\n        >\n          {url}\n        </Typography>\n      )}\n      {description && (\n        <Typography\n          variant=\"body2\"\n          sx={{\n            color: 'text.secondary',\n            lineHeight: 1.6,\n            display: '-webkit-box',\n            WebkitLineClamp: 3,\n            WebkitBoxOrient: 'vertical',\n            overflow: 'hidden',\n          }}\n        >\n          {description}\n        </Typography>\n      )}\n      {children}\n    </Box>\n  ),\n);\n\nInlineCitationSource.displayName = 'InlineCitationSource';\n\nexport type InlineCitationQuoteProps = ComponentProps<'blockquote'> & {\n  sx?: ComponentProps<typeof Box>['sx'];\n};\n\nexport const InlineCitationQuote = ({\n  children,\n  sx,\n  ...props\n}: InlineCitationQuoteProps) => (\n  <Box\n    component=\"blockquote\"\n    sx={{\n      borderLeft: 2,\n      borderColor: 'divider',\n      pl: 1.5,\n      fontStyle: 'italic',\n      color: 'text.secondary',\n      fontSize: '0.875rem',\n      m: 0,\n      ...sx,\n    }}\n    {...(props as any)}\n  >\n    {children}\n  </Box>\n);\n",
      "type": "registry:item"
    },
    {
      "path": "components/ai-inline-citation/index.ts",
      "target": "src/mui-treasury/components/ai-inline-citation/index.ts",
      "content": "export * from './ai-inline-citation';\n",
      "type": "registry:item"
    }
  ],
  "meta": {
    "category": "ai",
    "subcategory": "elements"
  }
}