/* eslint-disable */
// Before / After — two hero sliders side by side, then a "one image, whole
// campaign" section. Convention: B = BEFORE (raw product / shoot), A = AFTER
// (Studio output).

const HERO_PAIRS = [
{ before: "pricing-images/B1.jpg", after: "pricing-images/A1.jpg", caption: "Creative Studio · 2 min" },
{ before: "pricing-images/B6.jpg", after: "pricing-images/A6.jpg", caption: "Creative Studio · 2 min" }];


const CAMPAIGN_SOURCE = "pricing-images/Source.jpg";
const CAMPAIGN_VARIATIONS = [
{ src: "pricing-images/V1.jpg", label: "" },
{ src: "pricing-images/V2.jpg", label: "" },
{ src: "pricing-images/V3.jpg", label: "" },
{ src: "pricing-images/V4.jpg", label: "" }];


const MINI_PAIRS = [
{ before: "pricing-images/B2.jpg", after: "pricing-images/A2.jpg" },
{ before: "pricing-images/B3.jpg", after: "pricing-images/A3.jpg" },
{ before: "pricing-images/B4.jpg", after: "pricing-images/A4.jpg" },
{ before: "pricing-images/B5.jpg", after: "pricing-images/A5.jpg" }];


function HeroSlider({ pair }) {
  const [pos, setPos] = React.useState(0.5);
  const [dragging, setDragging] = React.useState(false);
  const wrapRef = React.useRef(null);

  const setFromClientX = (clientX) => {
    const r = wrapRef.current?.getBoundingClientRect();
    if (!r) return;
    setPos(Math.max(0.04, Math.min(0.96, (clientX - r.left) / r.width)));
  };

  React.useEffect(() => {
    if (!dragging) return;
    const onMove = (e) => setFromClientX(e.touches ? e.touches[0].clientX : e.clientX);
    const onUp = () => setDragging(false);
    window.addEventListener("mousemove", onMove);
    window.addEventListener("mouseup", onUp);
    window.addEventListener("touchmove", onMove, { passive: false });
    window.addEventListener("touchend", onUp);
    return () => {
      window.removeEventListener("mousemove", onMove);
      window.removeEventListener("mouseup", onUp);
      window.removeEventListener("touchmove", onMove);
      window.removeEventListener("touchend", onUp);
    };
  }, [dragging]);

  return (
    <div
      ref={wrapRef}
      onMouseDown={(e) => {setDragging(true);setFromClientX(e.clientX);}}
      onTouchStart={(e) => {setDragging(true);setFromClientX(e.touches[0].clientX);}}
      style={{
        position: "relative",
        width: "100%",
        aspectRatio: "3 / 4",
        borderRadius: 0,
        overflow: "hidden",
        background: "var(--card)",
        border: "1px solid var(--card-line)",
        cursor: "ew-resize",
        userSelect: "none",
        touchAction: "none"
      }}>
      {/* AFTER is the base layer (right side) — BEFORE is revealed on the left */}
      <img src={pair.after} alt="After" draggable="false"
      style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", pointerEvents: "none" }} />
      <div style={{
        position: "absolute", inset: 0,
        clipPath: `inset(0 ${(1 - pos) * 100}% 0 0)`,
        WebkitClipPath: `inset(0 ${(1 - pos) * 100}% 0 0)`
      }}>
        <img src={pair.before} alt="Before" draggable="false"
        style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", pointerEvents: "none" }} />
      </div>

      {/* Pills fade out when their side of the image isn't visible */}
      <PillTag style={{
        top: 18, left: 18, background: "#2A2420", color: "#F2ECE4",
        opacity: pos > 0.12 ? 1 : 0,
        transition: "opacity 200ms ease"
      }}>Before</PillTag>
      <PillTag style={{
        top: 18, right: 18, background: "#F2ECE4", color: "#2A2420",
        boxShadow: "0 4px 14px -6px rgba(0,0,0,0.25)",
        opacity: pos < 0.88 ? 1 : 0,
        transition: "opacity 200ms ease"
      }}>{pair.caption}</PillTag>

      <div style={{
        position: "absolute", top: 0, bottom: 0, left: `${pos * 100}%`,
        width: 2, background: "var(--cream)", transform: "translateX(-1px)",
        pointerEvents: "none", boxShadow: "0 0 0 1px rgba(0,0,0,0.12)"
      }} />
      <div style={{
        position: "absolute", top: "50%", left: `${pos * 100}%`,
        transform: "translate(-50%, -50%)", width: 56, height: 56, borderRadius: "50%",
        background: "var(--cream)", border: "1px solid var(--card-line)",
        display: "grid", placeItems: "center", color: "var(--ink)",
        boxShadow: "0 8px 24px -8px rgba(0,0,0,0.35)", pointerEvents: "none"
      }}>
        <svg width="22" height="22" viewBox="0 0 22 22" fill="none">
          <path d="M8 6L4 11L8 16" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
          <path d="M14 6L18 11L14 16" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </div>
    </div>);

}

// Pill colours are fixed, not theme variables: they sit on photographs, so they
// must read the same whether the page around them is light or dark.
function PillTag({ children, style }) {
  return (
    <div style={{
      position: "absolute", padding: "8px 14px", borderRadius: 999,
      fontFamily: "La Villa", fontSize: 10, letterSpacing: "0.22em",
      textTransform: "uppercase", fontWeight: 600, ...style
    }}>{children}</div>);

}

function BeforeAfter() {
  return (
    <section className="pp-ba-section" style={{ padding: "60px 40px 20px", maxWidth: 1480, margin: "0 auto" }}>
      <div className="pp-ba-head" style={{
        display: "grid", gridTemplateColumns: "minmax(220px, 1fr) 3fr",
        gap: 40, alignItems: "end", marginBottom: 28
      }}>
        <div>
          <div style={{
            fontFamily: "La Villa", fontSize: 11, letterSpacing: "0.22em",
            textTransform: "uppercase", fontWeight: 500, color: "var(--ink-mute)"
          }}>01 · Before / After</div>
          <p className="italic-serif" style={{ marginTop: 14, fontSize: 18, lineHeight: 1.35, color: "var(--ink-soft)" }}>
            Drop a product. Choose a scene.<br/>Rewrite the image.
          </p>
        </div>
        <div style={{ justifySelf: "end", textAlign: "right" }}>
          <div style={{
            fontFamily: "La Villa", fontSize: 11, letterSpacing: "0.22em",
            textTransform: "uppercase", color: "var(--ink-mute)"
          }}>Drag to reveal</div>
        </div>
      </div>

      <div className="pp-ba-hero" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
        {HERO_PAIRS.map((p, i) => <HeroSlider key={i} pair={p} />)}
      </div>

      <div className="pp-ba-mini" style={{ marginTop: 16, display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16 }}>
        {MINI_PAIRS.map((p, i) => <MiniBeforeAfter key={i} pair={p} />)}
      </div>

      <CampaignFromOne />
    </section>);

}

function MiniBeforeAfter({ pair }) {
  return (
    <div style={{
      display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4,
      borderRadius: 0, overflow: "hidden", background: "var(--card)",
      border: "1px solid var(--card-line)"
    }}>
      <div style={{ position: "relative", aspectRatio: "2 / 3" }}>
        <img src={pair.before} alt="Before" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
        <PillTag style={{ top: 10, left: 10, background: "rgba(28,23,21,0.78)", color: "#F2ECE4", fontSize: 9, padding: "4px 10px" }}>Before</PillTag>
      </div>
      <div style={{ position: "relative", aspectRatio: "2 / 3" }}>
        <img src={pair.after} alt="After" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
        <PillTag style={{ top: 10, left: 10, background: "#F2ECE4", color: "#2A2420", fontSize: 9, padding: "4px 10px" }}>After</PillTag>
      </div>
    </div>);

}

function CampaignFromOne() {
  return (
    <div className="pp-ba-campaign-wrap" style={{ marginTop: 96 }}>
      {/* Header */}
      <div style={{ marginBottom: 32, maxWidth: 760 }}>
        <div style={{
          fontFamily: "La Villa", fontSize: 11, letterSpacing: "0.22em",
          textTransform: "uppercase", fontWeight: 500, color: "var(--ink-mute)"
        }}>02 · One image, whole campaign</div>
        <p className="italic-serif" style={{
          marginTop: 14, marginBottom: 0,
          fontSize: 28, lineHeight: 1.2, color: "var(--ink)",
          letterSpacing: "-0.01em"
        }}>One product photo. Four finished images. Same afternoon.

        </p>
      </div>

      {/* Single row: source + arrow + 4 variations, all the same portrait aspect */}
      <div className="pp-ba-campaign" style={{
        display: "grid",
        gridTemplateColumns: "1.05fr auto repeat(4, 1fr)",
        gap: 14,
        alignItems: "stretch"
      }}>
        {/* Source */}
        <CampaignCard
          src={CAMPAIGN_SOURCE}
          alt="Source product photo"
          tag="Product"
          tagDark
          caption="What you upload"
          isSource />
        

        {/* Arrow divider */}
        <div className="pp-ba-arrow" style={{
          alignSelf: "center",
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          gap: 8,
          padding: "0 4px",
          color: "var(--ink-mute)"
        }}>
          <div style={{
            fontFamily: "La Villa", fontSize: 9, letterSpacing: "0.22em",
            textTransform: "uppercase", fontWeight: 600, writingMode: "vertical-rl",
            transform: "rotate(180deg)"
          }}>VARIATION PRESET

          </div>
          <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden>
            <path d="M3 10h14M12 5l5 5-5 5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />
          </svg>
        </div>

        {/* Variations */}
        {CAMPAIGN_VARIATIONS.map((v, i) =>
        <CampaignCard
          key={i}
          src={v.src}
          alt={v.label}
          tag={`0${i + 1}`}
          caption={v.label} />

        )}
      </div>
    </div>);

}

function CampaignCard({ src, alt, tag, tagDark, caption, isSource }) {
  return (
    <figure style={{
      margin: 0,
      position: "relative",
      borderRadius: 0,
      overflow: "hidden",
      background: isSource ? "#ffffff" : "var(--card)",
      border: "1px solid var(--card-line)",
      aspectRatio: "3 / 4"
    }}>
      <img
        src={src}
        alt={alt}
        style={{
          width: "100%", height: "100%",
          objectFit: isSource ? "contain" : "cover",
          objectPosition: "center",
          padding: isSource ? 12 : 0,
          display: "block"
        }} />
      <PillTag style={{
        top: 12, left: 12,
        background: tagDark ? "var(--ink)" : "var(--cream)",
        color: tagDark ? "var(--on-dark)" : "var(--ink)",
        fontSize: 9, padding: "5px 11px",
        borderRadius: 0
      }}>{tag}</PillTag>
      {caption &&
      <figcaption style={{
        position: "absolute", left: 0, right: 0, bottom: 0,
        padding: "44px 14px 12px",
        color: "var(--on-dark)",
        background: "linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.55) 100%)",
        fontFamily: "La Villa", fontSize: 11, letterSpacing: "0.04em"
      }}>
          <span className="italic-serif" style={{ opacity: 0.95 }}>{caption}</span>
        </figcaption>
      }
    </figure>);

}

window.BeforeAfter = BeforeAfter;