// Data: block library per output type, i18n, helpers
// Each block: { id, label, thumb, phrase, hint? }
// Categories: { id, label, color, items[] }

const BLOCK_DATA = {
  image: {
    icon: 'image',
    label: { th: 'รูปภาพ', en: 'Image' },
    subjectPh: { th: 'อยากได้รูปอะไร? เช่น "เชฟหนุ่มถือเส้นพาสต้า"', en: 'What do you want? e.g. "young chef holding pasta"' },
    contextPh: { th: 'อยู่ตรงไหน? บรรยากาศแบบไหน? เช่น "ยืนอยู่หน้าเตารีดสถานตะวันตก ไอน้ำลอยขึ้นจากพาสต้า สีหน้ายิ้มมีความสุข"', en: 'Where? What\'s the atmosphere? e.g. "in an old Italian kitchen at sunset, steam rising from the pasta, joyful expression"' },
    categories: [
      { id: 'style', label: { th: 'สไตล์', en: 'Style' }, color: '#4a7eff', items: [
        { id: 'cinematic',  label: 'Cinematic',   thumb: 'cinematic',  phrase: 'cinematic shot, film grain', desc: 'ภาพสไตล์หนัง มีเกรนฟิล์ม สีโทนอุ่น เหมือนถ่ายด้วยกล้องภาพยนตร์' },
        { id: 'portrait',   label: 'Studio',      thumb: 'portrait',   phrase: 'studio portrait, sharp focus', desc: 'ภาพถ่ายสตูดิโอ โฟกัสคมชัด พื้นหลังสะอาด เน้นใบหน้า/ตัวแบบ' },
        { id: 'anime',      label: 'Anime',       thumb: 'anime',      phrase: 'anime style, cel-shaded', desc: 'สไตล์อนิเมะญี่ปุ่น เส้นขอบชัด ระบายสีแบบ cel-shading' },
        { id: 'product',    label: 'Product',     thumb: 'product',    phrase: 'product photography, clean background', desc: 'ถ่ายสินค้า พื้นขาวสะอาด แสงสว่างทั่ว เหมาะโฆษณา/ร้านค้าออนไลน์' },
        { id: 'landscape',  label: 'Landscape',   thumb: 'landscape',  phrase: 'epic landscape, wide vista', desc: 'ทิวทัศน์กว้างไกล มุมมองพาโนรามา ดูยิ่งใหญ่อลังการ' },
        { id: 'abstract',   label: 'Abstract',    thumb: 'abstract',   phrase: 'abstract composition', desc: 'ศิลปะนามธรรม รูปทรง สี เส้นสาย ไม่เน้นสิ่งจริง เน้นอารมณ์' },
        { id: 'pixel',      label: 'Pixel art',   thumb: 'pixel',      phrase: '16-bit pixel art', desc: 'พิกเซลอาร์ตแบบเกมยุค 16-bit สไตล์ SNES/Mega Drive' },
        { id: 'watercolor', label: 'Watercolor',  thumb: 'abstract',   phrase: 'watercolor painting, soft edges', desc: 'สีน้ำ ขอบนุ่ม สีซึมเบลนด์ ให้ความรู้สึกละมุนเหมือนวาดมือ' },
      ]},
      { id: 'light', label: { th: 'แสง', en: 'Lighting' }, color: '#ff6b5b', items: [
        { id: 'golden', label: 'Golden hour',  thumb: 'cinematic',  phrase: 'golden hour, warm sunlight', desc: 'แสงชั่วโมงทอง ช่วงพระอาทิตย์ใกล้ตก แสงส้มอุ่น เงานุ่ม' },
        { id: 'studio', label: 'Studio',       thumb: 'product',    phrase: 'studio lighting, softbox', desc: 'แสงสตูดิโอจาก softbox แสงนุ่มสม่ำเสมอ ไม่มีเงาแข็ง' },
        { id: 'neon',   label: 'Neon',         thumb: 'abstract',   phrase: 'neon glow, cyberpunk lighting', desc: 'แสงนีออนสีสด ฟ้า ชมพู ม่วง สไตล์ cyberpunk ยุคอนาคต' },
        { id: 'soft',   label: 'Soft natural', thumb: 'portrait',   phrase: 'soft natural light', desc: 'แสงธรรมชาตินุ่ม เหมือนแสงจากหน้าต่าง ให้ผิวสวยเป็นธรรมชาติ' },
        { id: 'dramatic', label: 'Dramatic',   thumb: 'cinematic',  phrase: 'dramatic chiaroscuro lighting', desc: 'แสง-เงาตัดกันรุนแรง สไตล์ภาพวาดยุคเรอเนสซองส์ ลึกลับ ดราม่า' },
        { id: 'backlit', label: 'Backlit',     thumb: 'landscape',  phrase: 'backlit, lens flare', desc: 'แสงส่องจากด้านหลังตัวแบบ ขอบตัวเรืองแสง มี lens flare' },
      ]},
      { id: 'cam', label: { th: 'มุมกล้อง', en: 'Camera' }, color: '#1f8a5b', items: [
        { id: '35mm',   label: '35mm film',  thumb: 'cinematic', phrase: 'shot on 35mm film', desc: 'ถ่ายด้วยฟิล์ม 35mm มีเกรน สีฟิล์มคลาสสิก โบเก้สวย' },
        { id: 'wide',   label: 'Wide angle', thumb: 'landscape', phrase: 'wide angle, 24mm', desc: 'เลนส์มุมกว้าง 24mm จับภาพได้กว้าง เหมาะถ่ายสถาปัตยกรรม/ทิวทัศน์' },
        { id: 'macro',  label: 'Macro',      thumb: 'product',   phrase: 'macro lens, extreme close-up', desc: 'เลนส์มาโคร ถ่ายใกล้สุด เห็นรายละเอียดเล็กๆ ชัดมาก (ดอกไม้ แมลง เครื่องประดับ)' },
        { id: 'tele',   label: 'Telephoto',  thumb: 'portrait',  phrase: 'telephoto, compressed perspective', desc: 'เลนส์เทเล ซูมไกล บีบมุมมองแบน พื้นหลังเบลอสวย เหมาะถ่ายคน' },
        { id: 'drone',  label: 'Aerial',     thumb: 'landscape', phrase: 'aerial drone shot', desc: 'ถ่ายจากโดรนมุมสูง มองลงมาจากท้องฟ้า เห็นภาพรวมกว้าง' },
      ]},
      { id: 'mood', label: { th: 'อารมณ์', en: 'Mood' }, color: '#a259e6', items: [
        { id: 'dreamy', label: 'Dreamy',    thumb: 'abstract',  phrase: 'dreamy, ethereal atmosphere', desc: 'ฝันหวาน เบาหวิว เหมือนอยู่ในความฝัน สีพาสเทล หมอกบาง' },
        { id: 'moody',  label: 'Moody',     thumb: 'cinematic', phrase: 'moody, atmospheric', desc: 'บรรยากาศหนักแน่น มีมิติ โทนมืดเข้ม เงาเยอะ ลึกลับน่าค้นหา' },
        { id: 'joyful', label: 'Joyful',    thumb: 'portrait',  phrase: 'joyful, vibrant energy', desc: 'สดใส ร่าเริง สีสดจัด เต็มไปด้วยพลังบวกและรอยยิ้ม' },
        { id: 'calm',   label: 'Calm',      thumb: 'landscape', phrase: 'calm, serene mood', desc: 'สงบ เงียบ ผ่อนคลาย โทนสีเย็นนุ่ม เหมือนนั่งริมทะเลเช้าตรู่' },
        { id: 'noir',   label: 'Noir',      thumb: 'cinematic', phrase: 'film noir, high contrast', desc: 'สไตล์หนังฟิล์มนัวร์ ขาวดำ คอนทราสต์สูง เงามืดลึก บรรยากาศสืบสวน' },
      ]},
      { id: 'color', label: { th: 'สี', en: 'Color' }, color: '#ff9d00', items: [
        { id: 'warm',  label: 'Warm tones', thumb: 'cinematic', phrase: 'warm color palette', desc: 'โทนสีอุ่น — ส้ม แดง เหลือง น้ำตาล ให้ความรู้สึกอบอุ่น เป็นมิตร' },
        { id: 'cool',  label: 'Cool tones', thumb: 'landscape', phrase: 'cool color palette', desc: 'โทนสีเย็น — ฟ้า เขียว ม่วง ให้ความรู้สึกสงบ สดชื่น เป็นทางการ' },
        { id: 'mono',  label: 'B&W',        thumb: 'portrait',  phrase: 'black and white, monochrome', desc: 'ขาวดำ ไม่มีสี เน้นแสงเงาและเส้นสาย ดูคลาสสิก เหนือกาลเวลา' },
        { id: 'pastel',label: 'Pastel',     thumb: 'anime',     phrase: 'pastel palette', desc: 'สีพาสเทล — ชมพูอ่อน ฟ้าอ่อน เขียวมิ้นต์ ละมุน น่ารัก สบายตา' },
        { id: 'vivid', label: 'Vivid',      thumb: 'pixel',     phrase: 'vivid saturated colors', desc: 'สีสดจัดเข้ม อิ่มตัวสูง สะดุดตา เหมาะภาพโปสเตอร์/โฆษณา' },
      ]},
      { id: 'detail', label: { th: 'รายละเอียด', en: 'Detail' }, color: '#0ea5b7', items: [
        { id: 'hyper', label: 'Hyperreal', thumb: 'product',  phrase: 'hyperrealistic, ultra-detailed, 8K', desc: 'เหมือนจริงมาก ทุกรายละเอียดคมชัดระดับ 8K เหมือนถ่ายด้วยกล้องราคาแพง' },
        { id: 'intricate', label: 'Intricate', thumb: 'abstract', phrase: 'intricate details, fine textures', desc: 'รายละเอียดซับซ้อน ลวดลายวิจิตร พื้นผิวละเอียดยิบ' },
        { id: 'minimal', label: 'Minimal', thumb: 'abstract', phrase: 'minimalist composition', desc: 'มินิมอล เรียบง่าย ใช้องค์ประกอบน้อย เน้นพื้นที่ว่าง สะอาดตา' },
      ]},
      // ---- Imported from cheatsheets (merged at bootstrap) ----
    ],
  },

  text: {
    icon: 'text',
    label: { th: 'ข้อความ', en: 'Text' },
    subjectPh: { th: 'อยากเขียนเรื่องอะไร?', en: 'What do you want to write about?' },
    contextPh: { th: 'เป้าหมายคือใคร? จะเอาไปใช้ที่ไหน? มีข้อมูลอะไรพิเศษไหม?', en: 'Who\'s the audience? Where will it be used? Any specific angle?' },
    categories: [
      { id: 'format', label: { th: 'รูปแบบ', en: 'Format' }, color: '#4a7eff', items: [
        { id: 'email',   label: 'Email',         thumb: 'text', phrase: 'as a well-structured email', desc: 'เขียนเป็นอีเมล มีหัวเรื่อง เนื้อหา ลงท้าย' },
        { id: 'blog',    label: 'Blog post',     thumb: 'text', phrase: 'as a blog post with intro, body, conclusion', desc: 'เขียนเป็นบทความบล็อก มีเปิดเรื่อง เนื้อหา สรุป' },
        { id: 'tweet',   label: 'Tweet',         thumb: 'text', phrase: 'as a single tweet under 280 chars', desc: 'โพสต์สั้นไม่เกิน 280 ตัวอักษร แบบ X/Twitter' },
        { id: 'thread',  label: 'Twitter thread',thumb: 'text', phrase: 'as a 5-tweet thread', desc: 'ชุดโพสต์ต่อเนื่อง 5 ข้อความ อ่านเป็นเรื่อง' },
        { id: 'summary', label: 'Summary',       thumb: 'text', phrase: 'as a concise summary', desc: 'สรุปย่อ จับใจความสำคัญ สั้นกระชับ' },
        { id: 'outline', label: 'Outline',       thumb: 'text', phrase: 'as a hierarchical outline', desc: 'โครงร่างเป็นหัวข้อย่อย แบ่งชั้น เห็นภาพรวม' },
        { id: 'bullets', label: 'Bullet points', thumb: 'text', phrase: 'as scannable bullet points', desc: 'เขียนเป็นข้อๆ อ่านง่าย ไล่สายตาได้เร็ว' },
        { id: 'story',   label: 'Short story',   thumb: 'text', phrase: 'as a short narrative story', desc: 'เขียนเป็นเรื่องสั้น มีตัวละคร เหตุการณ์ บทสนทนา' },
      ]},
      { id: 'tone', label: { th: 'โทน', en: 'Tone' }, color: '#ff6b5b', items: [
        { id: 'friendly', label: 'Friendly',    thumb: 'text', phrase: 'in a warm friendly tone', desc: 'อบอุ่น เป็นกันเอง เหมือนคุยกับเพื่อน' },
        { id: 'pro',      label: 'Professional',thumb: 'text', phrase: 'in a professional tone', desc: 'ทางการ สุภาพ น่าเชื่อถือ เหมาะใช้ในที่ทำงาน' },
        { id: 'casual',   label: 'Casual',      thumb: 'text', phrase: 'in a casual conversational tone', desc: 'สบายๆ ภาษาพูด ไม่เป็นทางการ' },
        { id: 'witty',    label: 'Witty',       thumb: 'text', phrase: 'with wit and light humor', desc: 'มีมุก ตลกเบาๆ ฉลาดแกมโกง อ่านแล้วยิ้ม' },
        { id: 'persuade', label: 'Persuasive',  thumb: 'text', phrase: 'in a persuasive tone with strong CTA', desc: 'โน้มน้าว ชักจูง มีปุ่มกดหรือคำเชิญชวนให้ทำอะไรบางอย่าง' },
        { id: 'empathy',  label: 'Empathetic',  thumb: 'text', phrase: 'with empathy and care', desc: 'เห็นอกเห็นใจ ใส่ใจความรู้สึกผู้อ่าน อ่อนโยน' },
      ]},
      { id: 'audience', label: { th: 'กลุ่มเป้าหมาย', en: 'Audience' }, color: '#1f8a5b', items: [
        { id: 'general', label: 'General',    thumb: 'text', phrase: 'for a general audience', desc: 'คนทั่วไป ไม่ต้องมีความรู้เฉพาะทาง' },
        { id: 'tech',    label: 'Technical',  thumb: 'code', phrase: 'for a technical audience', desc: 'คนที่มีความรู้ด้านเทคโนโลยี ใช้ศัพท์เทคนิคได้' },
        { id: 'exec',    label: 'Executives', thumb: 'chart',phrase: 'for busy executives — lead with the bottom line', desc: 'ผู้บริหารที่ไม่มีเวลา ขึ้นต้นด้วยสรุป ตามด้วยรายละเอียด' },
        { id: 'student', label: 'Students',   thumb: 'text', phrase: 'for students learning the topic', desc: 'นักเรียน/นักศึกษา อธิบายชัดเจน มีตัวอย่าง' },
        { id: 'kid',     label: 'Kids',       thumb: 'text', phrase: 'explained simply for a 10-year-old', desc: 'เด็ก 10 ขวบ ภาษาง่าย ไม่ซับซ้อน มีเปรียบเทียบ' },
      ]},
      { id: 'length', label: { th: 'ความยาว', en: 'Length' }, color: '#a259e6', items: [
        { id: 'one',  label: '1 sentence',  thumb: 'text', phrase: 'in exactly one sentence', desc: 'ประโยคเดียว สั้นมาก' },
        { id: 'short',label: '~50 words',   thumb: 'text', phrase: 'in about 50 words', desc: 'ย่อหน้าสั้นๆ อ่านจบใน 15 วินาที' },
        { id: 'med',  label: '~300 words',  thumb: 'text', phrase: 'in about 300 words', desc: 'บทความสั้น อ่านจบใน 2 นาที' },
        { id: 'long', label: '~1000 words', thumb: 'text', phrase: 'in about 1000 words', desc: 'บทความยาว อ่านจบใน 5-7 นาที' },
      ]},
      { id: 'lang', label: { th: 'ภาษา', en: 'Language' }, color: '#ff9d00', items: [
        { id: 'en', label: 'English',  thumb: 'text', phrase: 'in English', desc: 'เขียนเป็นภาษาอังกฤษ' },
        { id: 'th', label: 'ภาษาไทย',  thumb: 'text', phrase: 'in Thai (ภาษาไทย, สำนวนเป็นธรรมชาติ)', desc: 'เขียนเป็นภาษาไทย สำนวนธรรมชาติ' },
        { id: 'bi', label: 'Bilingual',thumb: 'text', phrase: 'in both English and Thai', desc: 'เขียนทั้ง 2 ภาษา ไทยและอังกฤษ' },
      ]},
      { id: 'aimode', label: { th: 'สั่ง AI', en: 'AI Control' }, color: '#e0489a', items: [
        { id: 'direct',   label: 'No filler',     thumb: 'text', phrase: 'answer directly — no filler, no preamble', desc: 'ตอบตรงประเด็นทันที ไม่มีน้ำ ไม่เกริ่นนำ' },
        { id: 'verify',   label: 'Verify facts',  thumb: 'text', phrase: 'verify every claim against the source material; if unsure, say so explicitly', desc: 'ตรวจทุกข้อเท็จจริงกับแหล่งข้อมูล ไม่แน่ใจให้บอกตรงๆ ลดการมั่ว (จาก Fable 5 guide)' },
        { id: 'evidence', label: 'Evidence only', thumb: 'text', phrase: 'only state things you can point to evidence for — never invent facts', desc: 'พูดเฉพาะสิ่งที่มีหลักฐานชี้ได้ ห้ามแต่งข้อมูลเอง' },
        { id: 'scope',    label: 'Stay in scope', thumb: 'text', phrase: "don't add anything beyond what was asked", desc: 'ทำเฉพาะที่ขอ ไม่เพิ่มเติมเกินคำสั่ง' },
        { id: 'examples', label: 'With examples', thumb: 'text', phrase: 'support each main point with a concrete example', desc: 'ทุกประเด็นหลักมีตัวอย่างจริงประกอบ เข้าใจง่ายขึ้น' },
        { id: 'why',      label: 'Explain why',   thumb: 'text', phrase: 'briefly explain the reasoning behind each recommendation', desc: 'อธิบายเหตุผลสั้นๆ ประกอบทุกข้อแนะนำ' },
      ]},
    ],
  },

  code: {
    icon: 'code',
    label: { th: 'โค้ด', en: 'Code' },
    subjectPh: { th: 'อยากให้เขียนอะไร? เช่น "ฟอร์ม login พร้อม validation"', en: 'What to build? e.g. "login form with validation"' },
    contextPh: { th: 'อยู่ในโปรเจคต์ไหน? มี constraints อะไร? จะ integrate กับระบบอะไรบ้าง?', en: 'Which codebase / framework already? Constraints? What does it integrate with?' },
    categories: [
      { id: 'lang', label: { th: 'ภาษา', en: 'Language' }, color: '#4a7eff', items: [
        { id: 'ts',   label: 'TypeScript', thumb: 'code', phrase: 'in TypeScript with strict types', desc: 'ภาษา TypeScript กำหนดชนิดข้อมูลชัดเจน ลดบั๊ก' },
        { id: 'js',   label: 'JavaScript', thumb: 'code', phrase: 'in modern JavaScript (ES2023)', desc: 'ภาษา JavaScript รุ่นใหม่ ใช้ได้ทั้งเว็บและแอป' },
        { id: 'py',   label: 'Python',     thumb: 'code', phrase: 'in Python 3.12 with type hints', desc: 'ภาษา Python อ่านง่าย เหมาะงาน AI และวิเคราะห์ข้อมูล' },
        { id: 'sql',  label: 'SQL',        thumb: 'code', phrase: 'as a SQL query (PostgreSQL dialect)', desc: 'ภาษาจัดการฐานข้อมูล ดึง/เพิ่ม/แก้ข้อมูลในตาราง' },
        { id: 'go',   label: 'Go',         thumb: 'code', phrase: 'in Go, idiomatic style', desc: 'ภาษา Go ทำงานเร็ว เหมาะระบบหลังบ้านขนาดใหญ่' },
        { id: 'rs',   label: 'Rust',       thumb: 'code', phrase: 'in Rust, idiomatic style', desc: 'ภาษา Rust ปลอดภัย เร็วมาก เหมาะงานที่ต้องการประสิทธิภาพสูง' },
        { id: 'swift',label: 'Swift',      thumb: 'code', phrase: 'in Swift 5 / SwiftUI', desc: 'ภาษา Swift สำหรับสร้างแอป iPhone/iPad/Mac' },
      ]},
      { id: 'fw', label: { th: 'เฟรมเวิร์ค', en: 'Framework' }, color: '#ff6b5b', items: [
        { id: 'react', label: 'React',    thumb: 'code', phrase: 'using React 18 + hooks', desc: 'เครื่องมือสร้างหน้าเว็บ ของ Meta ใช้กันแพร่หลายมาก' },
        { id: 'next',  label: 'Next.js',  thumb: 'code', phrase: 'using Next.js 14 (app router)', desc: 'ต่อยอดจาก React เว็บโหลดเร็ว ติดอันดับ Google ดี' },
        { id: 'vue',   label: 'Vue',      thumb: 'code', phrase: 'using Vue 3 composition API', desc: 'เครื่องมือสร้างเว็บ เรียนง่าย เริ่มต้นเร็ว' },
        { id: 'svelte',label: 'Svelte',   thumb: 'code', phrase: 'using SvelteKit', desc: 'เครื่องมือสร้างเว็บรุ่นใหม่ เบา เร็ว เขียนน้อยได้มาก' },
        { id: 'fastapi',label:'FastAPI',  thumb: 'code', phrase: 'using FastAPI', desc: 'เครื่องมือ Python สร้างระบบหลังบ้าน (API) ได้เร็ว' },
        { id: 'none',  label: 'No framework', thumb: 'code', phrase: 'with no framework dependencies', desc: 'ไม่ใช้เครื่องมือเสริม เขียนโค้ดล้วนๆ' },
      ]},
      { id: 'pattern', label: { th: 'แนวทาง', en: 'Pattern' }, color: '#1f8a5b', items: [
        { id: 'clean',  label: 'Clean code',  thumb: 'code', phrase: 'follow clean-code principles', desc: 'โค้ดเป็นระเบียบ อ่านง่าย แก้ไขทีหลังได้สะดวก' },
        { id: 'fn',     label: 'Functional',  thumb: 'code', phrase: 'use functional patterns', desc: 'เขียนแบบแยกเป็นฟังก์ชันย่อยๆ ไม่ยุ่งกัน' },
        { id: 'oop',    label: 'OOP',         thumb: 'code', phrase: 'use OOP / classes', desc: 'เขียนแบบจัดกลุ่มเป็นก้อนๆ เหมาะระบบใหญ่' },
        { id: 'perf',   label: 'Performant',  thumb: 'code', phrase: 'optimize for performance', desc: 'เน้นความเร็ว ทำงานไว ไม่กินทรัพยากร' },
        { id: 'a11y',   label: 'Accessible',  thumb: 'code', phrase: 'fully accessible (ARIA, keyboard nav)', desc: 'ทุกคนใช้ได้ รวมถึงผู้พิการ ใช้คีย์บอร์ดได้' },
      ]},
      { id: 'inc', label: { th: 'รวม', en: 'Include' }, color: '#a259e6', items: [
        { id: 'tests',   label: 'Tests',       thumb: 'code', phrase: 'include unit tests', desc: 'มีชุดทดสอบ ตรวจว่าโค้ดทำงานถูกต้อง' },
        { id: 'comments',label: 'Comments',    thumb: 'code', phrase: 'include explanatory comments', desc: 'มีคำอธิบายในโค้ด อ่านแล้วเข้าใจว่าทำอะไร' },
        { id: 'errors',  label: 'Error handling',thumb:'code',phrase: 'include robust error handling', desc: 'จัดการข้อผิดพลาด ไม่พังเมื่อเจอปัญหา' },
        { id: 'types',   label: 'Types',       thumb: 'code', phrase: 'include full type definitions', desc: 'กำหนดชนิดข้อมูลชัดเจน ลดข้อผิดพลาด' },
        { id: 'docs',    label: 'JSDoc',       thumb: 'code', phrase: 'include JSDoc comments', desc: 'มีเอกสารอธิบายในโค้ด สร้างคู่มือได้อัตโนมัติ' },
      ]},
      { id: 'aimode', label: { th: 'สั่ง AI', en: 'AI Control' }, color: '#e0489a', items: [
        { id: 'scope',  label: 'No extra features', thumb: 'code', phrase: "don't add features or abstractions beyond what the task requires", desc: 'ห้ามเพิ่มฟีเจอร์/โครงสร้างเกินที่สั่ง กัน AI refactor เกิน (จาก Fable 5 guide)' },
        { id: 'verify', label: 'Verify before done', thumb: 'code', phrase: 'run and verify the code before declaring it done — only report results you can show', desc: 'ต้องรัน/ทดสอบจริงก่อนบอกว่าเสร็จ รายงานเฉพาะผลที่พิสูจน์ได้' },
        { id: 'act',    label: 'Act, don\'t overplan', thumb: 'code', phrase: 'when you have enough information to act, act — don\'t overplan', desc: 'มีข้อมูลพอแล้วให้ลงมือเลย ไม่ต้องวางแผนวนไปมา' },
        { id: 'assess', label: 'Assess first',  thumb: 'code', phrase: "if I'm describing a problem, give an assessment first — don't jump to fixing", desc: 'ถ้าเล่าปัญหาให้วิเคราะห์ก่อน อย่าเพิ่งรีบแก้โค้ด' },
        { id: 'surgical', label: 'Surgical fix', thumb: 'code', phrase: 'make the smallest targeted change — do not restructure surrounding code', desc: 'แก้เฉพาะจุดเล็กที่สุด ไม่รื้อโค้ดรอบข้าง' },
        { id: 'match',  label: 'Match codebase', thumb: 'code', phrase: 'match the existing code style, naming, and idioms of the codebase', desc: 'เขียนให้กลมกลืนกับสไตล์โค้ดเดิมของโปรเจค' },
      ]},
    ],
  },

  video: {
    icon: 'video',
    label: { th: 'วิดีโอ', en: 'Video' },
    subjectPh: { th: 'อยากได้วิดีโอเกี่ยวกับอะไร?', en: 'What video do you want? e.g. "a cat running through a meadow"' },
    contextPh: { th: 'บรรยากาศไหน สถานที่ไหน อะไรเกิดขึ้น?', en: 'What setting? What\'s happening in the scene?' },
    categories: [
      { id: 'style', label: { th: 'สไตล์', en: 'Style' }, color: '#4a7eff', items: [
        { id: 'cinematic',label:'Cinematic',   thumb:'cinematic', phrase: 'cinematic, film look', desc: 'สไตล์ภาพยนตร์ สีสวย มุมกล้องดราม่า' },
        { id: 'vlog',     label:'Vlog',        thumb:'portrait',  phrase: 'casual vlog style', desc: 'สไตล์ Vlog ถ่ายเองสบายๆ เหมือนเล่าให้เพื่อนฟัง' },
        { id: 'mv',       label:'Music video', thumb:'abstract',  phrase: 'music video, rhythmic cuts', desc: 'มิวสิควิดีโอ ตัดภาพตามจังหวะเพลง' },
        { id: 'doc',      label:'Documentary', thumb:'landscape', phrase: 'documentary style, natural pacing', desc: 'สารคดี เล่าเรื่องจริง จังหวะเนิบ ดูน่าเชื่อถือ' },
        { id: 'ad',       label:'Commercial',  thumb:'product',   phrase: 'commercial ad polish', desc: 'โฆษณา ภาพสวยขัดเงา เน้นขายสินค้า/บริการ' },
      ]},
      { id: 'cam', label: { th: 'กล้อง', en: 'Camera move' }, color: '#ff6b5b', items: [
        { id: 'static', label:'Static',   thumb:'portrait',  phrase: 'static camera', desc: 'กล้องนิ่ง ไม่เคลื่อนที่ เน้นสิ่งที่เกิดขึ้นตรงหน้า' },
        { id: 'pan',    label:'Slow pan', thumb:'landscape', phrase: 'slow horizontal pan', desc: 'กล้องแพนช้าๆ หันซ้าย-ขวา เห็นภาพกว้างขึ้น' },
        { id: 'zoom',   label:'Zoom in',  thumb:'cinematic', phrase: 'slow zoom-in', desc: 'ซูมเข้าช้าๆ เน้นจุดสนใจ สร้างอารมณ์ลุ้น' },
        { id: 'dolly',  label:'Dolly',    thumb:'cinematic', phrase: 'smooth dolly forward', desc: 'กล้องเลื่อนเข้าหาตัวแบบนุ่มนวล ดูมืออาชีพ' },
        { id: 'drone',  label:'Aerial',   thumb:'landscape', phrase: 'aerial drone shot', desc: 'ถ่ายจากโดรนมุมสูง เห็นวิวกว้างจากท้องฟ้า' },
      ]},
      { id: 'dur', label: { th: 'ความยาว', en: 'Duration' }, color: '#1f8a5b', items: [
        { id: 's5',  label:'5 seconds',  thumb:'video', phrase: '5 second clip', desc: 'คลิปสั้น 5 วินาที เหมาะโพสต์โซเชียล' },
        { id: 's10', label:'10 seconds', thumb:'video', phrase: '10 second clip', desc: 'คลิป 10 วินาที ความยาวพอดี เล่าเรื่องสั้นๆ' },
        { id: 's30', label:'30 seconds', thumb:'video', phrase: '30 second clip', desc: 'คลิป 30 วินาที เล่าเรื่องได้ครบ เหมาะโฆษณา' },
      ]},
      { id: 'mood', label: { th: 'อารมณ์', en: 'Mood' }, color: '#a259e6', items: [
        { id: 'epic',   label:'Epic',      thumb:'landscape', phrase: 'epic, sweeping', desc: 'ยิ่งใหญ่ อลังการ เหมือนตัวอย่างหนังฮอลลีวูด' },
        { id: 'calm',   label:'Calm',      thumb:'landscape', phrase: 'calm, meditative', desc: 'สงบ ผ่อนคลาย เหมือนนั่งสมาธิริมน้ำ' },
        { id: 'energy', label:'Energetic', thumb:'pixel',     phrase: 'high energy, kinetic', desc: 'มีพลัง ตื่นเต้น เคลื่อนไหวเร็ว สนุกสนาน' },
        { id: 'mel',    label:'Melancholic',thumb:'cinematic',phrase: 'melancholic, introspective', desc: 'เศร้าเล็กๆ ครุ่นคิด ดูแล้วซึ้ง' },
      ]},
    ],
  },

  email: {
    icon: 'mail',
    label: { th: 'อีเมล', en: 'Email' },
    subjectPh: { th: 'อีเมลเรื่องอะไร? ถึงใคร?', en: 'What email? To whom? e.g. "intro email to a podcast host"' },
    contextPh: { th: 'มี background ระหว่างเรากับผู้รับยังไง? อยากได้อะไรหลังส่ง?', en: 'Any prior context with this person? What outcome do you want?' },
    categories: [
      { id: 'purpose', label: { th: 'จุดประสงค์', en: 'Purpose' }, color: '#4a7eff', items: [
        { id: 'cold',  label: 'Cold outreach', thumb: 'mail', phrase: 'cold outreach email', desc: 'ทักคนที่ไม่เคยรู้จักกันมาก่อน เสนอตัว' },
        { id: 'fu',    label: 'Follow-up',     thumb: 'mail', phrase: 'polite follow-up email', desc: 'ติดตามผล ทวงถามอย่างสุภาพ หลังส่งไปแล้ว' },
        { id: 'thanks',label: 'Thank you',     thumb: 'mail', phrase: 'thank-you email', desc: 'ขอบคุณ แสดงความซาบซึ้ง หลังได้รับความช่วยเหลือ' },
        { id: 'ann',   label: 'Announcement',  thumb: 'mail', phrase: 'announcement email', desc: 'ประกาศข่าว แจ้งเรื่องสำคัญให้หลายคนรู้' },
        { id: 'intro', label: 'Introduction',  thumb: 'mail', phrase: 'self-introduction email', desc: 'แนะนำตัว บอกว่าเราเป็นใคร ทำอะไร' },
        { id: 'pitch', label: 'Pitch',         thumb: 'mail', phrase: 'pitch email', desc: 'เสนอไอเดีย/สินค้า/บริการ ชวนให้สนใจ' },
      ]},
      { id: 'tone', label: { th: 'โทน', en: 'Tone' }, color: '#ff6b5b', items: [
        { id: 'warm',   label: 'Warm',         thumb: 'mail', phrase: 'warm, personable tone', desc: 'อบอุ่น จริงใจ เหมือนคุยกับคนคุ้นเคย' },
        { id: 'pro',    label: 'Professional', thumb: 'mail', phrase: 'formal professional tone', desc: 'ทางการ สุภาพ เหมาะส่งให้ลูกค้าหรือหัวหน้า' },
        { id: 'urgent', label: 'Urgent',       thumb: 'mail', phrase: 'respectfully urgent tone', desc: 'เร่งด่วนแต่สุภาพ บอกว่าต้องรีบตอบ' },
        { id: 'casual', label: 'Casual',       thumb: 'mail', phrase: 'casual conversational tone', desc: 'สบายๆ ภาษาพูด ไม่เป็นทางการ' },
      ]},
      { id: 'len', label: { th: 'ความยาว', en: 'Length' }, color: '#1f8a5b', items: [
        { id: 'short',label:'Short (~80w)', thumb: 'mail', phrase: 'keep it under 80 words', desc: 'สั้นกระชับ อ่านจบใน 30 วินาที' },
        { id: 'med',  label:'Medium (~150w)',thumb: 'mail', phrase: 'about 150 words', desc: 'ยาวพอดี อธิบายได้ครบ ไม่ยืดเยื้อ' },
        { id: 'long', label:'Long (~300w)',  thumb: 'mail', phrase: 'about 300 words', desc: 'ยาวละเอียด เหมาะเรื่องที่ต้องอธิบายเยอะ' },
      ]},
      { id: 'inc', label: { th: 'รวม', en: 'Include' }, color: '#a259e6', items: [
        { id: 'cta',     label: 'Clear CTA',    thumb: 'mail', phrase: 'with one clear call-to-action', desc: 'มีปุ่มหรือคำชวนให้ผู้อ่านทำอะไรบางอย่างชัดเจน' },
        { id: 'subj',    label: 'Subject line', thumb: 'mail', phrase: 'and suggest 3 subject lines', desc: 'แนะนำหัวข้ออีเมล 3 แบบให้เลือก' },
        { id: 'sig',     label: 'Signature',    thumb: 'mail', phrase: 'and include a friendly sign-off', desc: 'มีลงท้ายสุภาพ เช่น ขอแสดงความนับถือ' },
        { id: 'options', label: '3 versions',   thumb: 'mail', phrase: 'and provide 3 variations', desc: 'ให้ 3 เวอร์ชันเปรียบเทียบ เลือกได้ตามชอบ' },
      ]},
    ],
  },
};

// Build prompt string from subject + context + selected blocks
function composePrompt(typeId, subject, context, selectedBlocks) {
  const t = BLOCK_DATA[typeId];
  const parts = [];
  const subj = (subject || '').trim();
  const ctx = (context || '').trim();
  if (subj) parts.push(subj);
  if (ctx) {
    // For image/video — comma-style. For text/code/email — natural phrasing.
    if (typeId === 'image' || typeId === 'video') {
      parts.push(ctx);
    } else {
      parts.push('Context: ' + ctx);
    }
  }
  for (const b of selectedBlocks) parts.push(b.phrase);
  if (!parts.length) {
    return typeId === 'image'
      ? '(start by typing what you want, then tap blocks below to add style/lighting/mood…)'
      : '(type your topic, then tap blocks to refine the prompt)';
  }
  return parts.join(', ');
}

// i18n strings
const STRINGS = {
  th: {
    appName: 'Autoprompt',
    extract: 'ถอดรูป',
    livePreview: 'Preview สด',
    subject: 'อยากได้อะไร?',
    context: 'บริบท / รายละเอียด',
    contextHint: { th: 'อธิบายฉากรรม / อารมณ์ / จุดประสงค์ ช่วยให้ AI เข้าใจมากขึ้น (ไม่บังคับ)', en: 'Describe the scene / mood / purpose so the AI understands better (optional)' },
    output: 'รูปแบบผลลัพธ์',
    stack: 'บล็อคของคุณ',
    library: 'คลังบล็อค',
    addMore: 'แตะเพื่อเพิ่ม',
    random: 'สุ่ม',
    randomEmpty: 'สุ่มช่องว่าง',
    randomCat: 'สุ่มจากหมวดนี้',
    context: 'บริบท / ฉาก',
    optional: '(ไม่บังคับ)',
    contextTip: 'ยิ่งบอกบริบทละเอียด AI ยิ่งเข้าใจว่าต้องการอะไร',
    copy: 'คัดลอก',
    copied: 'คัดลอกแล้ว ✓',
    save: 'บันทึก',
    share: 'แชร์',
    saved: 'บันทึกแล้ว ★',
    clear: 'ล้างทั้งหมด',
    empty: '(ยังไม่มีบล็อค — แตะที่คลังด้านล่างเพื่อเพิ่ม)',
    history: 'ประวัติ',
    favorites: 'ที่บันทึก',
    home: 'หน้าหลัก',
    build: 'สร้าง',
    settings: 'ตั้งค่า',
    account: 'บัญชี',
    newPrompt: '+ สร้าง prompt ใหม่',
    noHistory: 'ยังไม่มีประวัติ — กด "บันทึก" ใน prompt ใดก็ได้',
    enhance: 'เกลาด้วย AI',
    enhancing: 'กำลังเกลา…',
    showThumb: 'แสดงตัวอย่าง',
    delete: 'ลบ',
    moveUp: 'ขึ้น',
    moveDown: 'ลง',
  },
  en: {
    appName: 'Autoprompt',
    extract: 'Extract',
    livePreview: 'Live preview',
    subject: 'What do you want?',
    context: 'Context / Scene',
    contextHint: { th: 'อธิบายฉากรรม / อารมณ์ / จุดประสงค์ (ไม่บังคับ)', en: 'Describe the scene / mood / purpose (optional)' },
    output: 'Output type',
    stack: 'Your stack',
    library: 'Block library',
    addMore: 'Tap to add',
    random: 'Random',
    randomEmpty: 'Fill empty',
    randomCat: 'Random from this',
    context: 'Context / Scene',
    optional: '(optional)',
    contextTip: 'The more context you give, the better the AI understands your intent',
    copy: 'Copy',
    copied: 'Copied ✓',
    save: 'Save',
    share: 'Share',
    saved: 'Saved ★',
    clear: 'Clear all',
    empty: '(no blocks yet — tap the library below to add)',
    history: 'History',
    favorites: 'Saved',
    home: 'Home',
    build: 'Build',
    settings: 'Settings',
    account: 'Account',
    newPrompt: '+ New prompt',
    noHistory: 'No saved prompts yet — tap Save on any prompt',
    enhance: 'Enhance with AI',
    enhancing: 'Enhancing…',
    showThumb: 'Show previews',
    delete: 'Remove',
    moveUp: 'Up',
    moveDown: 'Down',
  },
};

Object.assign(window, { BLOCK_DATA, composePrompt, STRINGS });

// ---- Merge imported cheatsheets into Image type ----
(function mergeCheatsheets() {
  if (!window.CHEATSHEET) return;
  const cs = window.CHEATSHEET;
  const imageCats = BLOCK_DATA.image.categories;
  // SD categories (lighting, angle, pose, etc.)
  for (const c of cs.sdCats) {
    const existing = imageCats.find(x => x.id === c.id);
    if (existing) {
      // merge items into existing category, avoiding dup ids
      const seen = new Set(existing.items.map(i => i.id));
      for (const it of c.items) if (!seen.has(it.id)) {
        existing.items.push({ ...it, thumb: it.thumb || 'abstract' });
      }
    } else {
      imageCats.push({ id: c.id, label: c.label, color: c.color, items: c.items.map(i => ({ ...i, thumb: 'abstract' })) });
    }
  }
  // Big categories — hair + body — get their own thumb hints
  const thumbMap = { hairF: 'portrait', hairM: 'portrait', bodyF: 'portrait', bodyM: 'portrait' };
  for (const key of ['hairF', 'hairM', 'bodyF', 'bodyM']) {
    const blk = cs.blocks[key];
    if (!blk) continue;
    imageCats.push({
      id: key,
      label: blk.label,
      color: blk.color,
      items: blk.items.map(i => ({ ...i, thumb: thumbMap[key] || 'portrait' })),
      bigCat: false,
    });
  }
})();
