// partner-shared.jsx — shared components and styles used across all partner pages

// ── Shared brand panel shell (gradient + glow) ────────────────────────────────

const BRAND_GRADIENT = "linear-gradient(145deg, #072B1E 0%, #0B4A30 38%, #10A171 72%, #0D7A56 100%)";

const BrandPanelShell = ({ style, children }) => (
  <div style={{
    flex: 1, position: "relative", overflow: "hidden",
    background: BRAND_GRADIENT,
    display: "flex", flexDirection: "column",
    ...style,
  }}>
    <div style={{
      position: "absolute", inset: 0, pointerEvents: "none",
      background: "radial-gradient(ellipse 70% 60% at 70% 30%, rgba(16,161,113,.35) 0%, transparent 70%)",
    }} />
    {children}
  </div>
);

// ── Login brand panel ─────────────────────────────────────────────────────────

const PartnerBrandPanel = () => (
  <BrandPanelShell style={{ justifyContent: "flex-end", padding: "52px 56px" }}>
    <div style={{ position: "relative", zIndex: 1, marginBottom: 40 }}>
      <div style={{
        fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
        fontSize: "clamp(36px, 3.6vw, 54px)", lineHeight: 1.05,
        color: "#fff", letterSpacing: "-0.01em", marginBottom: 14,
      }}>
        {t("PartnerBrandPanel.taglineLine1")}<br />{t("PartnerBrandPanel.taglineLine2")}
      </div>
      <p style={{ margin: 0, fontSize: 15, color: "rgba(255,255,255,.58)", lineHeight: 1.6, maxWidth: 340 }}>
        {t("PartnerBrandPanel.subtext")}
      </p>
    </div>

    <div style={{ position: "relative", zIndex: 1, display: "flex", alignItems: "center" }}>
      {/* Phone sidebar */}
      <div style={{
        width: 52, zIndex: 2, position: "relative", flexShrink: 0,
        background: "rgba(255,255,255,.97)", borderRadius: 18,
        boxShadow: "0 8px 32px rgba(0,0,0,.22)",
        display: "flex", flexDirection: "column",
        alignItems: "center", justifyContent: "space-between",
        padding: "18px 0 16px", height: 200, marginRight: -16,
      }}>
        <div style={{ display: "flex", flexDirection: "column", gap: 14, alignItems: "center" }}>
          <div style={{ width: 34, height: 34, borderRadius: 10, background: "var(--accent)", display: "grid", placeItems: "center" }}>
            <svg viewBox="0 0 24 24" fill="white" width="15" height="15"><path d="M3 12l9-9 9 9v9a1 1 0 01-1 1h-5v-6H9v6H4a1 1 0 01-1-1v-9z"/></svg>
          </div>
          <svg viewBox="0 0 24 24" fill="none" stroke="rgba(10,10,11,.25)" strokeWidth="1.6" width="15" height="15"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>
          <svg viewBox="0 0 24 24" fill="none" stroke="rgba(10,10,11,.25)" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" width="15" height="15"><path d="M12 3l8 3v6c0 5-3.5 8.4-8 9-4.5-.6-8-4-8-9V6l8-3z"/></svg>
        </div>
        <div style={{ width: 32, height: 32, borderRadius: 10, background: "var(--accent)", display: "grid", placeItems: "center" }}>
          <Ic.sparkle width="16" height="16" style={{ color: "#fff" }} />
        </div>
      </div>

      {/* Info card */}
      <div style={{
        flex: 1, background: "#fff", borderRadius: 20,
        boxShadow: "0 8px 32px rgba(0,0,0,.16)", padding: "22px 20px",
      }}>
        <div style={{ marginBottom: 14, opacity: 0.15 }}>
          <Logo size={20} />
        </div>
        <div style={{ fontSize: 32, fontWeight: 700, letterSpacing: "-0.035em", color: "var(--ink)", lineHeight: 1 }}>24</div>
        <div style={{ fontSize: 12, color: "var(--mute)", marginTop: 4, marginBottom: 18 }}>{t("PartnerBrandPanel.newReferrals")}</div>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", paddingTop: 14, borderTop: "1px solid var(--rule)" }}>
          <div>
            <div style={{ fontSize: 13, fontWeight: 600, color: "var(--ink)", letterSpacing: "-0.01em" }}>{t("PartnerBrandPanel.activeCasesLabel")}</div>
            <div style={{ fontSize: 11, color: "var(--mute)", marginTop: 2 }}>{t("PartnerBrandPanel.activeCasesSubtext")}</div>
          </div>
          <div style={{ fontSize: 16, fontWeight: 700, color: "var(--ink)", letterSpacing: "-0.02em" }}>7</div>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 14 }}>
          <span style={{ fontSize: 11, color: "var(--mute)", fontWeight: 500 }}>{t("PartnerBrandPanel.avgJobValue")}</span>
          <div style={{ fontSize: 13, fontWeight: 700, color: "var(--ink)", letterSpacing: "-0.02em" }}>€2,300</div>
        </div>
      </div>
    </div>
  </BrandPanelShell>
);

// ── Sign-up brand panel ───────────────────────────────────────────────────────

const PartnerSignUpBrandPanel = () => (
  <BrandPanelShell style={{ padding: "40px 52px 0px" }}>
    <div style={{ position: "relative", zIndex: 1, paddingTop: 64 }}>
      <div style={{
        fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
        fontSize: "clamp(28px, 3vw, 44px)", lineHeight: 1.05,
        color: "#fff", letterSpacing: "-0.01em", marginBottom: 12,
      }}>
        {t("PartnerSignUpBrandPanel.taglineLine1")}<br />{t("PartnerSignUpBrandPanel.taglineLine2")}
      </div>
      <p style={{ margin: 0, fontSize: 14, color: "rgba(255,255,255,.55)", lineHeight: 1.6 }}>
        {t("PartnerSignUpBrandPanel.subtext")}
      </p>
    </div>

    <div style={{
      position: "relative", zIndex: 1,
      display: "flex", flexDirection: "column",
      gap: 20, paddingTop: 113,
    }}>
      {[
        t("PartnerSignUpBrandPanel.bullet1"),
        t("PartnerSignUpBrandPanel.bullet2"),
        t("PartnerSignUpBrandPanel.bullet3"),
      ].map((text, i) => (
        <div key={i} style={{ display: "flex", gap: 12, alignItems: "flex-start" }}>
          <div style={{
            width: 20, height: 20, borderRadius: "50%", background: "rgba(255,255,255,.14)",
            display: "grid", placeItems: "center", flexShrink: 0, marginTop: 2,
          }}>
            <svg viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" width="10" height="10">
              <path d="M5 12.5l4.5 4.5L19 7"/>
            </svg>
          </div>
          <span style={{ fontSize: 13.5, color: "rgba(255,255,255,.78)", lineHeight: 1.6 }}>{text}</span>
        </div>
      ))}
    </div>

    <div style={{ flex: 1 }} />

    <div style={{ position: "relative", zIndex: 1, marginLeft: -52, marginRight: -52 }}>
      <svg viewBox="0 0 400 130" width="100%" preserveAspectRatio="xMidYMax meet">
        <rect x="-20" y="50" width="120" height="120" rx="6"
          fill="rgba(255,255,255,.04)" stroke="rgba(255,255,255,.14)" strokeWidth="1"
          transform="rotate(-20, 40, 110)" />
        <rect x="155" y="30" width="90" height="90" rx="4"
          fill="rgba(255,255,255,.05)" stroke="rgba(255,255,255,.16)" strokeWidth="1"
          transform="rotate(45, 200, 75)" />
        <rect x="178" y="53" width="44" height="44" rx="2"
          fill="rgba(255,255,255,.06)" stroke="rgba(255,255,255,.2)" strokeWidth="0.8"
          transform="rotate(45, 200, 75)" />
        <polygon points="320,120 380,20 440,120"
          fill="rgba(255,255,255,.04)" stroke="rgba(255,255,255,.15)" strokeWidth="1" />
        <circle cx="370" cy="55" r="18"
          fill="rgba(255,255,255,.05)" stroke="rgba(255,255,255,.18)" strokeWidth="0.8" />
        <circle cx="110" cy="35" r="3" fill="rgba(255,255,255,.2)" />
        <circle cx="125" cy="28" r="2" fill="rgba(255,255,255,.14)" />
        <circle cx="138" cy="40" r="2.5" fill="rgba(255,255,255,.12)" />
      </svg>
    </div>
  </BrandPanelShell>
);

// ── Shared card shell ─────────────────────────────────────────────────────────

const PartnerPageShell = ({ children }) => (
  <div style={{ minHeight: "100vh", background: "var(--bg)", display: "flex", alignItems: "center", justifyContent: "center", padding: "40px 20px" }}>
    <div style={{ display: "flex", width: "100%", maxWidth: 900, minHeight: 560, borderRadius: 24, overflow: "hidden", boxShadow: "var(--shadow-lg)", border: "1px solid var(--rule)" }}>
      {children}
    </div>
  </div>
);

// ── Small shared sub-components ───────────────────────────────────────────────

const PartnerTypeCard = ({ value, selected, onSelect, title }) => (
  <button
    type="button"
    data-testid={`partner-type-${value}`}
    onClick={() => onSelect(value)}
    style={{
      appearance: "none", fontFamily: "var(--sans)", cursor: "default",
      textAlign: "center", padding: "12px 14px", borderRadius: 10,
      border: selected ? "1.5px solid var(--accent)" : "1.5px solid rgba(10,10,11,.1)",
      background: selected ? "var(--accent-tint)" : "#F7F7F5",
      transition: "border-color .15s ease, background .15s ease",
      fontSize: 13, fontWeight: 600,
      color: selected ? "var(--accent-ink)" : "var(--ink)",
      letterSpacing: "-0.01em",
    }}>
    {title}
  </button>
);

const PartnerField = ({ label, children }) => (
  <div style={{ display: "flex", flexDirection: "column", gap: 7 }}>
    <label style={{ fontSize: 13, fontWeight: 500, color: "var(--ink-3)" }}>{label}</label>
    {children}
  </div>
);

const PasswordInput = ({ value, onChange, show, onToggle }) => (
  <div style={{ position: "relative" }}>
    <input
      type={show ? "text" : "password"} placeholder="••••••••"
      value={value} onChange={onChange} autoComplete="current-password"
      style={{ ...loginInputStyle, paddingRight: 42 }}
    />
    <button type="button" onClick={onToggle} style={eyeButtonStyle}>
      {show ? (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" width="15" height="15">
          <path d="M17.9 17.9A9.9 9.9 0 0112 20C6 20 2 12 2 12a18 18 0 015.1-6.1M9.9 4.2A9.6 9.6 0 0112 4c6 0 10 8 10 8a18 18 0 01-2.1 3.1M1 1l22 22"/>
          <path d="M10.5 10.6a3 3 0 004 4"/>
        </svg>
      ) : (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" width="15" height="15">
          <path d="M2 12s4-8 10-8 10 8 10 8-4 8-10 8S2 12 2 12z"/>
          <circle cx="12" cy="12" r="3"/>
        </svg>
      )}
    </button>
  </div>
);

const PartnerSubmitBtn = ({ loading, label, loadingLabel, testId }) => (
  <button
    type="submit" disabled={loading}
    data-testid={testId}
    style={{
      marginTop: 4, width: "100%", height: 46, borderRadius: 10,
      background: loading ? "var(--accent-ink)" : "var(--accent)",
      color: "#fff", border: "none", fontSize: 15, fontWeight: 600,
      fontFamily: "var(--sans)", letterSpacing: "-0.01em",
      cursor: "default", display: "flex", alignItems: "center",
      justifyContent: "center", gap: 8, transition: "background .15s ease",
    }}>
    {loading ? <><SpinnerIcon /> {loadingLabel}</> : label}
  </button>
);

// ── Helpers ───────────────────────────────────────────────────────────────────

// Logo that links back home — shared across login / signup / activate.
const PartnerLogoHome = ({ onHome }) => (
  <a href="/" onClick={(e) => { e.preventDefault(); onHome && onHome(); }} style={{ display: "inline-block" }}>
    <Logo size={28} />
  </a>
);

// Inline form error box (red tint). Routes through the --danger* tokens.
const PartnerErrorBox = ({ children }) => (
  <div style={{ background: "var(--danger-tint)", color: "var(--danger)", borderRadius: 8, padding: "10px 14px", fontSize: 13.5, lineHeight: 1.5 }}>
    {children}
  </div>
);

// Scroll to top once when a partner page mounts.
const useScrollTopOnMount = () => React.useEffect(() => { window.scrollTo(0, 0); }, []);

const HoverLink = ({ onClick, children, disabled }) => {
  const [hovered, setHovered] = React.useState(false);
  return (
    <button
      type="button"
      onClick={onClick}
      disabled={disabled}
      onMouseEnter={() => setHovered(true)}
      onMouseLeave={() => setHovered(false)}
      style={{
        ...linkBtnStyle,
        textDecoration: hovered && !disabled ? "underline" : "none",
        textDecorationColor: "var(--accent-ink)",
        color: disabled ? "var(--mute)" : hovered ? "var(--accent)" : "var(--accent-ink)",
        cursor: disabled ? "default" : linkBtnStyle.cursor,
        transition: "color .15s ease",
      }}>
      {children}
    </button>
  );
};

const loginInputStyle = {
  fontFamily: "var(--sans)", fontSize: 14, color: "var(--ink)",
  background: "#F7F7F5", border: "1px solid rgba(10,10,11,.1)",
  borderRadius: 8, padding: "11px 14px", outline: "none",
  width: "100%", boxSizing: "border-box", transition: "border-color .15s ease",
};

const forgotStyle = {
  appearance: "none", background: "none", border: "none", padding: 0,
  fontSize: 12.5, color: "var(--accent-ink)", cursor: "default",
  fontFamily: "var(--sans)", fontWeight: 500,
};

const linkBtnStyle = {
  appearance: "none", background: "none", border: "none", padding: 0,
  color: "var(--accent-ink)", fontSize: 12.5, fontWeight: 500,
  cursor: "default", fontFamily: "var(--sans)",
};

const eyeButtonStyle = {
  position: "absolute", right: 12, top: "50%", transform: "translateY(-50%)",
  appearance: "none", background: "none", border: "none", padding: 4,
  color: "var(--mute)", cursor: "default", display: "grid", placeItems: "center",
};

const SpinnerIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"
    strokeLinecap="round" width="14" height="14"
    style={{ animation: "spin 0.8s linear infinite" }}>
    <path d="M12 2a10 10 0 010 20" strokeOpacity="0.3"/>
    <path d="M12 2a10 10 0 0110 10"/>
  </svg>
);
