/**
 * Filigree — decorative art-nouveau line ornaments used throughout the design.
 * Inline SVG so they inherit `currentColor` from their parent section.
 */
function HeroFlourish({ mirror = false }) {
  return (
    <svg
      viewBox="0 0 180 140"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.8"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
      style={mirror ? { transform: "scale(-1, -1)" } : undefined}
    >
      {/* main sweeping arc */}
      <path d="M8 128 C 36 116, 60 96, 86 76 S 142 38, 172 12" />
      {/* parallel inner shadow line */}
      <path d="M30 124 C 52 112, 72 94, 92 80" />
      {/* terminal curl top */}
      <path d="M172 12 C 168 22, 158 22, 156 14 C 154 6, 164 2, 168 8" />
      {/* tiny leaf at terminal */}
      <path d="M158 14 c 2 -8, 10 -10, 14 -4 c -2 8, -10 10, -14 4 z" fill="currentColor" stroke="none" opacity="0.55" />
      {/* opposite curl at base */}
      <path d="M8 128 C 4 122, 10 116, 18 118 C 26 120, 28 130, 22 134 C 16 138, 8 134, 8 128 z" />
      {/* tendril branching off mid */}
      <path d="M86 76 c -6 12, -18 16, -28 12 c 4 -10, 14 -16, 24 -14" />
      <path d="M120 50 c 10 -2, 18 6, 16 16 c -10 0, -16 -8, -16 -16 z" fill="currentColor" stroke="none" opacity="0.45" />
      {/* small dots accent */}
      <circle cx="58" cy="100" r="1.6" fill="currentColor" stroke="none" />
      <circle cx="130" cy="44" r="1.6" fill="currentColor" stroke="none" />
    </svg>
  );
}

/**
 * DividerFlourish — the section separator graphic (Untitled-4-15), a symmetric
 * winged art-nouveau motif. Cream-filled SVG; the wrapping `.divider` controls
 * size + spacing.
 */
function DividerFlourish() {
  return (
    <img className="divider-img" src="assets/orn/divider.svg" alt="" aria-hidden="true" />
  );
}

function CornerFlourish() {
  return (
    <svg
      viewBox="0 0 200 200"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.8"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      {/* outer vertical sweep down left */}
      <path d="M16 192 C 16 150, 22 100, 38 60 C 50 32, 72 16, 96 14" />
      {/* inner parallel curve */}
      <path d="M34 188 C 36 152, 44 112, 60 78" />
      {/* outer horizontal sweep across top */}
      <path d="M192 16 C 150 16, 100 22, 60 38 C 32 50, 16 72, 14 96" />
      {/* inner parallel */}
      <path d="M188 34 C 152 36, 112 44, 78 60" />

      {/* terminal curl top-right */}
      <path d="M96 14 C 104 6, 116 8, 116 18 C 116 28, 104 30, 98 24" />
      <circle cx="116" cy="18" r="2" fill="currentColor" stroke="none" />

      {/* terminal curl bottom-left */}
      <path d="M14 96 C 6 104, 8 116, 18 116 C 28 116, 30 104, 24 98" />
      <circle cx="18" cy="116" r="2" fill="currentColor" stroke="none" />

      {/* leaf flourishes */}
      <path d="M58 58 c -10 4, -14 14, -10 26 c 12 -2, 18 -14, 14 -28 c -2 0, -3 1, -4 2 z" fill="currentColor" opacity="0.55" stroke="none" />
      <path d="M80 42 c 4 -8, 16 -10, 22 -4 c -4 10, -16 12, -22 4 z" fill="currentColor" opacity="0.55" stroke="none" />
      <path d="M42 80 c -8 4, -10 16, -4 22 c 10 -4, 12 -16, 4 -22 z" fill="currentColor" opacity="0.55" stroke="none" />

      {/* small accent curls */}
      <path d="M132 28 c 6 0, 10 6, 8 12 c -8 -2, -10 -8, -8 -12 z" />
      <path d="M28 132 c 0 6, 6 10, 12 8 c -2 -8, -8 -10, -12 -8 z" />

      {/* dot ornaments */}
      <circle cx="140" cy="22" r="1.6" fill="currentColor" stroke="none" />
      <circle cx="22" cy="140" r="1.6" fill="currentColor" stroke="none" />
    </svg>
  );
}

/**
 * SectionDivider — the art-nouveau divider flourish with a Tweakable layout:
 *   - "below-text" → compact, hugs the paragraph above it.
 *   - "section"    → larger flourish with generous spacing, reads as a break
 *                    between two sections.
 */
function SectionDivider({ variant = "below-text" }) {
  return (
    <div className={`divider divider--${variant}`} aria-hidden="true">
      <DividerFlourish />
    </div>
  );
}

/**
 * SectionFrame — corner/edge frame ornaments for full-bleed sections (hero) and
 * the closing section (outro). Driven by the shared `frame` tweak:
 *   - "vine"    → Untitled-4-04 corner sweep, top-left + bottom-right.
 *   - "corners" → Untitled-8-06 corner flourish, top-right + bottom-left.
 *   - "grapes" / "nouveau" → a full frame stretched over the hero image; on a
 *                 non-image section (cornerOnly) these fall back to vine corners.
 *   - "none"    → nothing.
 * Colour is set by context: the hero filters it white/ink; the outro shows the
 * cream base directly.
 */
const SECTION_FRAME_CORNERS = {
  vine: { src: "assets/orn/frame-vine.svg", at: ["tl", "br"] },
  corners: { src: "assets/orn/frame-corner-flip.svg", at: ["tl", "br"] }
};
function SectionFrame({ frame = "vine", cornerOnly = false }) {
  if (!frame || frame === "none") return null;

  if (!cornerOnly && (frame === "grapes" || frame === "nouveau")) {
    const src =
      frame === "grapes" ? "assets/frame-grapes-rot.svg" : "assets/frame-nouveau-rot.svg";
    return <img className="sframe sframe--full" src={src} alt="" aria-hidden="true" />;
  }

  const fkey = SECTION_FRAME_CORNERS[frame] ? frame : "vine";
  const def = SECTION_FRAME_CORNERS[fkey];
  return (
    <>
      <img className={`sframe sframe--corner sframe--${fkey} sframe--${def.at[0]}`} src={def.src} alt="" aria-hidden="true" />
      <img className={`sframe sframe--corner sframe--${fkey} sframe--${def.at[1]}`} src={def.src} alt="" aria-hidden="true" />
    </>
  );
}

/**
 * Flourish — a single tweakable decorative motif (the Untitled-8 / Art-Nouveau
 * set), placed as a small accent. `name` matches the asset suffix
 * (e.g. "m01" → assets/orn/fl-m01.svg). Height-sized so any aspect ratio works.
 */
function Flourish({ name, className = "" }) {
  if (!name || name === "none") return null;
  return (
    <img
      className={`flourish ${className}`.trim()}
      src={`assets/orn/fl-${name}.svg`}
      alt=""
      aria-hidden="true"
    />
  );
}

if (typeof window !== "undefined") {
  window.HeroFlourish = HeroFlourish;
  window.DividerFlourish = DividerFlourish;
  window.CornerFlourish = CornerFlourish;
  window.SectionDivider = SectionDivider;
  window.SectionFrame = SectionFrame;
  window.Flourish = Flourish;
}
