-- =============================================================================
-- fix_nsp_foundation_design_match.sql — Re-theme NSP Foundation's CMS content
-- to actually match the source design file pixel-for-pixel (colors, nav
-- labels, section anchors, hero badges, and the fiscal-sponsorship/
-- get-involved composite layouts), after a full visual QA pass found the
-- site had been built with an entirely different (light/warm) theme than
-- the dark/teal/purple design it was supposed to match.
--
-- Same NAME-based business resolution as seed_nsp_foundation_business_and_site.sql
-- (see that file's header for why) — this file only UPDATEs rows under the
-- resolved site_id, it never inserts a business/site/collection.
--
-- Idempotent: every statement is an UPDATE against a natural key, safe to
-- re-run. Deploy the same way as the original seed file — via
-- apply-migrations.sh (default DB_NAME=stacie_Aggie_v1.0).
-- =============================================================================

SET @business_id := (SELECT id FROM businesses WHERE name = 'NSP Foundation' AND is_deleted = 0 ORDER BY id LIMIT 1);
SET @tenant_id := (SELECT tenant_id FROM businesses WHERE id = @business_id LIMIT 1);
SET @site_id := (SELECT id FROM dim_web_sites WHERE business_id = @business_id AND slug = 'nsp-foundation' LIMIT 1);

-- ── 1. Header nav — exact labels/anchors from the source design. The
-- previous seed invented "Why NSP / Where We Focus / In Action / Get
-- Involved" as a 5th nav link; the source has exactly 4 links (About /
-- Impact Areas / Fiscal Sponsorship / Current Projects) plus two header
-- BUTTONS (Donate, Get Involved) that Header.tsx now renders directly, not
-- as CMS nav items. ─────────────────────────────────────────────────────────
DELETE FROM dim_web_navigation_items
WHERE site_id = @site_id AND location = 'header' AND parent_id IS NULL;

INSERT INTO dim_web_navigation_items (tenant_id, business_id, site_id, parent_id, location, label, href, sort_order, created_by, updated_by, is_deleted)
VALUES
  (@tenant_id, @business_id, @site_id, NULL, 'header', 'About', '/#about', 1, NULL, NULL, 0),
  (@tenant_id, @business_id, @site_id, NULL, 'header', 'Impact Areas', '/#impact', 2, NULL, NULL, 0),
  (@tenant_id, @business_id, @site_id, NULL, 'header', 'Fiscal Sponsorship', '/#model', 3, NULL, NULL, 0),
  (@tenant_id, @business_id, @site_id, NULL, 'header', 'Current Projects', '/#initiatives', 4, NULL, NULL, 0);

-- ── 2. Home page layout — full rebuild using the corrected block types/props
-- (hero badges+vision card, teal ticker, dark focus-areas grid, the
-- sponsorshipSplit and getInvolvedSplit composite blocks). ──────────────────
UPDATE dim_web_pages SET layout_json = JSON_OBJECT(
  'version', 1,
  'blocks', JSON_ARRAY(
    JSON_OBJECT('id', 'home-hero', 'type', 'hero', 'props', JSON_OBJECT(
      'eyebrow', '501(c)(3) Nonprofit Venture Studio & Think Tank',
      'heading', 'Catalyzing equity, innovation, and economic mobility for underserved communities.',
      'subheading', 'NSP Foundation is a 501(c)(3) nonprofit venture studio and think tank dedicated to dismantling systemic economic barriers through fiscal sponsorship, entrepreneurial incubation, and community-centered programs.',
      'ctaLabel', 'Explore Our Work',
      'ctaHref', '/#impact',
      'secondaryLabel', 'Partner With Us',
      'secondaryHref', '/#connect',
      'visionText', 'A catalyst for economic empowerment and equity — so every community can overcome systemic barriers and thrive.',
      'visionLabel', 'Our Vision',
      'statusItems', JSON_ARRAY('EST. 2023', 'WASHINGTON, D.C.'),
      'badges', JSON_ARRAY(
        JSON_OBJECT('title', 'Fiscal sponsorship', 'subtitle', 'Launch under our 501(c)(3)', 'accent', 'var(--orange)'),
        JSON_OBJECT('title', 'Community-led', 'subtitle', 'Impact built with people', 'accent', 'var(--teal)')
      )
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'home-ticker', 'type', 'ticker', 'props', JSON_OBJECT(
      'lines', JSON_ARRAY('FISCAL SPONSORSHIP', 'VENTURE INCUBATION', 'APPLIED RESEARCH', 'COMMUNITY PARTNERSHIP')
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'why-nsp', 'type', 'richText', 'props', JSON_OBJECT(
      'anchor', 'about',
      'html', CONCAT(
        '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:48px;align-items:start;">',
        '<div><span style="display:inline-flex;align-items:center;gap:8px;font-size:12px;letter-spacing:.14em;text-transform:uppercase;color:var(--muted-2);"><span style="display:inline-block;width:24px;height:1px;background:var(--teal);"></span>Why NSP</span>',
        '<h2 style="margin-top:14px;font-size:2rem;font-weight:800;line-height:1.2;color:var(--ink);">We don''t just fund good ideas — <span style="color:var(--purple);">we help build them.</span></h2>',
        '<svg aria-hidden="true" width="230" height="148" viewBox="0 0 230 148" style="margin-top:32px;"><circle cx="88" cy="74" r="62" fill="none" stroke="var(--teal)" stroke-width="1.6" opacity=".85"></circle><circle cx="146" cy="74" r="62" fill="none" stroke="var(--purple)" stroke-width="1.6" opacity=".85"></circle><text x="42" y="45" font-family="var(--font-heading), sans-serif" font-size="11" font-weight="700" fill="var(--ink)">Venture</text><text x="42" y="59" font-family="var(--font-heading), sans-serif" font-size="11" font-weight="700" fill="var(--ink)">Studio</text><text x="156" y="45" font-family="var(--font-heading), sans-serif" font-size="11" font-weight="700" fill="var(--ink)">Think</text><text x="156" y="59" font-family="var(--font-heading), sans-serif" font-size="11" font-weight="700" fill="var(--ink)">Tank</text><text x="101" y="79" font-family="var(--font-heading), sans-serif" font-size="10" font-weight="800" letter-spacing="1.5" fill="var(--muted-2)">NSP</text></svg>',
        '</div>',
        '<div><p>Traditional social-impact models often move slower than the communities they''re meant to serve. NSP Foundation — Never Stop Pushing — was built to close that gap.</p>',
        '<p style="margin-top:16px;">As a 501(c)(3) public charity operating as a nonprofit venture studio and think tank, we pair venture-building discipline with the public trust of tax-exempt status — identifying high-potential social-impact ideas and equipping them with the infrastructure needed to scale, from applied research to direct-to-community programs.</p>',
        '<p style="margin-top:16px;">NSP Foundation operates under federal and state governance standards that support transparency, fiscal responsibility, and donor accountability across every sponsored project. The Foundation is led by Founder &amp; President Stacie Whisonant and a board of directors.</p></div>',
        '</div>',
        '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:24px;margin-top:40px;">',
        '<div style="border:1px solid var(--line);border-radius:20px;padding:24px;"><p style="font-size:11px;text-transform:uppercase;letter-spacing:.12em;color:var(--teal);font-weight:700;">The Venture Studio Engine</p><p style="font-weight:700;margin-top:8px;color:var(--ink);">Hands-on program support</p><p style="margin-top:8px;color:var(--muted);">We incubate early-stage social-impact projects and mission-aligned programs. Through fiscal sponsorship, shared services, and strategic mentorship, we reduce overhead and accelerate execution time for leaders working in underserved communities.</p></div>',
        '<div style="border:1px solid var(--line);border-radius:20px;padding:24px;"><p style="font-size:11px;text-transform:uppercase;letter-spacing:.12em;color:var(--purple);font-weight:700;">The Think Tank Engine</p><p style="font-weight:700;margin-top:8px;color:var(--ink);">Applied research &amp; convening</p><p style="margin-top:8px;color:var(--muted);">We conduct applied research and convene community leaders, corporate partners, and policy champions to design equitable solutions in student finance, small-business capital access, and housing preservation.</p></div>',
        '</div>'
      )
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'focus', 'type', 'numberedGrid', 'props', JSON_OBJECT(
      'anchor', 'impact',
      'variant', 'dark',
      'eyebrow', 'Where We Focus',
      'heading', 'Economic mobility is a connected system.',
      'collectionKey', 'focus-areas'
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'sponsorship', 'type', 'sponsorshipSplit', 'props', JSON_OBJECT(
      'anchor', 'model',
      'eyebrow', 'Fiscal Sponsorship & Venture Studio',
      'heading', 'Turn your social-impact vision into action.',
      'stepsEyebrow', 'Application & Onboarding',
      'benefitsCollectionKey', 'sponsorship-benefits',
      'stepsCollectionKey', 'onboarding-steps',
      'ctaLabel', 'Apply for fiscal sponsorship',
      'ctaHref', '/#connect'
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'in-action', 'type', 'pillarGrid', 'props', JSON_OBJECT(
      'anchor', 'initiatives',
      'variant', 'cards-icon',
      'heading', 'Current projects in flight.',
      'description', 'NSP Foundation currently supports a portfolio of initiatives spanning several areas of economic and community impact, including:',
      'collectionKey', 'portfolio-areas'
    ), 'children', JSON_ARRAY()),

    JSON_OBJECT('id', 'get-involved', 'type', 'getInvolvedSplit', 'props', JSON_OBJECT(
      'anchor', 'connect',
      'eyebrow', 'Get Involved',
      'heading', 'Join us in building an equitable future.',
      'collectionKey', 'get-involved-audiences',
      'formKey', 'connect',
      'contactLabel', 'Direct Contact',
      'contactEmail', 'contact@nspfoundation.org',
      'partnershipsEmail', 'partnerships@nspfoundation.org',
      'phone', '(804) 479-4784',
      'address', 'Washington, D.C.'
    ), 'children', JSON_ARRAY())
  )
)
WHERE site_id = @site_id AND slug = 'home';

-- ── 3. Site-wide theme_json — header CTA labels/hrefs and footer copy that
-- aren't page content but were previously hardcoded in Header.tsx/Footer.tsx
-- instead of being editable. dim_web_sites.theme_json is an existing generic
-- per-site config column (already exposed as `themeJson` in the public API,
-- per PublicSiteSettingsDto) — reused here rather than adding new columns. ──
UPDATE dim_web_sites SET theme_json = JSON_OBJECT(
  'headerDonateLabel', 'Donate',
  'headerDonateHref', '/#connect',
  'headerCtaLabel', 'Get Involved',
  'headerCtaHref', '/#connect',
  'footerTagline', 'Building the infrastructure behind community progress.',
  'footerEin', '99-0491172'
)
WHERE id = @site_id;
