'use client'
import type { ReactNode } from 'react'
import { cn } from '@langgenius/dify-ui/cn'
import { useId } from 'react'
import { useTranslation } from 'react-i18next'
import CornerLabel from '@/app/components/base/corner-label'
import { SkeletonContainer, SkeletonRectangle } from '@/app/components/base/skeleton'
import Link from '@/next/link'
import { newKnowledgeCreatePathWithStartMode } from '../routes'
const LOADING_CARD_IDS = [
'loading-card-1',
'loading-card-2',
'loading-card-3',
'loading-card-4',
'loading-card-5',
'loading-card-6',
'loading-card-7',
'loading-card-8',
] as const
const EMPTY_GHOST_CARD_IDS = Array.from({ length: 16 }, (_, index) => `empty-ghost-card-${index}`)
export const KNOWLEDGE_SPACE_GRID_CLASS_NAME =
'grid grid-cols-[repeat(auto-fill,minmax(min(100%,280px),1fr))] gap-2.5'
export function NewKnowledgeLoadingState() {
const { t } = useTranslation('common')
return (
$.loading)}>
{LOADING_CARD_IDS.map((id) => (
))}
)
}
export function NewKnowledgePageState({
action,
description,
title,
}: {
action?: ReactNode
description: ReactNode
title: ReactNode
}) {
return (
{title}
{description}
{action ?
{action}
: null}
)
}
function EmptyAction({
description,
href,
iconClassName,
recommended = false,
title,
}: {
description: string
href?: string
iconClassName: string
recommended?: boolean
title: string
}) {
const { t } = useTranslation('dataset')
const unavailable = t(($) => $['cornerLabel.unavailable'])
const recommendedLabel = t(($) => $['firstEmpty.recommended'])
const descriptionId = useId()
const unavailableId = useId()
const recommendedId = useId()
return (
{title}
{description}
{!href && (
{unavailable}
)}
{recommended && (
)}
)
}
function ButtonOrLink({
children,
href,
...props
}: {
'aria-describedby': string
'aria-label': string
children: ReactNode
className: string
href?: string
}) {
if (href)
return (
{children}
)
return (
)
}
function EmptyGhostGrid() {
return (
{EMPTY_GHOST_CARD_IDS.map((id) => (
))}
)
}
export function NewKnowledgeEmptyState({
canConnect,
canCreate,
}: {
canConnect: boolean
canCreate: boolean
}) {
const { t } = useTranslation('dataset')
const canStart = canCreate
return (
{t(($) => $['newKnowledge.emptyTitle'])}
{t(($) => $['newKnowledge.emptyDescription'])}
{canStart ? (
{canConnect && (
$['newKnowledge.connectSource'])}
description={t(($) => $['newKnowledge.connectSourceDescription'])}
/>
)}
{canCreate && (
$['newKnowledge.uploadFiles'])}
description={t(($) => $['newKnowledge.uploadFilesDescription'])}
/>
)}
{canCreate && (
<>
{t(($) => $['firstEmpty.or'])}
$['newKnowledge.startEmpty'])}
description={t(($) => $['newKnowledge.startEmptyDescription'])}
href={newKnowledgeCreatePathWithStartMode('empty')}
/>
>
)}
) : (
{t(($) => $['newKnowledge.readOnlyEmpty'])}
)}
)
}