'use client' import type { RecommendedAppResponse } from '@dify/contracts/api/console/explore/types.gen' import { cn } from '@langgenius/dify-ui/cn' import { useSuspenseQuery } from '@tanstack/react-query' import { useId } from 'react' import { useTranslation } from 'react-i18next' import { AppTypeIcon } from '@/app/components/app/type-selector' import { trackEvent } from '@/app/components/base/amplitude' import AppIcon from '@/app/components/base/app-icon' import { systemFeaturesQueryOptions } from '@/features/system-features/client' import { AppModeEnum } from '@/types/app' type TemplateCardProps = { app: RecommendedAppResponse canCreate: boolean onCreate: () => void onTry: (app: RecommendedAppResponse) => void } export function TemplateCard({ app, canCreate, onCreate, onTry }: TemplateCardProps) { const { t } = useTranslation() const { data: deploymentEdition } = useSuspenseQuery({ ...systemFeaturesQueryOptions(), select: ({ deployment_edition }) => deployment_edition, }) const nameId = useId() const descriptionId = useId() const appBasicInfo = app.app const appName = appBasicInfo?.name ?? '' const appMode = appBasicInfo?.mode ?? '' const appIconType = appBasicInfo?.icon_type === 'image' || appBasicInfo?.icon_type === 'emoji' || appBasicInfo?.icon_type === 'link' ? appBasicInfo.icon_type : null const canViewApp = deploymentEdition === 'CLOUD' const isClickable = canViewApp || canCreate const handleTryApp = () => { trackEvent('preview_template', { template_id: app.app_id, template_name: appName, template_mode: appMode, template_categories: app.categories ?? [], page: 'explore', }) onTry(app) } const handleCardClick = () => { if (canViewApp) { handleTryApp() return } if (canCreate) onCreate() } return (
{isClickable && (
) }