import React, { useState, useEffect } from 'react'; import ReactDOM from 'react-dom/client'; import { GoogleGenAI, GenerateContentResponse } from "@google/genai"; const App = () => { const [platform, setPlatform] = useState('facebook'); const [contentType, setContentType] = useState('facebook-post'); const [contentLength, setContentLength] = useState('standard'); const [contentCategory, setContentCategory] = useState('promotion'); // Kept for general theme const [style, setStyle] = useState('friendly'); // Renamed from tone const [productName, setProductName] = useState(''); const [keyMessage, setKeyMessage] = useState(''); const [facebookPageLink, setFacebookPageLink] = useState(''); const [objective, setObjective] = useState('brand-awareness'); const [targetAudience, setTargetAudience] = useState(''); const [keywords, setKeywords] = useState(''); const [includeCTA, setIncludeCTA] = useState(true); const [includeEmojis, setIncludeEmojis] = useState(true); const [includeHashtags, setIncludeHashtags] = useState(false); const [numVariations, setNumVariations] = useState(1); const [generatedContents, setGeneratedContents] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); // const [copyButtonText, setCopyButtonText] = useState('📋 Copy Content'); // Will be per variation const [qaMetrics, setQaMetrics] = useState<{ grammar: string; narrativeFlow: string; culturalContext: string; optimizationSuggestion: string; engagementScore: string; } | null>(null); const API_KEY = process.env.API_KEY; let ai: GoogleGenAI | null = null; if (API_KEY) { ai = new GoogleGenAI({ apiKey: API_KEY }); } else { console.error("API_KEY environment variable not set."); } const platformContentTypeOptions: Record> = { facebook: [ { value: 'facebook-post', label: 'Post (Text, Multimedia)' }, { value: 'facebook-story-text', label: 'Story (Text-based)' }, { value: 'facebook-ad-copy', label: 'Ad Copy' }, { value: 'facebook-reel-script', label: 'Reel Script' }, ], instagram: [ { value: 'instagram-caption', label: 'Caption (for Post/Reel)' }, { value: 'instagram-story-text', label: 'Story (Text-based)' }, { value: 'instagram-reel-script', label: 'Reel Script' }, { value: 'instagram-ad-copy', label: 'Ad Copy' }, ], tiktok: [ { value: 'tiktok-video-script', label: 'Video Script' }, { value: 'tiktok-ad-script', label: 'Ad Script' }, ], youtube: [ { value: 'youtube-video-script', label: 'Video Script (Main)' }, { value: 'youtube-short-script', label: 'Short Script' }, { value: 'youtube-community-post', label: 'Community Post' }, { value: 'youtube-video-description', label: 'Video Description' }, ], viber: [ { value: 'viber-broadcast', label: 'Broadcast Message' }, { value: 'viber-channel-update', label: 'Channel Update' }, ], telegram: [ { value: 'telegram-channel-post', label: 'Channel Post' }, { value: 'telegram-group-message', label: 'Group Message' }, ] }; const simplifiedLengthOptions = [ { value: 'concise', label: 'Concise / Short' }, { value: 'standard', label: 'Standard / Medium' }, { value: 'detailed', label: 'Detailed / Long' }, ]; const styleOptions = [ { value: 'polite', label: 'Polite (Formal Burmese)' }, { value: 'friendly', label: 'Friendly (Casual Burmese)' }, { value: 'professional', label: 'Professional (Business Burmese)'}, { value: 'humorous', label: 'Humorous' }, { value: 'persuasive', label: 'Persuasive' }, { value: 'urgent', label: 'Urgent' }, { value: 'empathetic', label: 'Empathetic' }, ]; const objectiveOptions = [ { value: 'brand-awareness', label: 'Brand Awareness' }, { value: 'lead-generation', label: 'Lead Generation' }, { value: 'sales', label: 'Sales / Conversions' }, { value: 'engagement', label: 'Engagement (Likes, Comments, Shares)' }, { value: 'educate', label: 'Educate Audience' }, { value: 'event-promotion', label: 'Event Promotion'}, ]; useEffect(() => { const currentPlatformOptions = platformContentTypeOptions[platform] || []; if (currentPlatformOptions.length > 0 && !currentPlatformOptions.find(opt => opt.value === contentType)) { setContentType(currentPlatformOptions[0].value); } // Ensure contentLength is valid for the simplified options if (!simplifiedLengthOptions.find(opt => opt.value === contentLength)) { setContentLength(simplifiedLengthOptions[0].value); // Default to first option if current is invalid } }, [platform, contentType, contentLength]); // Added contentLength to dependencies const handleGenerateContent = async () => { if (!ai) { setError("Gemini AI client is not initialized. Check API Key configuration."); return; } if (!productName.trim() && !keyMessage.trim() && contentCategory !== 'seasonal' && objective !== 'brand-awareness') { setError("Please enter Product/Service Name or Key Message/Details, or select a broader category/objective."); return; } setIsLoading(true); setError(null); setGeneratedContents([]); setQaMetrics(null); let lengthInstruction = ""; switch (contentLength) { case 'concise': lengthInstruction = "a concise and short piece of content."; break; case 'standard': lengthInstruction = "a standard length piece of content, providing adequate detail."; break; case 'detailed': lengthInstruction = "a detailed and comprehensive piece of content."; break; default: lengthInstruction = "a standard length piece of content."; } const selectedContentTypeLabel = platformContentTypeOptions[platform]?.find(opt => opt.value === contentType)?.label || contentType; const selectedStyleLabel = styleOptions.find(opt => opt.value === style)?.label || style; const selectedObjectiveLabel = objectiveOptions.find(opt => opt.value === objective)?.label || objective; const capitalizedCategory = contentCategory.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); const prompt = ` You are an expert Burmese social media copywriter with deep understanding of native Burmese speaker patterns and cultural nuances relevant to Myanmar. Your style should emulate successful content found on Myanmar social media business pages and promotional posts. Generate ${numVariations} distinct variation(s) of content based on the following specifications: - Language: Burmese - Platform: ${platform.charAt(0).toUpperCase() + platform.slice(1)} - Content Type: ${selectedContentTypeLabel} - Desired Content Scope/Length: Generate ${lengthInstruction} - Primary Objective/Goal: ${selectedObjectiveLabel} - Content Theme/Category: ${capitalizedCategory} - Style: ${selectedStyleLabel} (translate this style appropriately into Burmese) ${productName.trim() ? `- Product/Service Name: "${productName}"` : ''} ${keyMessage.trim() ? `- Key Message/Details: "${keyMessage}"` : ''} ${targetAudience.trim() ? `- Target Audience: "${targetAudience}"` : ''} ${keywords.trim() ? `- Keywords to incorporate (if natural): "${keywords}"` : ''} ${facebookPageLink.trim() ? `- Business Context/Reference Facebook Page: ${facebookPageLink.trim()}. (Adapt to their style if possible)` : ''} Output Instructions: - Ensure each variation is clearly separated by "---VARIATION SEPARATOR---". If only 1 variation is requested, this separator is not needed. - For each variation: ${includeEmojis ? "- Seamlessly integrate relevant Burmese-style emojis." : "- Do not use emojis unless absolutely essential for the content type."} ${includeCTA ? `- Include a clear and natural-sounding Call To Action (CTA) suitable for the platform and objective.` : "- A direct Call To Action is not a priority unless inherent to the content type."} ${includeHashtags ? `- Include a few relevant and effective hashtags (Burmese or English as appropriate).` : "- Do not include hashtags unless specifically requested by the content type itself."} - Ensure the output is ONLY the generated Burmese content, ready to be used. - Focus on creating engaging, grammatically correct, and culturally appropriate content for the Myanmar market. - If the content type is a script (e.g., Reel Script, Video Script), format it appropriately with scene descriptions or speaker cues if applicable. Please provide exactly ${numVariations} variation(s). `; try { const response: GenerateContentResponse = await ai.models.generateContent({ model: 'gemini-2.5-flash-preview-04-17', contents: prompt, }); const text = response.text; if (numVariations > 1) { setGeneratedContents(text.split("---VARIATION SEPARATOR---").map(v => v.trim()).filter(v => v)); } else { setGeneratedContents([text.trim()]); } // Simulate QA metrics (applied to the first variation for simplicity) setQaMetrics({ grammar: Math.random() > 0.15 ? '✅ Excellent Burmese Grammar' : '⚠️ Review Grammar Advised', narrativeFlow: Math.random() > 0.2 ? '👍 Coherent Narrative Flow' : '🤔 Flow Could Be Smoother', culturalContext: Math.random() > 0.1 ? '✅ Culturally Appropriate for Myanmar' : '❓ Verify Cultural Context Locally', optimizationSuggestion: ['Consider A/B testing variations.', 'Analyze competitor content for this objective.', 'Ensure the visual pairing matches the text.'][Math.floor(Math.random() * 3)], engagementScore: `Predicted: ${Math.floor(Math.random() * 31) + 65}% Engagement` }); } catch (e: any) { console.error("Error generating content:", e); setError(`Failed to generate content. ${e.message || 'Please try again.'}`); setGeneratedContents([]); } finally { setIsLoading(false); } }; const handleCopyVariation = (textToCopy: string, variationIndex: number) => { navigator.clipboard.writeText(textToCopy) .then(() => { // Visually indicate copy success, perhaps on the button itself const button = document.getElementById(`copy-button-${variationIndex}`); if (button) { const originalText = button.innerHTML; button.innerHTML = '✅ Copied!'; setTimeout(() => { button.innerHTML = originalText; }, 2000); } }) .catch(err => { console.error('Failed to copy variation: ', err); setError('Failed to copy content to clipboard.'); }); }; const handleExportContent = () => { if (generatedContents.length > 0) { const allContent = generatedContents.map((content, index) => { return `--- Variation ${index + 1} ---\n${content}\n\n`; }).join(''); const blob = new Blob([allContent], { type: 'text/plain;charset=utf-8' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'burmese_social_media_content.txt'; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(link.href); } }; const currentPlatformContentTypeOptions = platformContentTypeOptions[platform] || []; return (

✍️ Burmese Social Media Content Generator V2

{!API_KEY && (
API Key is not configured. This application requires the API_KEY environment variable to be set to function.
)}
{/* Platform */}
{/* Content Type (Dynamic) */}
{/* Content Length/Scope */}
{/* Objective/Goal */}
{/* Style (was Tone) */}
{/* Content Category (General Theme) */}
{/* Product/Service Name */}
setProductName(e.target.value)} placeholder="e.g., Shwe Coffee Mix, Yangon Tech Services" aria-label="Product or Service Name" />
{/* Key Message/Details */}
{/* Target Audience */}
{/* Keywords */}
setKeywords(e.target.value)} placeholder="e.g., organic, sustainable, best coffee, tech solutions" aria-label="Keywords, comma separated" />
setFacebookPageLink(e.target.value)} placeholder="e.g., https://www.facebook.com/yourbusinesspage" aria-label="Facebook Page Link (Optional for style reference)" />
{/* Output Controls */}
{/* Number of Variations */}
setNumVariations(Math.max(1, Math.min(3, parseInt(e.target.value, 10) || 1)))} min="1" max="3" aria-label="Number of content variations" />
{error &&
{error}
} {isLoading &&
Generating Burmese content, please wait...
} {generatedContents.length > 0 && (

Generated Content (Burmese)

{generatedContents.map((content, index) => (

Variation {index + 1}

{content}
))} {generatedContents.length > 0 && ( )}
)} {qaMetrics && generatedContents.length > 0 && (

Content Quality Assurance (Simulated for Variation 1)

  • Grammar: {qaMetrics.grammar}
  • Narrative Flow: {qaMetrics.narrativeFlow}
  • Cultural Context: {qaMetrics.culturalContext}
  • Optimization Suggestion: {qaMetrics.optimizationSuggestion}
  • Engagement Predictor: {qaMetrics.engagementScore}
)}
); }; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render();