import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { MarketServer, MarketServerInstallation } from '@/types'; import ServerForm from './ServerForm'; interface MarketServerDetailProps { server: MarketServer; onBack: () => void; onInstall: (server: MarketServer) => void; installing?: boolean; isInstalled?: boolean; } const MarketServerDetail: React.FC = ({ server, onBack, onInstall, installing = false, isInstalled = false }) => { const { t } = useTranslation(); const [modalVisible, setModalVisible] = useState(false); const [error, setError] = useState(null); // Helper function to determine button state const getButtonProps = () => { if (isInstalled) { return { className: "bg-green-600 cursor-default px-4 py-2 rounded text-sm font-medium text-white", disabled: true, text: t('market.installed') }; } else if (installing) { return { className: "bg-gray-400 cursor-not-allowed px-4 py-2 rounded text-sm font-medium text-white", disabled: true, text: t('market.installing') }; } else { return { className: "bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded text-sm font-medium text-white", disabled: false, text: t('market.install') }; } }; const toggleModal = () => { setModalVisible(!modalVisible); setError(null); // Clear any previous errors when toggling modal }; const handleInstall = () => { if (!isInstalled) { toggleModal(); } }; // Get the preferred installation configuration based on priority: // npm > uvx > default const getPreferredInstallation = (): MarketServerInstallation | undefined => { if (!server.installations) { return undefined; } if (server.installations.npm) { return server.installations.npm; } else if (server.installations.uvx) { return server.installations.uvx; } else if (server.installations.default) { return server.installations.default; } // If none of the preferred types are available, get the first available installation type const installTypes = Object.keys(server.installations); if (installTypes.length > 0) { return server.installations[installTypes[0]]; } return undefined; }; const handleSubmit = async (payload: any) => { try { setError(null); // Pass the server object to the parent component for installation onInstall(server); setModalVisible(false); } catch (err) { console.error('Error installing server:', err); setError(t('errors.serverInstall')); } }; const buttonProps = getButtonProps(); const preferredInstallation = getPreferredInstallation(); return (

{server.display_name} ({server.name}) {t('market.author')}: {server.author.name} • {t('market.license')}: {server.license} • {t('market.repository')}

{server.is_official && ( {t('market.official')} )}

{server.description}

{t('market.categories')} & {t('market.tags')}

{server.categories?.map((category, index) => ( {category} ))} {server.tags && server.tags.map((tag, index) => ( #{tag} ))}
{server.arguments && Object.keys(server.arguments).length > 0 && (

{t('market.arguments')}

{Object.entries(server.arguments).map(([name, arg], index) => ( ))}
{t('market.argumentName')} {t('market.description')} {t('market.required')} {t('market.example')}
{name} {arg.description} {arg.required ? ( ) : ( )} {arg.example}
)}

{t('market.tools')}

{server.tools?.map((tool, index) => (

{tool.name}

{tool.description}

                  {JSON.stringify(tool.inputSchema, null, 2)}
                
))}
{server.examples && server.examples.length > 0 && (

{t('market.examples')}

{server.examples.map((example, index) => (

{example.title}

{example.description}

                  {example.prompt}
                
))}
)}
{modalVisible && (
)}
); }; export default MarketServerDetail;