// ─────────────────────────────────────────────────────────────
// "ONE GROUP. ONE POWER." — campaign-poster sibling of the
// Definitive concept. Same form mechanics; the personality
// dial is turned up:
//
//   • Squares-cluster header burst (full brand palette —
//     primary amber + tertiary strong + secondary pastels)
//     arranged around the stacked logo, matching the WXG
//     "Visit Your New Website" campaign aesthetic.
//   • "WE ARE" / "ONE GROUP. ONE POWER." tagline frame.
//   • Skyline lives at the BOTTOM, not the top — feels like
//     a closing horizon line, with the squares acting as
//     the rising celebration overhead.
//   • Track record stats row above the skyline.
//   • Form card identical to the Definitive — reuses every
//     shared internal so the two are interchangeable.
// ─────────────────────────────────────────────────────────────

const CB_TYPE = WXG_FONT;
const CB_MONO = WXG_MONO;

// Palette — full brand spectrum (primaries, secondaries, tertiaries)
const CB_PALETTE = {
  amber:       '#FCAF17',
  pinkStrong:  '#C161CA',
  greenStrong: '#61CAA0',
  blueStrong:  '#6186CA',
  goldStrong:  '#CABE61',
  redStrong:   '#CA6461',
  pinkSoft:    '#E0B0E5',
  greenSoft:   '#B0E5D0',
  blueSoft:    '#B0C2E5',
  goldSoft:    '#E5DEB0',
  redSoft:     '#E5B2B0',
  ink:         '#1F1F1F',
  grey:        '#4D4D4D',
  paper:       '#F5F5F4',
};

// ─────────────────────────────────────────────────────────────
// The squares-cluster — fixed, intentional composition arranged
// around the logo. Numbers are percentages relative to the
// header region (so the cluster scales with the viewport).
// ─────────────────────────────────────────────────────────────
const CB_SQUARES = [
  // Big amber anchor — lower-left of the burst
  { x: 38, y: 60, w: 64,  h: 64,  c: CB_PALETTE.amber,       d: 0 },

  // Strong pinks/magenta accents
  { x: 22, y: 14, w: 38,  h: 30,  c: CB_PALETTE.pinkStrong,  d: 0.4 },
  { x: 49, y: 10, w: 24,  h: 32,  c: CB_PALETTE.pinkStrong,  d: 0.5 },
  { x: 64, y: 26, w: 18,  h: 18,  c: CB_PALETTE.pinkStrong,  d: 0.6 },
  { x: 14, y: 40, w: 14,  h: 18,  c: CB_PALETTE.pinkStrong,  d: 0.7 },

  // Pastel pinks
  { x: 30, y: 5,  w: 18,  h: 18,  c: CB_PALETTE.pinkSoft,    d: 0.3 },
  { x: 76, y: 12, w: 22,  h: 16,  c: CB_PALETTE.pinkSoft,    d: 0.55 },

  // Greens
  { x: 5,  y: 22, w: 22,  h: 18,  c: CB_PALETTE.greenSoft,   d: 0.2 },
  { x: 60, y: 50, w: 28,  h: 22,  c: CB_PALETTE.greenStrong, d: 0.45 },
  { x: 4,  y: 60, w: 14,  h: 14,  c: CB_PALETTE.greenSoft,   d: 0.65 },

  // Golds
  { x: 73, y: 38, w: 30,  h: 26,  c: CB_PALETTE.goldSoft,    d: 0.35 },
  { x: 86, y: 56, w: 20,  h: 22,  c: CB_PALETTE.goldStrong,  d: 0.5 },
  { x: 56, y: 28, w: 14,  h: 14,  c: CB_PALETTE.goldSoft,    d: 0.4 },

  // Blues
  { x: 18, y: 4,  w: 14,  h: 14,  c: CB_PALETTE.blueSoft,    d: 0.15 },
  { x: 81, y: 4,  w: 12,  h: 14,  c: CB_PALETTE.blueStrong,  d: 0.6 },

  // Small black + amber accents (the brand book's "dots")
  { x: 50, y: 36, w: 8,   h: 8,   c: CB_PALETTE.ink,         d: 0.7 },
  { x: 26, y: 56, w: 8,   h: 8,   c: CB_PALETTE.ink,         d: 0.75 },
  { x: 70, y: 16, w: 6,   h: 6,   c: CB_PALETTE.ink,         d: 0.8 },
  { x: 90, y: 36, w: 10,  h: 10,  c: CB_PALETTE.amber,       d: 0.55 },
  { x: 12, y: 70, w: 10,  h: 10,  c: CB_PALETTE.amber,       d: 0.65 },

  // Red accents
  { x: 44, y: 80, w: 14,  h: 12,  c: CB_PALETTE.redSoft,     d: 0.8 },
  { x: 38, y: 30, w: 10,  h: 12,  c: CB_PALETTE.redStrong,   d: 0.6 },
];

function CB_SquaresCluster({ mobile, progress }) {
  // Cluster region: full width × ~85% of header height.
  // On mobile, slightly tighter scaling.
  return (
    <div style={{
      position: 'absolute', insetInline: 0, top: 0, bottom: 0,
      pointerEvents: 'none',
    }}>
      {CB_SQUARES.map((sq, i) => {
        // Each square fades in based on `d` (delay 0..1) compared
        // to progress through the survey. Subtle drift on activation.
        const revealed = progress >= sq.d - 0.05;
        return (
          <div key={i} style={{
            position: 'absolute',
            insetInlineStart: `${sq.x}%`,
            top: `${sq.y}%`,
            width: mobile ? sq.w * 0.65 : sq.w,
            height: mobile ? sq.h * 0.65 : sq.h,
            background: sq.c,
            opacity: revealed ? 1 : 0.18,
            transform: revealed
              ? 'translate(0, 0) scale(1)'
              : 'translate(0, 6px) scale(0.92)',
            transition: `opacity 600ms cubic-bezier(.2,.8,.2,1) ${i * 35}ms,
                         transform 600ms cubic-bezier(.2,.8,.2,1) ${i * 35}ms`,
          }} />
        );
      })}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// "WE ARE WXG / ONE GROUP. ONE POWER." stacked treatment
// (the campaign-edition variant of the stacked logo)
// ─────────────────────────────────────────────────────────────
function CB_CampaignLogo({ mobile }) {
  const wxgH = mobile ? 44 : 60;
  return (
    <div style={{
      display: 'inline-flex', flexDirection: 'column', alignItems: 'center',
      gap: mobile ? 4 : 6,
      fontFamily: CB_TYPE,
    }}>
      <span style={{
        fontFamily: CB_TYPE, fontWeight: 400,
        fontSize: mobile ? 9.5 : 11, letterSpacing: mobile ? 4 : 5,
        color: CB_PALETTE.grey, textTransform: 'uppercase',
      }}>WE ARE</span>

      <WXGOfficial height={wxgH} color={CB_PALETTE.grey} accent={CB_PALETTE.amber} />

      <span style={{
        fontFamily: CB_TYPE, fontWeight: 400,
        fontSize: mobile ? 9.5 : 11, letterSpacing: mobile ? 2 : 2.5,
        color: CB_PALETTE.grey, textTransform: 'uppercase',
        whiteSpace: 'nowrap',
      }}>One Group. One Power<span style={{ color: CB_PALETTE.amber }}>.</span></span>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Track-record stats row above the skyline footer.
// ─────────────────────────────────────────────────────────────
function CB_Stats({ mobile }) {
  const items = [
    ['30+', 'שנות מצוינות'],
    ['400+', 'פרויקטים'],
    ['12', 'מדינות'],
  ];
  return (
    <div style={{
      display: 'flex', justifyContent: 'center',
      alignItems: 'baseline',
      gap: mobile ? 18 : 40,
      padding: mobile ? '14px 18px 6px' : '20px 36px 10px',
      fontFamily: CB_TYPE,
      flexWrap: 'wrap',
    }}>
      {items.map(([n, l], i) => (
        <div key={l} style={{
          display: 'inline-flex', alignItems: 'baseline', gap: mobile ? 6 : 10,
        }}>
          <span style={{
            fontFamily: CB_TYPE, fontWeight: 700,
            fontSize: mobile ? 18 : 22, color: CB_PALETTE.ink,
            letterSpacing: '-0.02em',
          }}>{n}</span>
          <span style={{
            fontFamily: CB_TYPE, fontWeight: 300,
            fontSize: mobile ? 11 : 12, color: CB_PALETTE.grey,
          }}>{l}</span>
          {i < items.length - 1 && (
            <span style={{
              width: 4, height: 4, background: CB_PALETTE.amber,
              marginInlineStart: mobile ? 6 : 14, alignSelf: 'center',
            }} />
          )}
        </div>
      ))}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Direction shell — Squares header + Card + Stats + Skyline footer
// ─────────────────────────────────────────────────────────────
function DirectionCelebrate({ mobile = false, initialPage = 0, initialAnswers = null }) {
  const s = useSurvey({ initialPage, initialAnswers });

  // Continuous progress 0..1 across the survey, used to reveal
  // both the squares cluster and the skyline footer.
  const progress = s.page === 0 ? 0.04
                 : s.page > s.total ? 1
                 : (s.page / (s.total + 0.4));

  return (
    <div dir="rtl" style={{
      width: '100%', height: '100%', position: 'relative',
      background: '#FAF9F6', color: CB_PALETTE.ink,
      fontFamily: CB_TYPE, overflow: 'hidden',
      display: 'flex', flexDirection: 'column',
    }}>
      {/* Squares-cluster header */}
      <div style={{
        position: 'relative',
        height: mobile ? 170 : 230,
        flexShrink: 0, overflow: 'hidden',
      }}>
        <CB_SquaresCluster mobile={mobile} progress={progress} />

        {/* Logo + tagline centered, anchored to bottom of header */}
        <div style={{
          position: 'absolute', insetInline: 0,
          bottom: mobile ? 12 : 18,
          display: 'flex', justifyContent: 'center',
          zIndex: 3,
        }}>
          <div style={{
            padding: mobile ? '8px 18px' : '12px 26px',
            background: '#FAF9F6',
          }}>
            <CB_CampaignLogo mobile={mobile} />
          </div>
        </div>
      </div>

      {/* Form card */}
      <div style={{
        flex: 1, position: 'relative', zIndex: 2,
        display: 'flex', justifyContent: 'center',
        padding: mobile ? '14px 18px 0' : '20px 36px 0',
        minHeight: 0,
      }}>
        <div style={{
          width: '100%', maxWidth: mobile ? 360 : 760,
          background: '#FFFFFF',
          padding: mobile ? '22px 22px 26px' : '32px 40px 34px',
          boxShadow: '0 1px 0 rgba(0,0,0,0.04), 0 12px 32px -16px rgba(0,0,0,0.10), 0 28px 56px -32px rgba(0,0,0,0.10)',
          position: 'relative', overflow: 'auto', maxHeight: '100%',
          boxSizing: 'border-box',
        }}>
          {/* Card header — project meta */}
          <RL_CardHeader mobile={mobile} />

          {/* Body — fade-slide between states */}
          <div key={s.page} style={{
            marginTop: mobile ? 22 : 28,
            animation: `wxg-fade-slide-${s.direction > 0 ? 'next' : 'prev'} 380ms cubic-bezier(.2,.8,.2,1)`,
          }}>
            {s.page === 0 && <RL_Intro mobile={mobile} onStart={s.goNext} />}
            {s.page > 0 && s.page <= s.total && <RL_Question s={s} mobile={mobile} />}
            {s.page > s.total && <RL_Thanks s={s} mobile={mobile} />}
          </div>

          {/* Card nav */}
          <RL_CardNav s={s} mobile={mobile} />
        </div>
      </div>

      {/* Stats row + skyline footer */}
      <div style={{ flexShrink: 0, position: 'relative', zIndex: 1 }}>
        <CB_Stats mobile={mobile} />
        <div style={{
          position: 'relative',
          height: mobile ? 60 : 90,
          marginTop: mobile ? 4 : 8,
        }}>
          <RL_Skyline progress={progress} mobile={mobile} />
        </div>
        <div style={{
          padding: mobile ? '4px 16px 10px' : '4px 36px 12px',
          textAlign: 'center',
          fontFamily: CB_TYPE, fontWeight: 300, fontSize: mobile ? 11 : 12,
          color: '#8A8A8A',
        }}>
          © 2026 WXG · Waxman Group
        </div>
      </div>
    </div>
  );
}

window.DirectionCelebrate = DirectionCelebrate;
