#!/usr/bin/env python3
"""
Devlin Checkout Geo Flash — WordPress.org listing asset generator.

Design tokens and layout follow docs/DESIGN-SYSTEM.md §7 exactly.
Produces the authoritative icon, banner, screenshot PNGs, and SVG sources for
submission directly in the .wordpress-org folder root.

Run: python3 .wordpress-org/generate_assets.py
Requires: cairosvg  (pip install cairosvg)
"""
import pathlib
import sys

import cairosvg

sys.dont_write_bytecode = True

ROOT = pathlib.Path(__file__).parent

# ── Design tokens (DESIGN-SYSTEM.md §7.1) ─────────────────────────────────
PAPER      = "#f7f1e3"
PAPER_STR  = "#efe4d0"
PAPER_LT   = "#fffcf7"
INK        = "#1c2220"
MUTED      = "#5c665d"
ACCENT     = "#8b5e34"
ACCENT_S   = "#4d2f1b"
GREEN      = "#375947"
RED        = "#b44f2f"
WARN       = "#b1772f"

# WP admin chrome colours
WP_DARK    = "#1d2327"
WP_BLUE    = "#2271b1"
WP_MUTED   = "#a8b1b8"
WP_WHITE   = "#ffffff"
WP_BODY    = "#f0f0f1"
WP_SUB_BG  = "#101517"

# Storefront / toast colours
SF_BG      = "#f9fafb"
TOAST_BG   = "#ffffff"
TOAST_BD   = "#e5e7eb"
TOAST_EYE  = "#6b7280"
TOAST_TTL  = "#111827"
TOAST_SHAD = "rgba(15,23,42,0.12)"

# Fonts (DESIGN-SYSTEM.md §7.2 – system stacks, no remote dependencies)
F_SERIF = "Iowan Old Style, Georgia, serif"
F_MONO  = "American Typewriter, Courier New, monospace"
F_SANS  = "Avenir Next, Segoe UI, sans-serif"


def export(svg: str, src_name: str, sizes: list) -> None:
      """Write SVG source and export PNGs at the requested output sizes."""
      p = ROOT / src_name
      p.write_text(svg, encoding="utf-8")
      for w, h, out in sizes:
            op = ROOT / out
            cairosvg.svg2png(url=str(p), write_to=str(op), output_width=w, output_height=h)
            print(f"  created  {out}  ({w}×{h},  ~{op.stat().st_size // 1024} KB)")


# ════════════════════════════════════════════════════════════════════════════
# ICON  —  512×512 lightning bolt mark on warm cream
# ════════════════════════════════════════════════════════════════════════════

def icon_svg() -> str:
    WP_BLUE = "#2271b1"
    WP_WHITE = "#ffffff"
    return f"""\
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
  <rect width="512" height="512" rx="0" fill="{WP_BLUE}"/>
  <rect x="16" y="16" width="480" height="480" fill="none" stroke="rgba(255,255,255,0.15)" stroke-width="2"/>
  <circle cx="256" cy="256" r="152" fill="rgba(255,255,255,0.1)" stroke="rgba(255,255,255,0.2)" stroke-width="2"/>
  <circle cx="256" cy="256" r="132" fill="rgba(255,255,255,0.15)" stroke="rgba(255,255,255,0.25)" stroke-width="2"/>
  <path d="M 329,117 L 216,250 L 266,250 L 183,393 L 296,261 L 246,261 Z" fill="{WP_WHITE}"/>
</svg>"""


# ════════════════════════════════════════════════════════════════════════════
# BANNER  —  1544×500  (brand left, admin mockup right)
# ════════════════════════════════════════════════════════════════════════════

def banner_svg() -> str:
    W, H = 1544, 500
    CX, CY, CW, CH = 632, 40, 840, 420
    CR = 4
    
    WP_DARK = "#1d2327"
    WP_BODY = "#f0f0f1"
    WP_BLUE = "#2271b1"
    WP_WHITE = "#ffffff"
    WP_MUTED = "#a8b1b8"
    F_SANS = "Avenir Next, Segoe UI, sans-serif"

    return f"""\
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}">
  <defs>
    <filter id="bShadow" x="-5%" y="-5%" width="110%" height="115%">
      <feDropShadow dx="0" dy="2" stdDeviation="2"
                    flood-color="#000" flood-opacity="0.05"/>
    </filter>
  </defs>

  <rect width="608" height="{H}" fill="{WP_DARK}"/>
  <rect x="608" width="{W - 608}" height="{H}" fill="{WP_BODY}"/>

  <g transform="translate(60,60) scale(0.08)">
    <path d="M 353,70 L 201,258 L 265,258 L 159,442 L 311,254 L 247,254 Z" fill="{WP_BLUE}"/>
  </g>
  <text x="60" y="140" font-family="{F_SANS}" font-size="14" font-weight="600" letter-spacing="1.5" fill="{WP_BLUE}">WOOCOMMERCE PLUGIN</text>
  <text x="60" y="210" font-family="{F_SANS}" font-size="64" font-weight="400" fill="{WP_WHITE}">Checkout Geo Flash</text>
  <text x="60" y="260" font-family="{F_SANS}" font-size="20" fill="{WP_MUTED}">Native WooCommerce settings for privacy-safe purchase toasts.</text>

  <rect x="60" y="300" width="100" height="32" rx="4" fill="rgba(255,255,255,0.05)" stroke="{WP_BLUE}" stroke-width="1"/>
  <text x="110" y="320" text-anchor="middle" font-family="{F_SANS}" font-size="12" font-weight="600" fill="{WP_WHITE}">Native UI</text>

  <rect x="176" y="300" width="116" height="32" rx="4" fill="rgba(255,255,255,0.05)" stroke="{WP_BLUE}" stroke-width="1"/>
  <text x="234" y="320" text-anchor="middle" font-family="{F_SANS}" font-size="12" font-weight="600" fill="{WP_WHITE}">Live Polling</text>

  <rect x="308" y="300" width="134" height="32" rx="4" fill="rgba(255,255,255,0.05)" stroke="{WP_BLUE}" stroke-width="1"/>
  <text x="375" y="320" text-anchor="middle" font-family="{F_SANS}" font-size="12" font-weight="600" fill="{WP_WHITE}">Owner Preview</text>

  <rect x="{CX}" y="{CY}" width="{CW}" height="{CH}" rx="{CR}" fill="{WP_WHITE}" stroke="#c3c4c7" stroke-width="1" filter="url(#bShadow)"/>
  
  <text x="{CX + 40}" y="{CY + 50}" font-family="{F_SANS}" font-size="16" font-weight="600" fill="#1d2327">Forwarding and display rules</text>
  <text x="{CX + 40}" y="{CY + 80}" font-family="{F_SANS}" font-size="14" fill="#50575e">Choose when WooCommerce events are stored and how coarse storefront locations should appear.</text>
  
  <line x1="{CX + 40}" y1="{CY + 110}" x2="{CX + CW - 40}" y2="{CY + 110}" stroke="#c3c4c7" stroke-width="1" />
  
  <text x="{CX + 40}" y="{CY + 150}" font-family="{F_SANS}" font-size="14" font-weight="600" fill="#1d2327">Enable forwarding</text>
  <rect x="{CX + 240}" y="{CY + 135}" width="16" height="16" rx="3" fill="{WP_BLUE}"/>
  <text x="{CX + 244}" y="{CY + 147}" font-family="{F_SANS}" font-size="12" fill="#fff" font-weight="bold">✓</text>
  <text x="{CX + 270}" y="{CY + 150}" font-family="{F_SANS}" font-size="14" fill="#1d2327">Record WooCommerce order events locally.</text>

  <line x1="{CX + 40}" y1="{CY + 180}" x2="{CX + CW - 40}" y2="{CY + 180}" stroke="#dcdcde" stroke-width="1" />
  
  <text x="{CX + 40}" y="{CY + 220}" font-family="{F_SANS}" font-size="14" font-weight="600" fill="#1d2327">Location mode</text>
  <circle cx="{CX + 248}" cy="{CY + 215}" r="8" fill="none" stroke="{WP_BLUE}" stroke-width="2"/>
  <circle cx="{CX + 248}" cy="{CY + 215}" r="4" fill="{WP_BLUE}"/>
  <text x="{CX + 270}" y="{CY + 220}" font-family="{F_SANS}" font-size="14" fill="#1d2327">Show city for local or national stores</text>

  <circle cx="{CX + 248}" cy="{CY + 255}" r="8" fill="none" stroke="#c3c4c7" stroke-width="2"/>
  <text x="{CX + 270}" y="{CY + 260}" font-family="{F_SANS}" font-size="14" fill="#50575e">Show country for global stores</text>

  <line x1="{CX + 40}" y1="{CY + 290}" x2="{CX + CW - 40}" y2="{CY + 290}" stroke="#dcdcde" stroke-width="1" />
  
  <rect x="{CX + 40}" y="{CY + 330}" width="120" height="36" rx="4" fill="{WP_BLUE}" />
  <text x="{CX + 100}" y="{CY + 353}" text-anchor="middle" font-family="{F_SANS}" font-size="14" font-weight="600" fill="#fff">Save settings</text>

</svg>"""


# ════════════════════════════════════════════════════════════════════════════
# SCREENSHOT 1  —  1280×960  WordPress admin plugin page
# ════════════════════════════════════════════════════════════════════════════

def screenshot1_svg() -> str:
    """WordPress admin screenshot showing the native WooCommerce admin page."""
    W, H = 1280, 960

    # --- chrome dimensions ---
    BAR_H   = 32
    SIDE_W  = 160
    CX, CY  = SIDE_W, BAR_H
    CW, CH  = W - SIDE_W, H - BAR_H

    # --- content layout ---
    PX = CX + 20         # page left padding
    PW = CW - 40         # page content width
    TABS_Y  = CY + 12
    H1_Y    = TABS_Y + 32 + 14
    SHELL_Y = H1_Y + 42

    # --- card dimensions ---
    SC_Y, SC_H = SHELL_Y, 272          # settings card
    GR_Y, GR_H = SC_Y + SC_H + 14, 196  # grid row
    GL_W = int(PW * 0.60)              # runtime card width
    GR_W = PW - GL_W - 14             # preview card width

    # --- native WP/WC tokens ---
    BD      = "#c3c4c7"
    BODY_BG = "#f0f0f1"
    CARD_BG = "#fff"
    H1_COL  = "#1d2327"
    TXT     = "#1d2327"
    MUT     = "#50575e"
    BLUE    = "#2271b1"
    BLUE_LT = "#e8f0fb"
    GREEN   = "#00a32a"
    GRN_BG  = "#edfaef"
    GRN_BD  = "#b8e6be"
    LBL     = "#1d2327"

    # card helper
    def card(x, y, w, h):
        return (
            f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="4" '            f'fill="{CARD_BG}" stroke="{BD}" stroke-width="1" '            f'filter="url(#cardShadow)"/>'        )

    # label / value row helper
    def row(th_text, td_el, y, TH_W=190):
        return f"""
  <text x="{PX + 24}" y="{y}" font-family="{F_SANS}" font-size="13" fill="{LBL}">{th_text}</text>
  {td_el}"""

    return f"""\
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}">
  <defs>
    <filter id="cardShadow" x="-2%" y="-4%" width="104%" height="110%">
      <feDropShadow dx="0" dy="1" stdDeviation="1"
                    flood-color="#000" flood-opacity="0.04"/>
    </filter>
  </defs>

  <!-- ── WP Top Bar ──────────────────────────────────────────────────────── -->
  <rect width="{W}" height="{BAR_H}" fill="{WP_DARK}"/>
  <circle cx="16" cy="16" r="6" fill="none" stroke="#9ec2e6" stroke-width="1.5"/>
  <text x="13" y="20" font-family="{F_SANS}" font-size="9" font-weight="700"
        fill="{WP_WHITE}">W</text>
  <text x="30" y="21" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">checkout-geo-flash.local</text>
  <text x="{W - 14}" y="21" text-anchor="end" font-family="{F_SANS}" font-size="12"
        fill="{WP_MUTED}">Howdy, devlinduldulao</text>

  <!-- ── WP Sidebar ─────────────────────────────────────────────────────── -->
  <rect x="0" y="{BAR_H}" width="{SIDE_W}" height="{CH}" fill="{WP_DARK}"/>
  <!-- Logo -->
  <circle cx="26" cy="60" r="12" fill="none" stroke="#9ec2e6" stroke-width="2"/>
  <text x="20" y="65" font-family="{F_SANS}" font-size="14" font-weight="700"
        fill="{WP_WHITE}">W</text>

  <!-- Menu items -->
  <text x="18" y="96"  font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Dashboard</text>
  <text x="18" y="124" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Posts</text>
  <text x="18" y="152" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Media</text>
  <text x="18" y="180" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Pages</text>
  <text x="18" y="208" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Comments</text>

  <line x1="8" y1="224" x2="152" y2="224" stroke="{WP_MUTED}" stroke-width="1"
        stroke-opacity="0.25"/>

  <!-- WooCommerce expanded -->
  <rect x="0" y="228" width="{SIDE_W}" height="24" fill="rgba(255,255,255,0.06)"/>
  <text x="18" y="244" font-family="{F_SANS}" font-size="12" font-weight="600"
        fill="{WP_WHITE}">WooCommerce</text>

  <rect x="0" y="252" width="{SIDE_W}" height="112" fill="{WP_SUB_BG}"/>
  <text x="32" y="270" font-family="{F_SANS}" font-size="11" fill="{WP_MUTED}">Home</text>
  <text x="32" y="290" font-family="{F_SANS}" font-size="11" fill="{WP_MUTED}">Orders</text>
  <text x="32" y="310" font-family="{F_SANS}" font-size="11" fill="{WP_MUTED}">Customers</text>
  <text x="32" y="330" font-family="{F_SANS}" font-size="11" fill="{WP_MUTED}">Reports</text>
  <!-- Settings (active - highlighted) -->
  <rect x="0" y="338" width="{SIDE_W}" height="22" fill="{BLUE}"/>
  <text x="32" y="353" font-family="{F_SANS}" font-size="11" fill="{WP_WHITE}">Settings</text>
  <text x="32" y="376" font-family="{F_SANS}" font-size="11" fill="{WP_MUTED}">Extensions</text>

  <line x1="8" y1="394" x2="152" y2="394" stroke="{WP_MUTED}" stroke-width="1"
        stroke-opacity="0.2"/>
  <text x="18" y="412" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Appearance</text>
  <text x="18" y="440" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Plugins</text>
  <text x="18" y="468" font-family="{F_SANS}" font-size="12" fill="{WP_MUTED}">Users</text>

  <!-- ── Content body ────────────────────────────────────────────────────── -->
  <rect x="{CX}" y="{CY}" width="{CW}" height="{CH}" fill="{BODY_BG}"/>

  <!-- WC page title (above tabs) -->
  <text x="{PX}" y="{CY + 26}" font-family="{F_SANS}" font-size="20" font-weight="400"
        fill="{H1_COL}">WooCommerce ▸ Settings</text>

  <!-- WC Settings tabs -->
  <rect x="{CX}" y="{TABS_Y + 28}" width="{CW}" height="1" fill="{BD}"/>

  <!-- Inactive tabs -->
  <text x="{PX}"       y="{TABS_Y + 22}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">General</text>
  <text x="{PX + 74}"  y="{TABS_Y + 22}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Products</text>
  <text x="{PX + 154}" y="{TABS_Y + 22}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Shipping</text>
  <text x="{PX + 232}" y="{TABS_Y + 22}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Advanced</text>
  <!-- Active tab -->
  <text x="{PX + 310}" y="{TABS_Y + 22}" font-family="{F_SANS}" font-size="13"
        font-weight="600" fill="{BLUE}">Checkout Geo Flash</text>
  <rect x="{PX + 309}" y="{TABS_Y + 26}" width="148" height="3" fill="{BLUE}"/>

  <!-- ── Plugin page heading ─────────────────────────────────────────────── -->
  <text x="{PX}" y="{H1_Y}" font-family="{F_SANS}" font-size="23" font-weight="400"
        fill="{H1_COL}">Devlin Checkout Geo Flash</text>
  <!-- wp-header-end separator -->
  <rect x="{PX}" y="{H1_Y + 8}" width="{PW}" height="1" fill="{BD}"/>

  <!-- ── Settings card ──────────────────────────────────────────────────── -->
  {card(PX, SC_Y, PW, SC_H)}

  <!-- Card h2 -->
  <text x="{PX + 24}" y="{SC_Y + 28}" font-family="{F_SANS}" font-size="14"
        font-weight="600" fill="{H1_COL}">Forwarding and display rules</text>
  <!-- Card description -->
  <text x="{PX + 24}" y="{SC_Y + 48}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Choose when WooCommerce events are stored, how coarse storefront locations should appear, and which milestones trigger a toast.</text>

  <!-- Form table rows -->
  <!-- Row 1: Enable forwarding -->
  <line x1="{PX + 24}" y1="{SC_Y + 62}" x2="{PX + PW - 24}" y2="{SC_Y + 62}"
        stroke="{BD}" stroke-width="1" stroke-opacity="0.6"/>
  <text x="{PX + 24}" y="{SC_Y + 84}" font-family="{F_SANS}" font-size="13"
        fill="{LBL}">Enable forwarding</text>
  <!-- Checkbox (checked, blue) -->
  <rect x="{PX + 220}" y="{SC_Y + 72}" width="14" height="14" rx="3" fill="{BLUE}"/>
  <text x="{PX + 224}" y="{SC_Y + 83}" font-family="{F_SANS}" font-size="10"
        fill="{WP_WHITE}">✓</text>
  <text x="{PX + 240}" y="{SC_Y + 84}" font-family="{F_SANS}" font-size="13"
        fill="{TXT}">Record WooCommerce order events locally and show privacy-safe toasts.</text>

  <!-- Row 2: Location mode -->
  <line x1="{PX + 24}" y1="{SC_Y + 102}" x2="{PX + PW - 24}" y2="{SC_Y + 102}"
        stroke="{BD}" stroke-width="1" stroke-opacity="0.6"/>
  <text x="{PX + 24}" y="{SC_Y + 120}" font-family="{F_SANS}" font-size="13"
        fill="{LBL}">Location mode</text>
  <!-- Radio selected -->
  <circle cx="{PX + 226}" cy="{SC_Y + 117}" r="6" fill="none" stroke="{BLUE}" stroke-width="2"/>
  <circle cx="{PX + 226}" cy="{SC_Y + 117}" r="3" fill="{BLUE}"/>
  <text x="{PX + 238}" y="{SC_Y + 121}" font-family="{F_SANS}" font-size="13"
        fill="{TXT}">Show city for local or national stores</text>
  <!-- Radio unselected -->
  <circle cx="{PX + 226}" cy="{SC_Y + 141}" r="6" fill="none" stroke="{BD}" stroke-width="2"/>
  <text x="{PX + 238}" y="{SC_Y + 145}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Show country for global stores</text>

  <!-- Row 3: Trigger on event -->
  <line x1="{PX + 24}" y1="{SC_Y + 162}" x2="{PX + PW - 24}" y2="{SC_Y + 162}"
        stroke="{BD}" stroke-width="1" stroke-opacity="0.6"/>
  <text x="{PX + 24}" y="{SC_Y + 182}" font-family="{F_SANS}" font-size="13"
        fill="{LBL}">Trigger on event</text>
  <!-- Select dropdown -->
  <rect x="{PX + 220}" y="{SC_Y + 169}" width="140" height="28" rx="3"
        fill="{CARD_BG}" stroke="{BD}" stroke-width="1"/>
  <text x="{PX + 232}" y="{SC_Y + 187}" font-family="{F_SANS}" font-size="13"
        fill="{TXT}">Both</text>
  <text x="{PX + 350}" y="{SC_Y + 187}" font-family="{F_SANS}" font-size="11"
        fill="{MUT}">▾</text>

  <!-- Submit separator + button -->
  <line x1="{PX + 24}" y1="{SC_Y + 212}" x2="{PX + PW - 24}" y2="{SC_Y + 212}"
        stroke="{BD}" stroke-width="1" stroke-opacity="0.6"/>
  <rect x="{PX + 24}" y="{SC_Y + 226}" width="118" height="30" rx="3" fill="{BLUE}"/>
  <text x="{PX + 83}" y="{SC_Y + 245}" text-anchor="middle" font-family="{F_SANS}"
        font-size="13" font-weight="600" fill="{WP_WHITE}">Save settings</text>

  <!-- ── Grid row ────────────────────────────────────────────────────────── -->
  <!-- Runtime card -->
  {card(PX, GR_Y, GL_W, GR_H)}
  <text x="{PX + 24}" y="{GR_Y + 28}" font-family="{F_SANS}" font-size="14"
        font-weight="600" fill="{H1_COL}">Runtime</text>
  <text x="{PX + 24}" y="{GR_Y + 48}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Checkout Geo Flash runs entirely inside WordPress. Events are stored locally</text>
  <text x="{PX + 24}" y="{GR_Y + 64}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">and delivered to storefront visitors through polling.</text>

  <!-- Status badge (green: standalone) -->
  <rect x="{PX + 24}" y="{GR_Y + 80}" width="102" height="22" rx="3"
        fill="{GRN_BG}" stroke="{GRN_BD}" stroke-width="1"/>
  <circle cx="{PX + 36}" cy="{GR_Y + 91}" r="3.5" fill="{GREEN}"/>
  <text x="{PX + 44}" y="{GR_Y + 95}" font-family="{F_SANS}" font-size="11"
        font-weight="600" fill="{GREEN}">Standalone</text>

  <!-- Refresh status button -->
  <rect x="{PX + 136}" y="{GR_Y + 78}" width="114" height="26" rx="3"
        fill="{CARD_BG}" stroke="{BD}" stroke-width="1"/>
  <text x="{PX + 193}" y="{GR_Y + 95}" text-anchor="middle" font-family="{F_SANS}"
        font-size="12" fill="{TXT}">Refresh status</text>

  <text x="{PX + 24}" y="{GR_Y + 126}" font-family="{F_SANS}" font-size="13"
        font-weight="600" fill="{TXT}">No external server is required.</text>
  <text x="{PX + 24}" y="{GR_Y + 148}" font-family="{F_SANS}" font-size="12"
        fill="{MUT}">Current site: https://checkout-geo-flash.local/</text>

  <!-- Preview card -->
  {card(PX + GL_W + 14, GR_Y, GR_W, GR_H)}
  <text x="{PX + GL_W + 38}" y="{GR_Y + 28}" font-family="{F_SANS}" font-size="14"
        font-weight="600" fill="{H1_COL}">Owner-only preview</text>
  <text x="{PX + GL_W + 38}" y="{GR_Y + 48}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Start or stop a clearly labeled sample</text>
  <text x="{PX + GL_W + 38}" y="{GR_Y + 64}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">preview visible only to the store owner.</text>

  <!-- Start preview button -->
  <rect x="{PX + GL_W + 38}" y="{GR_Y + 78}" width="152" height="30" rx="3" fill="{BLUE}"/>
  <text x="{PX + GL_W + 114}" y="{GR_Y + 97}" text-anchor="middle"
        font-family="{F_SANS}" font-size="12" font-weight="600"
        fill="{WP_WHITE}">Start sample preview</text>

  <text x="{PX + GL_W + 38}" y="{GR_Y + 128}" font-family="{F_SANS}" font-size="13"
        fill="{MUT}">Preview stopped.</text>

  <!-- Preview toast card (as rendered by JS) -->
  <rect x="{PX + GL_W + 38}" y="{GR_Y + 148}" width="{GR_W - 52}" height="34" rx="3"
        fill="{CARD_BG}" stroke="{BD}" stroke-width="1" stroke-left="4"/>
  <rect x="{PX + GL_W + 38}" y="{GR_Y + 148}" width="4" height="34" rx="2"
        fill="{BLUE}"/>
  <text x="{PX + GL_W + 50}" y="{GR_Y + 161}" font-family="{F_SANS}" font-size="9"
        font-weight="600" letter-spacing="0.5" fill="{MUT}">SAMPLE PREVIEW</text>
  <text x="{PX + GL_W + 50}" y="{GR_Y + 175}" font-family="{F_SANS}" font-size="12"
        font-weight="600" fill="{TXT}">Someone from Austin ordered recently</text>
</svg>"""


# ════════════════════════════════════════════════════════════════════════════
# SCREENSHOT 2  —  1280×960  WooCommerce storefront + toast
# ════════════════════════════════════════════════════════════════════════════

def screenshot2_svg() -> str:
    """WooCommerce storefront shop page with toast notification."""
    W, H = 1280, 960

    # Toast dimensions and position (bottom-right, ~380px wide)
    TW, TH = 380, 76
    TX = W - TW - 20
    TY = H - TH - 20

    # Header bar dimensions
    HDR_H = 72
    # Nav bar (below header)
    NAV_H = 44

    # Storefront elements
    STORE_COL_1 = 280  # sidebar width
    MAIN_X = STORE_COL_1
    MAIN_W = W - STORE_COL_1 - 32

    GRID_COLS = 3
    PROD_W    = (MAIN_W - 40) // GRID_COLS  # ~380
    PROD_H    = 320

    def product_card(col, row):
        x = MAIN_X + col * (PROD_W + 16)
        y = HDR_H + NAV_H + 60 + row * (PROD_H + 24)
        return f"""\
    <!-- Product card col={col} row={row} -->
    <rect x="{x}" y="{y}" width="{PROD_W}" height="{PROD_H}" rx="8"
          fill="{WP_WHITE}" stroke="#e5e7eb" stroke-width="1"/>
    <!-- Product image placeholder -->
    <rect x="{x}" y="{y}" width="{PROD_W}" height="{int(PROD_H * 0.55)}" rx="8"
          fill="#f3f4f6"/>
    <rect x="{x + PROD_W // 2 - 24}" y="{y + PROD_H // 4 - 16}" width="48" height="48" rx="6"
          fill="#e5e7eb"/>
    <!-- Product title -->
    <rect x="{x + 16}" y="{y + int(PROD_H * 0.58)}" width="{PROD_W - 80}" height="12" rx="3"
          fill="#d1d5db"/>
    <!-- Product price -->
    <rect x="{x + 16}" y="{y + int(PROD_H * 0.58) + 20}" width="60" height="10" rx="3"
          fill="#9ca3af"/>
    <!-- Add to cart button -->
    <rect x="{x + 16}" y="{y + PROD_H - 50}" width="{PROD_W - 32}" height="32" rx="4"
          fill="#1d2327"/>
    <text x="{x + PROD_W // 2}" y="{y + PROD_H - 28}" text-anchor="middle"
          font-family="{F_SANS}" font-size="12" font-weight="600"
          fill="{WP_WHITE}">Add to cart</text>"""

    products = "\n".join(
        product_card(c, r)
        for r in range(2)
        for c in range(GRID_COLS)
        if (r * GRID_COLS + c) < 5   # show 5 products
    )

    return f"""\
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}">
  <defs>
    <linearGradient id="toastShadow" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%"   stop-color="rgba(15,23,42,0.16)"/>
      <stop offset="100%" stop-color="rgba(15,23,42,0.06)"/>
    </linearGradient>
    <filter id="toastBlur" x="-20%" y="-30%" width="140%" height="160%">
      <feDropShadow dx="0" dy="8" stdDeviation="16"
                    flood-color="#0f172a" flood-opacity="0.14"/>
    </filter>
    <linearGradient id="toastStripe" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%"   stop-color="#6366f1"/>
      <stop offset="100%" stop-color="#4338ca"/>
    </linearGradient>
  </defs>

  <!-- Page background -->
  <rect width="{W}" height="{H}" fill="{SF_BG}"/>

  <!-- ── STOREFRONT HEADER ──────────────────────────────────────── -->
  <rect width="{W}" height="{HDR_H}" fill="{WP_WHITE}"
        stroke="#e5e7eb" stroke-width="1" stroke-dasharray="0,0"/>
  <!-- Logo text -->
  <text x="40" y="44"
        font-family="{F_SERIF}" font-size="26" font-weight="700"
        letter-spacing="-0.5" fill="{INK}">Devlin Mercantile</text>
  <!-- Nav icons: search (magnifying glass) and cart (simple shapes) -->
  <!-- Search icon -->
  <circle cx="{W - 72}" cy="37" r="9" fill="none" stroke="{MUTED}" stroke-width="2"/>
  <line x1="{W - 65}" y1="44" x2="{W - 58}" y2="51"
        stroke="{MUTED}" stroke-width="2" stroke-linecap="round"/>
  <!-- Cart icon -->
  <path d="M {W-44} 28 L {W-38} 28 L {W-34} 42 L {W-52} 42 Z"
        fill="none" stroke="{MUTED}" stroke-width="2" stroke-linejoin="round"/>
  <circle cx="{W-50}" cy="46" r="3" fill="{MUTED}"/>
  <circle cx="{W-36}" cy="46" r="3" fill="{MUTED}"/>

  <!-- ── NAVIGATION BAR ─────────────────────────────────────────── -->
  <rect y="{HDR_H}" width="{W}" height="{NAV_H}"
        fill="{WP_WHITE}" stroke="#e5e7eb" stroke-width="1"/>
  <text x="40" y="{HDR_H + 28}"
        font-family="{F_SANS}" font-size="14" fill="{MUTED}">Home</text>
  <text x="100" y="{HDR_H + 28}"
        font-family="{F_SANS}" font-size="14" font-weight="600"
        fill="{INK}">Shop</text>
  <text x="152" y="{HDR_H + 28}"
        font-family="{F_SANS}" font-size="14" fill="{MUTED}">Cart</text>
  <text x="196" y="{HDR_H + 28}"
        font-family="{F_SANS}" font-size="14" fill="{MUTED}">Checkout</text>
  <text x="270" y="{HDR_H + 28}"
        font-family="{F_SANS}" font-size="14" fill="{MUTED}">My Account</text>

  <!-- ── SHOP SIDEBAR ───────────────────────────────────────────── -->
  <rect x="0" y="{HDR_H + NAV_H}" width="{STORE_COL_1}" height="{H - HDR_H - NAV_H}"
        fill="{WP_WHITE}" stroke="#e5e7eb" stroke-width="1"/>

  <!-- Filter results heading -->
  <text x="24" y="{HDR_H + NAV_H + 34}"
        font-family="{F_SANS}" font-size="16" font-weight="600"
        fill="{INK}">Filter</text>

  <!-- Price filter -->
  <text x="24" y="{HDR_H + NAV_H + 66}"
        font-family="{F_SANS}" font-size="13" font-weight="600" fill="{INK}">Price</text>
  <rect x="24" y="{HDR_H + NAV_H + 78}" width="{STORE_COL_1 - 48}" height="4" rx="2"
        fill="#e5e7eb"/>
  <rect x="24" y="{HDR_H + NAV_H + 78}" width="{int((STORE_COL_1 - 48) * 0.6)}" height="4" rx="2"
        fill="{WP_DARK}"/>

  <!-- Category filter -->
  <text x="24" y="{HDR_H + NAV_H + 110}"
        font-family="{F_SANS}" font-size="13" font-weight="600" fill="{INK}">Categories</text>
  <text x="24" y="{HDR_H + NAV_H + 132}"
        font-family="{F_SANS}" font-size="13" fill="{MUTED}">All  (24)</text>
  <text x="24" y="{HDR_H + NAV_H + 152}"
        font-family="{F_SANS}" font-size="13" fill="{MUTED}">Apparel  (8)</text>
  <text x="24" y="{HDR_H + NAV_H + 172}"
        font-family="{F_SANS}" font-size="13" fill="{MUTED}">Electronics  (6)</text>
  <text x="24" y="{HDR_H + NAV_H + 192}"
        font-family="{F_SANS}" font-size="13" fill="{MUTED}">Home &amp; Garden  (5)</text>

  <!-- ── PRODUCT GRID ────────────────────────────────────────────── -->
  <!-- Shop heading -->
  <text x="{MAIN_X + 8}" y="{HDR_H + NAV_H + 38}"
        font-family="{F_SERIF}" font-size="24" font-weight="700"
        fill="{INK}">Shop</text>
  <text x="{W - 40}" y="{HDR_H + NAV_H + 38}" text-anchor="end"
        font-family="{F_SANS}" font-size="13" fill="{MUTED}">24 products</text>

  <line x1="{MAIN_X}" y1="{HDR_H + NAV_H + 50}" x2="{W - 24}" y2="{HDR_H + NAV_H + 50}"
        stroke="#e5e7eb" stroke-width="1"/>

  {products}

  <!-- ── TOAST NOTIFICATION ─────────────────────────────────────── -->
  <!-- Toast container positioned bottom-right (matches toast.js layout) -->
  <!-- Shadow -->
  <rect x="{TX}" y="{TY + 6}" width="{TW}" height="{TH}" rx="12"
        fill="rgba(15,23,42,0.08)" filter="url(#toastBlur)"/>
  <!-- Toast background -->
  <rect x="{TX}" y="{TY}" width="{TW}" height="{TH}" rx="12"
        fill="{TOAST_BG}" stroke="{TOAST_BD}" stroke-width="1"/>
  <!-- Toast content -->
  <!-- Eyebrow (uppercase, small, muted) -->
  <text x="{TX + 14}" y="{TY + 22}"
        font-family="{F_SANS}" font-size="11" font-weight="500"
        letter-spacing="0.5" fill="{TOAST_EYE}">DEVLIN CHECKOUT GEO FLASH</text>
  <!-- Toast title (main message) -->
  <text x="{TX + 14}" y="{TY + 50}"
        font-family="{F_SANS}" font-size="14" font-weight="600"
        fill="{TOAST_TTL}">Someone from Austin just completed</text>
  <text x="{TX + 14}" y="{TY + 66}"
        font-family="{F_SANS}" font-size="14" font-weight="600"
        fill="{TOAST_TTL}">checkout for a recent product</text>

  <!-- Second toast (stacked above first) -->
  <!-- Shadow -->
  <rect x="{TX}" y="{TY - TH - 12}" width="{TW}" height="{TH}" rx="12"
        fill="rgba(15,23,42,0.06)" filter="url(#toastBlur)"/>
  <!-- Toast 2 background -->
  <rect x="{TX}" y="{TY - TH - 10}" width="{TW}" height="{TH}" rx="12"
        fill="{TOAST_BG}" stroke="{TOAST_BD}" stroke-width="1"/>
  <!-- Toast 2 content -->
  <text x="{TX + 14}" y="{TY - TH - 10 + 22}"
        font-family="{F_SANS}" font-size="11" font-weight="500"
        letter-spacing="0.5" fill="{TOAST_EYE}">DEVLIN CHECKOUT GEO FLASH</text>
  <text x="{TX + 14}" y="{TY - TH - 10 + 50}"
        font-family="{F_SANS}" font-size="14" font-weight="600"
        fill="{TOAST_TTL}">Someone from London just placed</text>
  <text x="{TX + 14}" y="{TY - TH - 10 + 66}"
        font-family="{F_SANS}" font-size="14" font-weight="600"
        fill="{TOAST_TTL}">an order for a recent product</text>

</svg>"""


# ════════════════════════════════════════════════════════════════════════════
# MAIN — export all assets
# ════════════════════════════════════════════════════════════════════════════

if __name__ == "__main__":
    print("Generating Devlin Checkout Geo Flash WordPress.org assets …\n")

    export(
        icon_svg(), "icon.svg",
        [
            (128, 128, "icon-128x128.png"),
            (256, 256, "icon-256x256.png"),
        ],
    )

    export(
        banner_svg(), "banner.svg",
        [
            (772,  250, "banner-772x250.png"),
            (1544, 500, "banner-1544x500.png"),
        ],
    )

    export(
        screenshot1_svg(), "screenshot-admin.svg",
        [
            (1280, 960, "screenshot-1.png"),
        ],
    )

    export(
        screenshot2_svg(), "screenshot-storefront.svg",
        [
            (1280, 960, "screenshot-2.png"),
        ],
    )

    print("\nDone. All assets written to .wordpress-org/")
