# Script to port Core templates to new JSON format
# Reconstructs all 11 core templates with full 23-element structure

$baseTemplate = Get-Content "src-tauri\templates\core\default.json" -Raw | ConvertFrom-Json

$coreTemplates = @(
    @{
        id="circus-sideshow"; name="Circus Sideshow"; category="Entertainment"; 
        desc="Big top aesthetic. Ornamental fonts with red and cream stripe vibes."; vibe="Fun, Ornamental, Striped";
        fonts="https://fonts.googleapis.com/css2?family=Rye&family=Sancreek&family=Roboto+Slab&display=swap";
        heading="Sancreek"; heading2="Rye"; body="Roboto Slab"; 
        text="212121"; accent="D32F2F"; bg="FFF8E1"; secondary="1A237E";
        h1Size=40; h1Align="center"; h1Color="D32F2F"; 
        h2Size=18; h2Align="center"; h2Color="1A237E";
        bodyAlign="center"
    },
    @{
        id="environmental-green"; name="Environmental Green"; category="Sustainability";
        desc="Nature-inspired design for environmental and sustainability communications. Organic feel with earthy green palette."; vibe="Natural, Sustainable, Organic";
        fonts="https://fonts.googleapis.com/css2?family=Bitter:wght@400;500;700&family=Karla:wght@400;500;700&display=swap";
        heading="Bitter"; heading2="Bitter"; body="Karla";
        text="3E4A3D"; accent="2E7D32"; bg="FFFFFF"; secondary="388E3C";
        h1Size=26; h1Align="left"; h1Color="2E7D32";
        h2Size=14; h2Align="left"; h2Color="388E3C";
        bodyAlign="left"
    },
    @{
        id="highway-interstate"; name="Highway Interstate"; category="Urban";
        desc="Road signage aesthetic. Reflective white text on deep highway green backgrounds."; vibe="Functional, Travel, Signage";
        fonts="https://fonts.googleapis.com/css2?family=Overpass:wght@400;700&family=Public+Sans:wght@400;700&display=swap";
        heading="Overpass"; heading2="Public Sans"; body="Public Sans";
        text="212121"; accent="00695C"; bg="FFFFFF"; secondary="004D40";
        h1Size=36; h1Align="left"; h1Color="FFFFFF"; h1Bg="00695C";
        h2Size=18; h2Align="left"; h2Color="004D40";
        bodyAlign="left"
    },
    @{
        id="jungle-explorer"; name="Jungle Explorer"; category="Adventure";
        desc="Safari expedition style. Khaki, olive drab, and canvas textures."; vibe="Adventure, Khaki, Nature";
        fonts="https://fonts.googleapis.com/css2?family=Stardos+Stencil&family=Domine:wght@400;700&display=swap";
        heading="Stardos Stencil"; heading2="Domine"; body="Domine";
        text="1B1B1B"; accent="827717"; bg="F0F4C3"; secondary="558B2F";
        h1Size=36; h1Align="left"; h1Color="33691E"; 
        h2Size=16; h2Align="left"; h2Color="558B2F";
        bodyAlign="left"
    },
    @{
        id="public-transit"; name="Public Transit"; category="Urban";
        desc="Subway map and transit signage aesthetic. Clean, highly legible sans-serifs with color-coded lines."; vibe="Urban, Functional, Color-coded";
        fonts="https://fonts.googleapis.com/css2?family=Mukta:wght@400;700&family=Hanken+Grotesk:wght@400;700&display=swap";
        heading="Hanken Grotesk"; heading2="Mukta"; body="Mukta";
        text="212121"; accent="FFC107"; bg="FFFFFF"; secondary="000000";
        h1Size=32; h1Align="left"; h1Color="000000";
        h2Size=18; h2Align="left"; h2Color="000000"; h2Bg="EEEEEE";
        bodyAlign="left"
    },
    @{
        id="silent-film-intertitle"; name="Silent Film Intertitle"; category="Cinema";
        desc="1920s cinema cards. White decorative text on black backgrounds with ornate borders."; vibe="Cinema, Vintage, Dramatic";
        fonts="https://fonts.googleapis.com/css2?family=Gye-Gye&family=Sorts+Mill+Goudy&display=swap";
        heading="Gye-Gye"; heading2="Sorts Mill Goudy"; body="Sorts Mill Goudy";
        text="000000"; accent="000000"; bg="FFFFFF"; secondary="212121";
        h1Size=32; h1Align="center"; h1Color="FFFFFF"; h1Bg="000000";
        h2Size=18; h2Align="center"; h2Color="EEEEEE"; h2Bg="212121";
        bodyAlign="center"; bodySize=14
    },
    @{
        id="sports-dynamic"; name="Sports Dynamic"; category="Sports";
        desc="Energetic and bold design for sports and athletic content. Dynamic typography with high-impact colors."; vibe="Energetic, Bold, Athletic";
        fonts="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Rubik:wght@400;500;700&display=swap";
        heading="Bebas Neue"; heading2="Rubik"; body="Rubik";
        text="333333"; accent="D32F2F"; bg="FFFFFF"; secondary="1A1A1A";
        h1Size=36; h1Align="left"; h1Color="D32F2F";
        h2Size=14; h2Align="left"; h2Color="1A1A1A";
        bodyAlign="left"
    },
    @{
        id="steampunk-inventor"; name="Steampunk Inventor"; category="Fantasy";
        desc="Brass and gear aesthetic. Victorian fonts with industrial metallic colors."; vibe="Mechanical, Brass, Victorian";
        fonts="https://fonts.googleapis.com/css2?family=Rye&family=Lora:wght@400;700&display=swap";
        heading="Rye"; heading2="Lora"; body="Lora";
        text="3E2723"; accent="B8860B"; bg="EFEBE9"; secondary="8D6E63";
        h1Size=30; h1Align="left"; h1Color="5D4037";
        h2Size=16; h2Align="left"; h2Color="8D6E63";
        bodyAlign="left"
    },
    @{
        id="subway-tile"; name="Subway Tile"; category="Urban";
        desc="Classic station ceramics. Clean white backgrounds, heavy black text, and tile-like framing."; vibe="Clean, Ceramic, Urban";
        fonts="https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;600&family=Lexend:wght@400;700&display=swap";
        heading="Lexend"; heading2="Work Sans"; body="Work Sans";
        text="424242"; accent="000000"; bg="FFFFFF"; secondary="212121";
        h1Size=36; h1Align="center"; h1Color="000000";
        h2Size=16; h2Align="left"; h2Color="212121";
        bodyAlign="left"
    },
    @{
        id="taxi-cab"; name="Taxi Cab"; category="Urban";
        desc="Yellow cab aesthetic. Checkerboard patterns (simulated) and bold black on yellow."; vibe="Urban, Yellow, Bold";
        fonts="https://fonts.googleapis.com/css2?family=Archivo+Black&family=Roboto:wght@400;700&display=swap";
        heading="Archivo Black"; heading2="Roboto"; body="Roboto";
        text="212121"; accent="FFEB3B"; bg="212121"; secondary="000000";
        h1Size=36; h1Align="center"; h1Color="000000"; h1Bg="FFEB3B";
        h2Size=18; h2Align="center"; h2Color="000000"; h2Bg="FFFFFF";
        bodyAlign="left"; bodyColor="FFFFFF"; bodySize=12
    },
    @{
        id="varsity-team"; name="Varsity Team"; category="Sport";
        desc="College sports jersey style. Block lettering with athletic gold and navy."; vibe="Athletic, College, Bold";
        fonts="https://fonts.googleapis.com/css2?family=Graduate&family=Saira:wght@400;700&display=swap";
        heading="Graduate"; heading2="Saira"; body="Saira";
        text="212121"; accent="FDD835"; bg="FFFFFF"; secondary="1A237E";
        h1Size=36; h1Align="center"; h1Color="FDD835"; h1Bg="1A237E";
        h2Size=20; h2Align="center"; h2Color="1A237E";
        bodyAlign="center"; bodySize=12
    }
)

foreach ($t in $coreTemplates) {
    $new = $baseTemplate.PSObject.Copy()
    
    # Metadata
    $new.id = $t.id
    $new.name = $t.name
    $new.category = $t.category
    $new.description = $t.desc
    $new.vibe = $t.vibe
    $new.googleFontsImport = $t.fonts
    
    # Typography
    $new.typography.colors.text = $t.text
    $new.typography.colors.accent = $t.accent
    $new.typography.colors.background = $t.bg
    $new.typography.colors.textSecondary = $t.secondary
    $new.typography.colors.blockquoteBorder = $t.accent
    
    $new.typography.fonts.heading = $t.heading
    $new.typography.fonts.body = $t.body
    
    # Elements - H1
    $new.elements.h1.font = "heading"
    $new.elements.h1.size = $t.h1Size
    $new.elements.h1.align = $t.h1Align
    $new.elements.h1.color = if ($t.h1Color) { $t.h1Color } else { "text" }
    
    if ($t.h1Bg) {
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "background" -Value $t.h1Bg -Force
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "padding" -Value 16 -Force
    }
    
    # Elements - H2
    $new.elements.h2.font = if ($t.heading2) { $t.heading2 } else { "heading" }
    $new.elements.h2.size = $t.h2Size
    $new.elements.h2.align = $t.h2Align
    $new.elements.h2.color = if ($t.h2Color) { $t.h2Color } else { "textSecondary" }
    
    if ($t.h2Bg) {
        $new.elements.h2 | Add-Member -MemberType NoteProperty -Name "background" -Value $t.h2Bg -Force
        $new.elements.h2 | Add-Member -MemberType NoteProperty -Name "padding" -Value 8 -Force
        $new.elements.h2 | Add-Member -MemberType NoteProperty -Name "display" -Value "inline-block" -Force
    }
    
    # Elements - Body
    $new.elements.p.align = $t.bodyAlign
    $new.elements.p.color = if ($t.bodyColor) { $t.bodyColor } else { "text" }
    if ($t.bodySize) { $new.elements.p.size = $t.bodySize }
    
    # Special borders
    if ($t.id -eq "highway-interstate") {
        $borderVal = @{ top=@{color="FFFFFF"; width=2; style="single"}; bottom=@{color="FFFFFF"; width=2; style="single"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "jungle-explorer") {
        $borderVal = @{ bottom=@{color="827717"; width=4; style="solid"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "public-transit") {
        $borderVal = @{ bottom=@{color="FFC107"; width=6; style="solid"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "silent-film-intertitle") {
        $borderVal = @{ top=@{color="FFFFFF"; width=4; style="double"}; bottom=@{color="FFFFFF"; width=4; style="double"}; left=@{color="FFFFFF"; width=4; style="double"}; right=@{color="FFFFFF"; width=4; style="double"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "steampunk-inventor") {
        $borderVal = @{ bottom=@{color="B8860B"; width=6; style="double"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "subway-tile") {
        $borderVal = @{ top=@{color="000000"; width=4; style="solid"}; bottom=@{color="000000"; width=4; style="solid"}; left=@{color="000000"; width=4; style="solid"}; right=@{color="000000"; width=4; style="solid"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "taxi-cab") {
        $borderVal = @{ top=@{color="000000"; width=6; style="dashed"}; bottom=@{color="000000"; width=6; style="dashed"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }
    if ($t.id -eq "varsity-team") {
        $borderVal = @{ top=@{color="FDD835"; width=4; style="solid"}; bottom=@{color="FDD835"; width=4; style="solid"} }
        $new.elements.h1 | Add-Member -MemberType NoteProperty -Name "border" -Value $borderVal -Force
    }


    # Save file
    $path = "src-tauri\templates\core\$($t.id).json"
    $json = $new | ConvertTo-Json -Depth 10
    [System.IO.File]::WriteAllLines($path, $json)
    Write-Host "✅ Created $path" -ForegroundColor Green
}
