'use client'
import type { App } from '@/types/app'
import { cn } from '@langgenius/dify-ui/cn'
import { Input } from '@langgenius/dify-ui/input'
import { useTranslation } from 'react-i18next'
import AppIcon from '@/app/components/base/app-icon'
import { SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton'
import { toAppMode } from '../app-mode'
import { StepShell } from './layout'
const sourceAppSkeletonKeys = ['first-source-app', 'second-source-app', 'third-source-app']
function sourceAppSearchText(app: App) {
return `${app.name} ${app.id} ${app.mode}`.toLowerCase()
}
function SourceAppSkeleton() {
return (
{sourceAppSkeletonKeys.map(key => (
))}
)
}
function SourceAppOption({ app, selected, onSelect }: {
app: App
selected: boolean
onSelect: () => void
}) {
const { t } = useTranslation('deployments')
const mode = toAppMode(app.mode)
return (
)
}
export function SourceStep({
apps,
selectedApp,
searchText,
isLoading,
onSearchTextChange,
onSelectApp,
}: {
apps: App[]
selectedApp?: App
searchText: string
isLoading: boolean
onSearchTextChange: (value: string) => void
onSelectApp: (app: App) => void
}) {
const { t } = useTranslation('deployments')
const effectiveSelectedAppId = selectedApp?.id ?? apps[0]?.id
const filteredApps = searchText.trim()
? apps.filter(app => sourceAppSearchText(app).includes(searchText.trim().toLowerCase()))
: apps
return (
onSearchTextChange(event.target.value)}
placeholder={t('createGuide.source.searchPlaceholder')}
className="h-9 pr-8 pl-8"
/>
{searchText && (
)}
{isLoading
?
: filteredApps.length === 0
? (
{t('createGuide.source.empty')}
)
: (
{filteredApps.map(app => (
onSelectApp(app)}
/>
))}
)}
)
}