{"version":3,"file":"command-root.cjs","sources":["../../../components/command/command-root.tsx"],"sourcesContent":["'use client';\n\nimport { Autocomplete as AutocompletePrimitive } from '@base-ui/react/autocomplete';\nimport { cx } from 'class-variance-authority';\nimport {\n  createContext,\n  type RefObject,\n  useCallback,\n  useContext,\n  useMemo,\n  useRef,\n  useState\n} from 'react';\nimport styles from './command.module.css';\n\ninterface CommandContextValue {\n  inputValue: string;\n  hasItems: boolean;\n  inputContainerRef: RefObject<HTMLDivElement | null>;\n}\n\nconst CommandContext = createContext<CommandContextValue | undefined>(\n  undefined\n);\n\nexport const useCommandContext = (): CommandContextValue => {\n  const context = useContext(CommandContext);\n  if (!context) {\n    throw new Error('useCommandContext must be used within a Command');\n  }\n  return context;\n};\n\nexport interface CommandRootProps\n  extends Omit<AutocompletePrimitive.Root.Props<any>, 'items'> {\n  /**\n   * Items to be displayed and filtered by Base UI internally.\n   * When provided, the auto-search fallback is disabled and filtering is\n   * delegated to Base UI's built-in logic (or the user's custom `filter`).\n   */\n  items?: readonly any[];\n  /** Additional CSS class for the panel wrapper. */\n  className?: string;\n}\n\nexport const CommandRoot = ({\n  value: providedValue,\n  defaultValue,\n  onValueChange,\n  items,\n  inline = true,\n  open = true,\n  autoHighlight = 'always',\n  keepHighlight = true,\n  className,\n  children,\n  ...props\n}: CommandRootProps) => {\n  const [internalValue, setInternalValue] = useState<string>(\n    typeof defaultValue === 'string' ? defaultValue : ''\n  );\n  const inputContainerRef = useRef<HTMLDivElement>(null);\n\n  const computedValue =\n    typeof providedValue === 'string' ? providedValue : internalValue;\n\n  const handleValueChange = useCallback(\n    (\n      value: string,\n      eventDetails: AutocompletePrimitive.Root.ChangeEventDetails\n    ) => {\n      setInternalValue(value);\n      onValueChange?.(value, eventDetails);\n    },\n    [onValueChange]\n  );\n\n  const contextValue = useMemo(\n    () => ({\n      inputValue: computedValue,\n      hasItems: !!items,\n      inputContainerRef\n    }),\n    [computedValue, items]\n  );\n\n  return (\n    <CommandContext.Provider value={contextValue}>\n      <AutocompletePrimitive.Root\n        inline={inline}\n        open={open}\n        autoHighlight={autoHighlight}\n        keepHighlight={keepHighlight}\n        value={providedValue}\n        defaultValue={defaultValue}\n        onValueChange={handleValueChange}\n        items={items}\n        {...props}\n      >\n        <div data-slot='command' className={cx(styles.panel, className)}>\n          {children}\n        </div>\n      </AutocompletePrimitive.Root>\n    </CommandContext.Provider>\n  );\n};\n\nCommandRoot.displayName = 'Command';\n"],"names":[],"mappings":";;;;;;;;;AAqBA;AAIO;AACL;;AAEE;;AAEF;AACF;AAca;;AAgBX;AAEA;;;AASI;AACF;AAIF;AAEI;;;AAGD;AAIH;AAmBF;AAEA;;;"}