import React, { memo, useState, useCallback, useMemo } from 'react'; import * as Ariakit from '@ariakit/react'; import { CheckboxButton } from '@librechat/client'; import { ArtifactModes } from 'librechat-data-provider'; import { WandSparkles, ChevronDown } from 'lucide-react'; import { useBadgeRowContext } from '~/Providers'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; interface ArtifactsToggleState { enabled: boolean; mode: string; } function Artifacts() { const localize = useLocalize(); const { artifacts } = useBadgeRowContext(); const { toggleState, debouncedChange, isPinned } = artifacts; const [isPopoverOpen, setIsPopoverOpen] = useState(false); const currentState = useMemo(() => { if (typeof toggleState === 'string' && toggleState) { return { enabled: true, mode: toggleState }; } return { enabled: false, mode: '' }; }, [toggleState]); const isEnabled = currentState.enabled; const isShadcnEnabled = currentState.mode === ArtifactModes.SHADCNUI; const isCustomEnabled = currentState.mode === ArtifactModes.CUSTOM; const handleToggle = useCallback(() => { if (isEnabled) { debouncedChange({ value: '' }); } else { debouncedChange({ value: ArtifactModes.DEFAULT }); } }, [isEnabled, debouncedChange]); const handleShadcnToggle = useCallback(() => { if (isShadcnEnabled) { debouncedChange({ value: ArtifactModes.DEFAULT }); } else { debouncedChange({ value: ArtifactModes.SHADCNUI }); } }, [isShadcnEnabled, debouncedChange]); const handleCustomToggle = useCallback(() => { if (isCustomEnabled) { debouncedChange({ value: ArtifactModes.DEFAULT }); } else { debouncedChange({ value: ArtifactModes.CUSTOM }); } }, [isCustomEnabled, debouncedChange]); if (!isEnabled && !isPinned) { return null; } return (
); } export default memo(Artifacts);