'use client' import React, { useState } from 'react' interface AIServiceCardProps { title: string description: string isWalletConnected: boolean onGenerate: (prompt: string) => Promise<{ imageUrl?: string, error?: string }> mtmPrice: bigint } interface GenerationState { loading: boolean processing: boolean imageUrl: string | null error: string | null } const AIServiceCard: React.FC = ({ title, description, isWalletConnected, onGenerate, mtmPrice }) => { const [inputText, setInputText] = useState('') const [generationState, setGenerationState] = useState({ loading: false, processing: false, imageUrl: null, error: null, }) const handleGenerate = async (): Promise => { if (!inputText || !isWalletConnected) return setGenerationState({ ...generationState, loading: true, error: null, }) try { const result = await onGenerate(inputText) if (result.error) { setGenerationState({ ...generationState, loading: false, error: result.error, }) return } if (result.imageUrl) { setGenerationState({ loading: false, processing: false, imageUrl: result.imageUrl, error: null, }) } else { throw new Error('No image URL received') } } catch (error) { setGenerationState({ ...generationState, loading: false, error: error instanceof Error ? error.message : 'Generation failed', }) } } return (

{title}

{description}

Cost: {mtmPrice ? (mtmPrice / BigInt(10 ** 6)).toString() : '...'} MTM