// data.jsx — Gamingo Labs site data
// GL_DATA is populated synchronously from fallback, then hydrated from API async

const GL_FALLBACK = {
  studio: {
    name: 'Gamingo Labs',
    tagline: 'GAMES MAKE US!',
    subTagline: 'We craft mobile games that players love — from concept to Google Play.',
    eyebrow: 'Mobile Game Studio & Publisher',
    email: 'contact@gamingolabs.com',
    supportEmail: 'support@gamingolabs.com',
    website: 'https://gamingolabs.com',
    googlePlayDev: 'https://play.google.com/store/apps/dev?id=4944997063732533182',
    instagram: 'https://instagram.com/GamingoLabs',
    founded: '2020',
    newsletterDesc: 'Game launches, dev updates and tips from the team.',
    footerDesc: 'We craft mobile games that players love. From concept to Google Play — bold ideas, polished execution.',
    aboutParagraphs: [
      'Gamingo Labs is a passionate mobile game development and publishing studio. We live and breathe games — from the first prototype sketch to the final Google Play listing.',
      'Our portfolio spans casual puzzle, board games, and 3D sports titles. Each game is crafted with obsessive attention to feel, physics, and player retention.',
      'We work with a lean team of developers, designers, and marketers who care deeply about every pixel, every mechanic, and every rating.'
    ],
    values: [
      { title: 'Work Hard, Play Harder', desc: 'Our motto drives how we develop games and serve our players.' },
      { title: 'Player-First Design', desc: 'Every decision starts with: will the player enjoy this?' },
      { title: 'Sustainable Growth', desc: 'We build games and businesses that last — ethically and responsibly.' }
    ],
    stats: [
      { value: '4+', label: 'Games Published' },
      { value: '111K+', label: 'Downloads' },
      { value: '3', label: 'Game Genres' },
      { value: '4.0★', label: 'Avg Rating' }
    ],
  },
  games: [
    {
      id: 'pool-city',
      title: 'Pool City – 3D Billiards Pool',
      shortTitle: 'Pool City',
      genre: 'Sports',
      subgenre: '8 Ball, 9 Ball, Billiards, Snooker',
      description: 'Realistic 8-ball action on mobile. True 3D physics, neon-lit tables, online multiplayer, customizable cues.',
      longDescription: 'Pool City – 3D Billiards Pool is the ultimate mobile billiards experience. Featuring true 3D physics, city-themed neon-lit tables, and multiple game modes including 8 Ball, 9 Ball, and Snooker. Challenge players worldwide in real-time online multiplayer, unlock premium cue skins, and climb the global leaderboard.',
      features: ['True 3D physics engine', 'Online multiplayer & matchmaking', 'Multiple modes: 8 Ball, 9 Ball, Snooker', 'Neon-lit city-themed tables', 'Customizable cue skins', 'Daily challenges & rewards', 'Global leaderboards', 'Offline play supported'],
      keywords: 'pool city 3d billiards pool game android, 8 ball pool mobile game free, billiards game offline android, pool game 3d multiplayer',
      metaDescription: 'Play Pool City – the best 3D Billiards game on Android. Real physics, neon tables, online multiplayer, 8 Ball & 9 Ball modes. Free download on Google Play.',
      rating: 3.8, ratingCount: 1200, downloads: '10K+', platform: 'Android',
      bundleId: 'com.ggo.billiards.city.pool',
      playStoreUrl: 'https://play.google.com/store/apps/details?id=com.ggo.billiards.city.pool',
      icon: 'https://play-lh.googleusercontent.com/CsJUbNl2rlxThm8z0-3FhXlkJrHhj_WA9a9MnQx8dUVjJwtnIaDbMw8Cc0AyKhU9YAonECCzs8KeuQo6kdeD=s256',
      featured: true, status: 'Live', launchDate: '2024-03-15',
    },
    {
      id: 'screw-puzzle',
      title: 'Screw 3D Puzzle – Screwdle',
      shortTitle: 'Screwdle',
      genre: 'Puzzle',
      subgenre: 'Brain Teaser, Casual, Relaxing',
      description: 'Unscrew pins, free jammed bolts, master tricky levels. Satisfying 3D physics, offline play.',
      longDescription: "Screw 3D Puzzle – Screwdle is a uniquely satisfying puzzle game where you unscrew bolts, free jammed pins, and solve increasingly complex mechanical puzzles. With realistic 3D screw physics, ASMR-worthy sounds, and hundreds of handcrafted levels, Screwdle is the puzzle game you will not be able to put down.",
      features: ['Realistic 3D screw physics', '200+ handcrafted levels', 'ASMR satisfying sounds & animations', 'No internet required — fully offline', 'Regular new level packs', 'Relaxing gameplay — no timers', 'Brain-training puzzle mechanics', 'Free to play'],
      keywords: 'screw puzzle 3d screwdle android, bolt unscrew game mobile, brain puzzle game android free, screw jam nuts bolts puzzle',
      metaDescription: 'Play Screwdle – the most satisfying 3D screw puzzle game on Android. Unscrew bolts, solve tricky pin puzzles, 200+ levels. Free offline download on Google Play.',
      rating: 4.2, ratingCount: 850, downloads: '1K+', platform: 'Android',
      bundleId: 'com.screw.screwJam.nutsbolts.woodnuts',
      playStoreUrl: 'https://play.google.com/store/apps/details?id=com.screw.screwJam.nutsbolts.woodnuts',
      icon: 'https://play-lh.googleusercontent.com/4zAa8Ax3YhkCESfzh93muyOlUAL12PNdAkWtWpcmd_InSBO5F1JLRQeoG4VBHpiVAQ=s256',
      featured: true, status: 'Live', launchDate: '2024-06-10',
    },
    {
      id: 'carrom-city',
      title: 'Carrom City – 3D Pool Game',
      shortTitle: 'Carrom City',
      genre: 'Board',
      subgenre: 'Carrom, Disc Pool, Multiplayer Board',
      description: 'Ultimate disc pool challenge. Classic Carrom, Disc Pool, Practice modes. Online multiplayer, global leaderboards.',
      longDescription: 'Carrom City – 3D Pool Game brings the beloved board game of carrom to your phone with stunning 3D visuals and smooth physics. Play Classic Carrom, Disc Pool, and Practice modes. Challenge friends in private rooms or compete with players worldwide for a spot on the global leaderboard.',
      features: ['Classic Carrom & Disc Pool modes', 'Real-time online multiplayer', 'Private rooms — play with friends', 'Global leaderboards & tournaments', 'Smooth 3D physics engine', 'Unlock custom boards & strikers', 'Play offline in Practice mode', '100K+ downloads worldwide'],
      keywords: 'carrom city 3d pool game android, carrom board game online multiplayer, disc pool mobile game free, carrom game android best',
      metaDescription: 'Play Carrom City – the #1 3D Carrom board game on Android. Real physics, online multiplayer, classic carrom & disc pool modes. 100K+ downloads. Free on Google Play.',
      rating: 4.0, ratingCount: 4200, downloads: '100K+', platform: 'Android',
      bundleId: 'com.ggo.carrom.city.pool',
      playStoreUrl: 'https://play.google.com/store/apps/details?id=com.ggo.carrom.city.pool',
      icon: 'https://play-lh.googleusercontent.com/d2BTsedkq8qVyktEPhWvQHZd0r7Wjab2SrB7CAx7ZecTLbUpo6ve5s_UximZreM_G3Y=s256',
      featured: false, status: 'Live', launchDate: '2023-11-20',
    },
    {
      id: 'carrom-master',
      title: 'Carrom Master: Board Disc Pool',
      shortTitle: 'Carrom Master',
      genre: 'Board',
      subgenre: 'Carrom, Board Game, Multiplayer',
      description: 'Best carrom board simulator for Android. Play offline solo, local multiplayer, or live online.',
      longDescription: 'Carrom Master: Board Disc Pool is the most authentic carrom board simulator on Android. Featuring precise physics, multiple game modes, and seamless online matchmaking. Whether you want to practice offline, play locally with friends on the same device, or compete globally — Carrom Master delivers the full carrom experience.',
      features: ['Authentic carrom board physics', 'Offline solo & AI opponent', 'Local pass-and-play multiplayer', 'Online live matchmaking', 'Multiple carrom rule sets', 'Customizable boards & pieces', 'Smooth 60fps gameplay', 'All skill levels welcome'],
      keywords: 'carrom master board disc pool android, carrom game android download free, best carrom simulator mobile, carrom online multiplayer android',
      metaDescription: 'Carrom Master – the most authentic carrom board simulator on Android. Offline, local & online multiplayer. Real carrom physics. Free download on Google Play.',
      rating: 3.8, ratingCount: 620, downloads: '5K+', platform: 'Android',
      bundleId: 'com.gamingolabs.carrom',
      playStoreUrl: 'https://play.google.com/store/apps/details?id=com.gamingolabs.carrom',
      icon: 'https://play-lh.googleusercontent.com/bJGuKW2xvhd9nxEA5sroMlUOVlEiHWvG6FtrraJ1aJ6UDDnHyq4hCCAQQKDQIL8acQ=s256',
      featured: false, status: 'Live', launchDate: '2023-08-05',
    },
  ],
  services: [
    { icon: '🎮', title: 'Game Development', description: 'End-to-end mobile game development for Android and iOS. From concept to launch — polished gameplay, stunning visuals, optimized performance.' },
    { icon: '🚀', title: 'Game Publishing', description: 'We help indie developers publish and grow their games. Store optimization, metadata, screenshots, launch strategy — we handle it all.' },
    { icon: '📈', title: 'User Acquisition', description: 'Data-driven UA campaigns to grow your player base. We run targeted ads, analyze funnels, and scale what works.' },
    { icon: '💰', title: 'Monetization Strategy', description: 'Smart monetization with ad networks, IAP flows, and rewarded video strategies that retain players while maximizing LTV.' },
    { icon: '🎯', title: 'ASO & Store Optimization', description: 'Maximize app store visibility. Keyword research, compelling descriptions, A/B tested icons and screenshots.' },
    { icon: '🤝', title: 'Publishing Partnership', description: 'Are you an indie dev with a great game idea? Partner with us for funding, marketing, and full publishing support.' },
  ],
  videos: [
    { id: 'v1', title: 'Pool City – Official Gameplay Trailer', youtubeId: 'dQw4w9WgXcQ', gameId: 'pool-city', type: 'Gameplay', description: 'Official gameplay trailer for Pool City – 3D Billiards Pool.', date: '2024-03-20' },
    { id: 'v2', title: 'Screwdle – Gameplay Walkthrough Level 1-20', youtubeId: 'dQw4w9WgXcQ', gameId: 'screw-puzzle', type: 'Tutorial', description: 'Full walkthrough of the first 20 levels.', date: '2024-06-15' },
    { id: 'v3', title: 'Carrom City – Tips & Tricks for Beginners', youtubeId: 'dQw4w9WgXcQ', gameId: 'carrom-city', type: 'Tips', description: 'Master the basics and start winning online matches.', date: '2024-08-01' },
  ],
  tips: [
    { id: 't1', gameId: 'pool-city', title: 'Master the Power Stroke', content: 'Hold your shot longer to charge maximum power. Use full power only for break shots — controlled medium power wins more games.', difficulty: 'Beginner' },
    { id: 't2', gameId: 'screw-puzzle', title: 'Plan Your Sequence First', content: 'Before unscrewing anything, look at the full puzzle. Identify which screws are blocking others — always work outside-in.', difficulty: 'Beginner' },
    { id: 't3', gameId: 'carrom-city', title: 'The Thumb Flick Technique', content: 'For powerful straight shots, align your striker dead center and flick directly. Practice on the main queen for maximum points.', difficulty: 'Intermediate' },
    { id: 't4', gameId: 'pool-city', title: 'Spin & English Control', content: 'Tap the cue ball offset to add spin. Top spin pushes forward after contact, back spin pulls back — master both for position play.', difficulty: 'Advanced' },
  ],
  faq: [
    { id: 'f1', gameId: 'all', question: 'Are your games free to play?', answer: 'Yes! All Gamingo Labs games are free to download and play on Google Play. Some games contain optional ads and in-app purchases.' },
    { id: 'f2', gameId: 'all', question: 'Are the games available on iOS / App Store?', answer: 'Currently our games are available on Android (Google Play). iOS versions are on our roadmap — stay tuned!' },
    { id: 'f3', gameId: 'all', question: 'How do I report a bug or issue?', answer: 'Use the Support tab on this page or email us at support@gamingolabs.com. Include your device model, Android version, and a description of the issue.' },
    { id: 'f4', gameId: 'carrom-city', question: 'How does online multiplayer work in Carrom City?', answer: 'Tap Multiplayer from the main menu. Play with friends via private rooms or be matched with players globally via quick match.' },
    { id: 'f5', gameId: 'pool-city', question: 'How do I unlock new cues and tables?', answer: 'Complete daily challenges and win matches to earn coins. Visit the shop in-game to unlock premium cue designs and table skins.' },
  ],
  blog: [
    { id: 'b1', slug: 'pool-city-launch', title: 'Pool City 3D is Live on Google Play!', category: 'News', published_at: '2024-03-15', excerpt: 'After months of development, Pool City – our 3D Billiards game is now live on Google Play.', image: 'https://play-lh.googleusercontent.com/CsJUbNl2rlxThm8z0-3FhXlkJrHhj_WA9a9MnQx8dUVjJwtnIaDbMw8Cc0AyKhU9YAonECCzs8KeuQo6kdeD=s256', content: `## The Launch\n\nWe're thrilled to announce that **Pool City – 3D Billiards Pool** is now live on Google Play!\n\nAfter months of development, the game is finally in players' hands.\n\n## What's in the game\n\n- 8 Ball, 9 Ball and Snooker modes\n- Realistic 3D physics engine\n- City-themed neon-lit tables\n- Online multiplayer and daily challenges\n\nDownload it free on Google Play and let us know what you think!` },
    { id: 'b2', slug: 'screwdle-launch', title: 'Screwdle: Our Best-Rated Game Yet', category: 'Dev Log', published_at: '2024-06-10', excerpt: 'Screw 3D Puzzle – Screwdle launched to a 4.2 star rating. Here\'s the story of how we built it.', image: 'https://play-lh.googleusercontent.com/4zAa8Ax3YhkCESfzh93muyOlUAL12PNdAkWtWpcmd_InSBO5F1JLRQeoG4VBHpiVAQ=s256', content: `## Building Screwdle\n\nScrewdle started as a simple question: could we make unscrewing bolts *satisfying* on a touchscreen?\n\nThe answer, clearly, was yes.\n\n## The core mechanic\n\nThe key insight was **tactile feedback**. Every unscrew needed to feel physical — the right sound, the right animation speed, the right resistance.\n\n## Result\n\nWe launched to a 4.2-star rating and thousands of downloads in the first month. New puzzle packs are added every month!` },
    { id: 'b3', slug: 'mobile-game-lessons', title: '5 Things We Learned Publishing Mobile Games', category: 'Tips', published_at: '2024-09-01', excerpt: 'After publishing 4 games on Google Play, here are the top lessons from Gamingo Labs.', image: 'https://play-lh.googleusercontent.com/d2BTsedkq8qVyktEPhWvQHZd0r7Wjab2SrB7CAx7ZecTLbUpo6ve5s_UximZreM_G3Y=s256', content: `## 1. Screenshots matter more than anything\n\nYour store screenshots are your #1 conversion lever. We saw a **38% uplift** in installs after redesigning our Pool City screenshots.\n\n## 2. Launch with reviews ready\n\nAsk beta testers to leave reviews on day one. The algorithm rewards early velocity.\n\n## 3. Retention beats installs\n\nA game with 50K installs and 30% Day-7 retention beats one with 500K installs and 3%.\n\n## 4. Soft launch first\n\nWe always soft-launch in 2-3 countries before global rollout.\n\n## 5. Reply to every review\n\nEven negative ones. It shows you care and improves your store ranking.` },
  ],
  pressKit: {
    description: 'Download official Gamingo Labs brand assets for press, media, and partner use.',
    assets: [
      { name: 'Logo Pack (PNG + SVG)', type: 'zip', url: '#' },
      { name: 'Game Screenshots Bundle', type: 'zip', url: '#' },
      { name: 'Official Press Release', type: 'pdf', url: '#' },
    ],
    contact: 'press@gamingolabs.com',
  },
};

// Start with fallback, hydrate from API
const GL_DATA = { ...GL_FALLBACK };

async function GL_LOAD() {
  try {
    const [cRes, bRes] = await Promise.allSettled([
      fetch('/api/content.php?action=all'),
      fetch('/api/blog.php?action=list&limit=50'),
    ]);
    if (cRes.status === 'fulfilled' && cRes.value.ok) {
      const j = await cRes.value.json();
      if (j.success && j.data) {
        const d = j.data;
        if (d.studio)   Object.assign(GL_DATA.studio, d.studio);
        if (d.games?.length)    GL_DATA.games    = d.games;
        if (d.services?.length) GL_DATA.services = d.services;
        if (d.videos?.length)   GL_DATA.videos   = d.videos;
        if (d.tips?.length)     GL_DATA.tips     = d.tips;
        if (d.faq?.length)      GL_DATA.faq      = d.faq;
        const pk = d.press_kit || d.pressKit;
        if (pk) GL_DATA.pressKit = pk;
      }
    }
    if (bRes.status === 'fulfilled' && bRes.value.ok) {
      const j = await bRes.value.json();
      if (j.success && j.posts?.length) GL_DATA.blog = j.posts;
    }
  } catch (e) {
    // silently use fallback
  }
  return GL_DATA;
}

// Helpers
function glDate(str) {
  if (!str) return '';
  try { return new Date(str).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); } catch { return str; }
}

function glMd(md) {
  if (!md) return '';
  const e = md.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  return e
    .replace(/^### (.+)$/gm, '<h3 style="font-family:var(--gl-fd);font-size:1.5rem;margin:22px 0 8px;color:var(--gl-ink)">$1</h3>')
    .replace(/^## (.+)$/gm,  '<h2 style="font-family:var(--gl-fd);font-size:2rem;margin:30px 0 10px;color:var(--gl-ink)">$1</h2>')
    .replace(/^# (.+)$/gm,   '<h1 style="font-family:var(--gl-fd);font-size:2.8rem;margin:36px 0 12px;color:var(--gl-ink)">$1</h1>')
    .replace(/\*\*(.+?)\*\*/g,'<strong style="color:var(--gl-ink);font-weight:700">$1</strong>')
    .replace(/\*(.+?)\*/g,    '<em style="color:var(--gl-ink2)">$1</em>')
    .replace(/`(.+?)`/g,      '<code style="background:var(--gl-surface2);color:var(--gl-accent);padding:2px 7px;border-radius:5px;font-family:var(--gl-fm);font-size:.88em">$1</code>')
    .replace(/^> (.+)$/gm,    '<blockquote style="border-left:3px solid var(--gl-accent);padding:4px 0 4px 16px;color:var(--gl-ink2);margin:14px 0;font-style:italic">$1</blockquote>')
    .replace(/^- (.+)$/gm,    '<li style="margin:5px 0;color:var(--gl-ink2)">$1</li>')
    .replace(/\[(.+?)\]\((.+?)\)/g, '<a href="$2" target="_blank" rel="noreferrer" style="color:var(--gl-accent);text-decoration:underline;text-underline-offset:3px">$1</a>')
    .split(/\n\n+/).map(p => p.trim()).filter(Boolean)
    .map(p => /^<[h1-6buli]/.test(p) ? p : `<p style="color:var(--gl-ink2);line-height:1.85;font-weight:300;margin-bottom:16px">${p.replace(/\n/g,'<br>')}</p>`)
    .join('\n');
}

Object.assign(window, { GL_DATA, GL_LOAD, glDate, glMd });
