/* Ornaments - small SVG decorations, kept simple */

const Diamond = ({ size = 8, color = "#a88753" }) =>
  <span style={{
    display: "inline-block",
    width: size, height: size,
    background: color,
    transform: "rotate(45deg)"
  }} />;

const Divider = ({ children }) => (
  <div className="divider">
    <span className="diamond"></span>
    {children && <span style={{
      fontFamily: "'Cormorant Garamond', serif",
      fontSize: 14,
      letterSpacing: "0.28em",
      textTransform: "uppercase",
      color: "var(--ink-muted)"
    }}>{children}</span>}
    <span className="diamond"></span>
  </div>
);

/* Ornamental flourish - a simple horizontal motif */
const Flourish = ({ width = 120, color = "#a88753" }) => (
  <svg width={width} height="16" viewBox="0 0 120 16" style={{ display: "block", margin: "0 auto" }}>
    <line x1="0" y1="8" x2="48" y2="8" stroke={color} strokeWidth="0.8" />
    <line x1="72" y1="8" x2="120" y2="8" stroke={color} strokeWidth="0.8" />
    <circle cx="54" cy="8" r="1.2" fill={color} />
    <rect x="58.5" y="4.5" width="7" height="7" fill={color} transform="rotate(45 62 8)" />
    <circle cx="66" cy="8" r="1.2" fill={color} />
  </svg>
);

/* Decorative initials banner */
const Crest = ({ initials = "É & T" }) => (
  <div style={{
    display: "inline-flex",
    flexDirection: "column",
    alignItems: "center",
    gap: 6
  }}>
    <Flourish width={140} />
    <div style={{
      fontFamily: "'Cormorant Garamond', serif",
      fontSize: 22,
      letterSpacing: "0.18em",
      color: "var(--burgundy)"
    }}>{initials}</div>
    <Flourish width={140} />
  </div>
);

/* ============================================================
   Décor floral (aquarelle stylisée) — pivoines, feuillage,
   boutons safran et touches dorées/ivoire. Tout en SVG inline.
   ============================================================ */

const FlowerPetal = ({ cx, cy, r, angle, fill, opacity = 0.95 }) => {
  const rad = (angle * Math.PI) / 180;
  const d = r * 0.5;
  const px = cx + Math.cos(rad) * d;
  const py = cy + Math.sin(rad) * d;
  return (
    <ellipse
      cx={px} cy={py} rx={r * 0.34} ry={r * 0.6}
      fill={fill} opacity={opacity}
      transform={`rotate(${angle + 90} ${px} ${py})`}
    />
  );
};

/* Une pivoine : 2 couronnes de pétales + cœur doré.
   `grad` = préfixe des dégradés définis dans le <defs> du cluster. */
const Peony = ({ cx, cy, r, grad }) => {
  const outer = Array.from({ length: 9 }, (_, i) => i * 40);
  const inner = Array.from({ length: 7 }, (_, i) => i * 51 + 22);
  const heart = Array.from({ length: 7 }, (_, i) => i);
  return (
    <g>
      {outer.map((a) => <FlowerPetal key={"o" + a} cx={cx} cy={cy} r={r} angle={a} fill={`url(#${grad}-po)`} />)}
      {inner.map((a) => <FlowerPetal key={"i" + a} cx={cx} cy={cy} r={r * 0.62} angle={a} fill={`url(#${grad}-pi)`} opacity={0.98} />)}
      <circle cx={cx} cy={cy} r={r * 0.2} fill={`url(#${grad}-pc)`} />
      {heart.map((i) => {
        const a = (i * 51 * Math.PI) / 180;
        return <circle key={i} cx={cx + Math.cos(a) * r * 0.11} cy={cy + Math.sin(a) * r * 0.11} r={r * 0.045} fill="#bf9a4e" />;
      })}
    </g>
  );
};

const Leaf = ({ x, y, len, angle, fill, opacity = 1 }) => {
  const p = `M0 0 C ${len * 0.42} ${-len * 0.28} ${len * 0.42} ${-len * 0.82} 0 ${-len} C ${-len * 0.42} ${-len * 0.82} ${-len * 0.42} ${-len * 0.28} 0 0 Z`;
  return (
    <g transform={`translate(${x} ${y}) rotate(${angle})`} opacity={opacity}>
      <path d={p} fill={fill} />
      <path d={`M0 0 L0 ${-len}`} stroke="rgba(60,70,40,0.25)" strokeWidth="0.8" fill="none" />
    </g>
  );
};

/* Petit bouton safran avec calice vert. */
const Bud = ({ x, y, angle = 0 }) => (
  <g transform={`translate(${x} ${y}) rotate(${angle})`}>
    <ellipse cx="0" cy="-10" rx="6.5" ry="11" fill="#e08a36" />
    <ellipse cx="0" cy="-13" rx="4" ry="7" fill="#eaa24f" opacity="0.8" />
    <path d="M0 0 C 5 -4 7 -9 6 -14 C 3 -10 -3 -10 -6 -14 C -7 -9 -5 -4 0 0 Z" fill="#6f7c43" />
    <path d="M0 2 L0 -8" stroke="#6f7c43" strokeWidth="2" />
  </g>
);

/* Cluster floral complet, dessiné dans un coin (viewBox 320x380). */
const FlowerCluster = ({ id }) => (
  <svg viewBox="0 0 320 380" width="100%" height="100%" preserveAspectRatio="xMinYMin meet" aria-hidden="true">
    <defs>
      <radialGradient id={`${id}-po`} cx="50%" cy="42%" r="62%">
        <stop offset="0%" stopColor="#f5dadb" />
        <stop offset="62%" stopColor="#e7b3b6" />
        <stop offset="100%" stopColor="#d4868d" />
      </radialGradient>
      <radialGradient id={`${id}-pi`} cx="50%" cy="45%" r="60%">
        <stop offset="0%" stopColor="#e6acb0" />
        <stop offset="100%" stopColor="#c06b72" />
      </radialGradient>
      <radialGradient id={`${id}-pc`} cx="50%" cy="45%" r="60%">
        <stop offset="0%" stopColor="#b86166" />
        <stop offset="100%" stopColor="#8f4a4f" />
      </radialGradient>
    </defs>

    {/* Feuillage (vert sauge / olive / pistache) */}
    <g>
      <Leaf x={150} y={120} len={130} angle={58} fill="#6f7c43" opacity={0.95} />
      <Leaf x={120} y={150} len={120} angle={95} fill="#8a9a52" />
      <Leaf x={90} y={185} len={110} angle={135} fill="#9caa6e" />
      <Leaf x={185} y={95} len={95} angle={25} fill="#b3bd7e" />
      <Leaf x={60} y={120} len={88} angle={150} fill="#6f7c43" opacity={0.9} />
      <Leaf x={210} y={150} len={80} angle={70} fill="#9caa6e" opacity={0.9} />
    </g>

    {/* Brins dorés */}
    <g stroke="#bf9a4e" strokeWidth="1.4" fill="none" opacity="0.85">
      <path d="M150 120 q 60 -10 110 -55" />
      <path d="M120 150 q -10 60 -40 120" />
    </g>
    <g fill="#bf9a4e" opacity="0.9">
      <circle cx="262" cy="62" r="2.4" /><circle cx="248" cy="72" r="1.8" />
      <circle cx="82" cy="268" r="2.4" /><circle cx="92" cy="252" r="1.8" />
    </g>

    {/* Touches ivoire (petites fleurs) */}
    <g fill="#f3e7cd">
      <circle cx="235" cy="120" r="9" /><circle cx="246" cy="128" r="7" /><circle cx="228" cy="132" r="6" />
      <circle cx="70" cy="225" r="8" /><circle cx="60" cy="235" r="6" />
    </g>
    <circle cx="237" cy="124" r="3" fill="#e08a36" />
    <circle cx="66" cy="229" r="2.4" fill="#e08a36" />

    {/* Boutons safran */}
    <Bud x={205} y={70} angle={18} />
    <Bud x={120} y={300} angle={-12} />

    {/* Pivoines */}
    <Peony cx={100} cy={100} r={72} grad={id} />
    <Peony cx={185} cy={150} r={44} grad={id} />
    <Peony cx={70} cy={210} r={34} grad={id} />
  </svg>
);

/* Décor latéral retiré : la photo de fond fait désormais office de décor. */
const SideFlowers = () => null;

Object.assign(window, { Diamond, Divider, Flourish, Crest, SideFlowers });
