/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
'use client'
import { type ComponentProps, createContext, useContext } from 'react'
import { ChevronsUpDownIcon } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
import { Shimmer } from './shimmer'
type PlanContextValue = {
isStreaming: boolean
}
const PlanContext = createContext(null)
const usePlan = () => {
const context = useContext(PlanContext)
if (!context) {
throw new Error('Plan components must be used within Plan')
}
return context
}
export type PlanProps = ComponentProps & {
isStreaming?: boolean
}
export const Plan = ({
className,
isStreaming = false,
children,
...props
}: PlanProps) => (
}
>
{children}
)
export type PlanHeaderProps = ComponentProps
export const PlanHeader = ({ className, ...props }: PlanHeaderProps) => (
)
export type PlanTitleProps = Omit<
ComponentProps,
'children'
> & {
children: string
}
export const PlanTitle = ({ children, ...props }: PlanTitleProps) => {
const { isStreaming } = usePlan()
return (
{isStreaming ? {children} : children}
)
}
export type PlanDescriptionProps = Omit<
ComponentProps,
'children'
> & {
children: string
}
export const PlanDescription = ({
className,
children,
...props
}: PlanDescriptionProps) => {
const { isStreaming } = usePlan()
return (
{isStreaming ? {children} : children}
)
}
export type PlanActionProps = ComponentProps
export const PlanAction = (props: PlanActionProps) => (
)
export type PlanContentProps = ComponentProps
export const PlanContent = (props: PlanContentProps) => (
}
>
)
export type PlanFooterProps = ComponentProps<'div'>
export const PlanFooter = (props: PlanFooterProps) => (
)
export type PlanTriggerProps = ComponentProps
export const PlanTrigger = ({ className, ...props }: PlanTriggerProps) => {
const { t } = useTranslation()
return (
}
{...props}
>
{t('Toggle plan')}
)
}