/* Dexilion — case study: arrow routing for Excalidraw.
   One page per case study; copy lives in SITE.caseStudies.excalidraw. */

(function () {
  const { Button } = window;
  const {
    Ico,
    Grain,
    Grid,
    Eyebrow,
    Shell,
    tx,
    SiteHeader,
    PageHero,
    ConversionBand,
    SiteFooter,
  } = window;

  const CS = () => window.SITE.caseStudies.excalidraw;

  /* The mono particulars strip under the masthead — facts, not adjectives. */
  function Facts() {
    const c = CS();
    return (
      <div
        className="dx-case-facts"
        style={{
          marginTop: "38px",
          display: "grid",
          gridTemplateColumns: "repeat(4,auto)",
          justifyContent: "start",
          gap: "0 40px",
        }}
      >
        {c.facts.map((f, i) => (
          <div
            key={i}
            className="dx-case-fact"
            style={{
              paddingLeft: i ? "40px" : 0,
              borderLeft: i ? "1px solid rgba(255,255,255,.14)" : "none",
            }}
          >
            <div
              style={{
                font: "var(--text-eyebrow)",
                letterSpacing: "var(--ls-eyebrow)",
                textTransform: "uppercase",
                color: "var(--neutral-400)",
              }}
            >
              {f.label}
            </div>
            <div
              style={{
                marginTop: "8px",
                fontFamily: "var(--font-mono)",
                fontSize: "15px",
                color: "var(--white)",
              }}
            >
              {tx(f.value)}
            </div>
          </div>
        ))}
      </div>
    );
  }

  /* The recording sits directly under the masthead, then the framing prose at
     the brand's 720px measure. One band, because they are one thought. */
  function Opening() {
    const c = CS();
    return (
      <section
        style={{
          background: "var(--paper-50)",
          padding: "var(--section-y-compact) 0 var(--section-y)",
          position: "relative",
          overflow: "hidden",
        }}
      >
        <Grain />
        <Shell>
          <figure style={{ position: "relative", margin: 0 }}>
            <img
              src={c.media.src}
              alt={c.media.alt}
              style={{
                display: "block",
                width: "100%",
                height: "auto",
                borderRadius: "var(--radius-surface)",
                border: "1px solid var(--border-subtle)",
                background: "var(--white)",
              }}
            />
            <figcaption
              style={{
                marginTop: "14px",
                fontFamily: "var(--font-mono)",
                fontSize: "12px",
                color: "var(--text-muted)",
              }}
            >
              {tx(c.media.caption)}
            </figcaption>
          </figure>

          <div
            className="dx-indent"
            style={{
              position: "relative",
              maxWidth: "var(--container-narrow)",
              marginTop: "64px",
            }}
          >
            {c.intro.map((p, i) => (
              <p
                key={i}
                style={{
                  margin: i ? "22px 0 0" : 0,
                  fontSize: "var(--fs-body-lg)",
                  lineHeight: "var(--lh-body)",
                  color: i === 1 ? "var(--text-strong)" : "var(--text-body)",
                  fontWeight: i === 1 ? "var(--fw-medium)" : "inherit",
                  textWrap: "pretty",
                }}
              >
                {tx(p)}
              </p>
            ))}
          </div>
        </Shell>
      </section>
    );
  }

  /* The four constraints as a ruled list — the brand's default for "here are
     our N things". Numbered in mono, titled in serif, no card grid. */
  function Constraints() {
    const c = CS().constraints;
    return (
      <section
        style={{
          background: "var(--white)",
          padding: "var(--section-y) 0",
          borderTop: "1px solid var(--paper-200)",
          position: "relative",
          overflow: "hidden",
        }}
      >
        <Grid fade="linear-gradient(180deg,#000 0%,transparent 60%)" />
        <Shell>
          <div
            className="dx-services-grid"
            style={{
              position: "relative",
              display: "grid",
              gridTemplateColumns: "340px 1fr",
              gap: "56px",
              alignItems: "start",
            }}
          >
            <div
              className="dx-services-side"
              style={{ position: "sticky", top: "104px" }}
            >
              <Eyebrow>{c.eyebrow}</Eyebrow>
              <h2
                style={{
                  font: "var(--text-h1)",
                  letterSpacing: "var(--ls-heading)",
                  margin: "18px 0 0",
                  color: "var(--text-strong)",
                }}
              >
                {c.heading}
              </h2>
              <p
                style={{
                  margin: "18px 0 0",
                  fontSize: "var(--fs-body)",
                  lineHeight: "var(--lh-body)",
                  color: "var(--text-muted)",
                  maxWidth: "32ch",
                }}
              >
                {tx(c.lede)}
              </p>
            </div>
            <div>
              <div style={{ borderTop: "1px solid var(--paper-200)" }}>
                {c.items.map((item, i) => (
                  <div key={i} className="dx-rule-row">
                    <span className="dx-rule-num">
                      {String(i + 1).padStart(2, "0")}
                    </span>
                    <span
                      style={{
                        fontFamily: "var(--font-serif)",
                        fontSize: "24px",
                        fontWeight: "var(--fw-medium)",
                        letterSpacing: "var(--ls-heading)",
                        lineHeight: 1.3,
                        color: "var(--text-strong)",
                      }}
                    >
                      {tx(item)}
                    </span>
                  </div>
                ))}
              </div>
              <p
                style={{
                  margin: "28px 0 0",
                  maxWidth: "54ch",
                  fontSize: "var(--fs-body)",
                  lineHeight: "var(--lh-body)",
                  color: "var(--text-body)",
                }}
              >
                {tx(c.note)}
              </p>
            </div>
          </div>
        </Shell>
      </section>
    );
  }

  function Approach() {
    const a = CS().approach;
    return (
      <section
        style={{
          background: "var(--paper-50)",
          padding: "var(--section-y) 0",
          position: "relative",
          overflow: "hidden",
        }}
      >
        <Grain />
        <Shell>
          <div
            className="dx-split"
            style={{
              position: "relative",
              display: "grid",
              gridTemplateColumns: "340px 1fr",
              gap: "56px",
              alignItems: "start",
            }}
          >
            <div>
              <Eyebrow>{a.eyebrow}</Eyebrow>
              <h2
                style={{
                  font: "var(--text-h1)",
                  letterSpacing: "var(--ls-heading)",
                  margin: "18px 0 0",
                  color: "var(--text-strong)",
                }}
              >
                {a.heading}
              </h2>
            </div>
            <div style={{ maxWidth: "62ch" }}>
              {a.body.map((p, i) => (
                <p
                  key={i}
                  style={{
                    margin: i ? "22px 0 0" : 0,
                    fontSize: "var(--fs-body-lg)",
                    lineHeight: "var(--lh-body)",
                    color: "var(--text-body)",
                    textWrap: "pretty",
                  }}
                >
                  {tx(p)}
                </p>
              ))}
              <blockquote
                style={{
                  margin: "36px 0 0",
                  paddingLeft: "22px",
                  borderLeft: "3px solid var(--gold-400)",
                  font: "var(--text-quote)",
                  color: "var(--text-strong)",
                  maxWidth: "40ch",
                }}
              >
                {tx(a.quote)}
              </blockquote>
            </div>
          </div>
        </Shell>
      </section>
    );
  }

  function Outcome() {
    const o = CS().outcome;
    return (
      <section
        className="dx-dark"
        style={{
          background: "var(--ink-900)",
          color: "var(--white)",
          padding: "var(--section-y) 0",
          position: "relative",
          overflow: "hidden",
        }}
      >
        <Grid dark fade="linear-gradient(0deg,#000 0%,transparent 90%)" />
        <Grain dark />
        <Shell>
          <div
            className="dx-indent"
            style={{
              position: "relative",
              maxWidth: "var(--container-narrow)",
            }}
          >
            <Eyebrow color="var(--gold-400)">{o.eyebrow}</Eyebrow>
            <h2
              style={{
                font: "var(--text-h1)",
                letterSpacing: "var(--ls-heading)",
                margin: "18px 0 0",
                color: "var(--white)",
                textWrap: "balance",
              }}
            >
              {o.heading}
            </h2>
            {o.body.map((p, i) => (
              <p
                key={i}
                style={{
                  margin: "22px 0 0",
                  maxWidth: "56ch",
                  fontSize: "var(--fs-body-lg)",
                  lineHeight: "var(--lh-body)",
                  color: "var(--powder-500)",
                  textWrap: "pretty",
                }}
              >
                {tx(p)}
              </p>
            ))}
            <div
              style={{
                display: "flex",
                gap: "40px",
                flexWrap: "wrap",
                marginTop: "40px",
                paddingTop: "24px",
                borderTop: "1px solid rgba(255,255,255,.12)",
              }}
            >
              {o.stats.map((s, i) => (
                <div key={i}>
                  <div
                    style={{
                      fontFamily: "var(--font-mono)",
                      fontSize: "22px",
                      fontWeight: "var(--fw-semibold)",
                      color: "var(--gold-400)",
                    }}
                  >
                    {tx(s.value)}
                  </div>
                  <div
                    style={{
                      fontSize: "var(--fs-caption)",
                      color: "var(--neutral-400)",
                      marginTop: "4px",
                    }}
                  >
                    {tx(s.label)}
                  </div>
                </div>
              ))}
            </div>
            <div style={{ marginTop: "40px" }}>
              <Button
                variant="secondary"
                onClick={() => {
                  window.location.href = "work.html";
                }}
                iconLeft={<Ico n="arrow-left" s={17} />}
                style={{
                  background: "transparent",
                  color: "var(--white)",
                  borderColor: "rgba(255,255,255,.28)",
                }}
              >
                {CS().backLabel}
              </Button>
            </div>
          </div>
        </Shell>
      </section>
    );
  }

  function Page() {
    const c = CS();
    return (
      <React.Fragment>
        <SiteHeader active="work" />
        <PageHero eyebrow={c.eyebrow} headline={c.headline}>
          <Facts />
        </PageHero>
        <Opening />
        <Constraints />
        <Approach />
        <Outcome />
        <ConversionBand />
        <SiteFooter />
      </React.Fragment>
    );
  }

  mountPage(<Page />);
})();
