'use client' import type { KeyboardEvent } from 'react' import type { App } from '@/models/explore' import type { TryAppSelection } from '@/types/try-app' import { cn } from '@langgenius/dify-ui/cn' import * as React from 'react' import { trackEvent } from '@/app/components/base/amplitude' import AppIcon from '@/app/components/base/app-icon' import { IS_CLOUD_EDITION } from '@/config' type LearnDifyItemProps = { canCreate: boolean item: App onCreate?: (app: App) => void onTry?: (params: TryAppSelection) => void } const LearnDifyItem = ({ canCreate, item, onCreate, onTry, }: LearnDifyItemProps) => { const appBasicInfo = item.app const canViewApp = IS_CLOUD_EDITION const canShowCreate = canCreate && !!onCreate const isClickable = canViewApp || canShowCreate const handleTryApp = () => { trackEvent('preview_template', { template_id: item.app_id, template_name: appBasicInfo.name, template_mode: appBasicInfo.mode, template_categories: item.categories, page: 'explore', }) onTry?.({ appId: item.app_id, app: item }) } const handleCardClick = () => { if (IS_CLOUD_EDITION) { handleTryApp() return } if (canShowCreate) onCreate?.(item) } const handleCardKeyDown = (event: KeyboardEvent) => { if (event.key !== 'Enter' && event.key !== ' ') return event.preventDefault() handleCardClick() } return (

{appBasicInfo.name}

{item.description}

) } export default React.memo(LearnDifyItem)