"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/pdf-exports/index.ts
var pdf_exports_exports = {};
__export(pdf_exports_exports, {
  BrandedPdfPage: () => BrandedPdfPage,
  ExportFooterPdf: () => ExportFooterPdf,
  ExportHeaderPdf: () => ExportHeaderPdf,
  FOOTER_SAFE_AREA_PT: () => FOOTER_SAFE_AREA_PT,
  buildExportFilename: () => buildExportFilename,
  buildExportUrl: () => buildExportUrl,
  generateQrDataUrl: () => generateQrDataUrl,
  resolveProminence: () => resolveProminence,
  tierToProminence: () => tierToProminence
});
module.exports = __toCommonJS(pdf_exports_exports);

// src/pdf-exports/prominence.ts
function tierToProminence(tier) {
  if (tier === "patron") return "refined";
  if (tier === "supporter") return "refined";
  return "maximum";
}
function resolveProminence(brand, tier) {
  if (brand.prominenceMap) return brand.prominenceMap(tier);
  return tierToProminence(tier);
}

// src/pdf-exports/qr.ts
async function generateQrDataUrl(url, options) {
  try {
    const qr = await import("qrcode");
    const toDataURL = qr.default?.toDataURL ?? qr.toDataURL;
    return await toDataURL(url, {
      width: options?.size ?? 320,
      margin: options?.margin ?? 1,
      errorCorrectionLevel: options?.errorCorrectionLevel ?? "M",
      color: {
        dark: options?.darkColor ?? "#0c1f22",
        light: options?.lightColor ?? "#ffffff"
      }
    });
  } catch {
    return null;
  }
}

// src/pdf-exports/url-utils.ts
function buildExportUrl({
  brand,
  tool,
  medium,
  shareSlug,
  path,
  params
}) {
  const resolvedPath = path ? path : shareSlug ? `/s/${shareSlug}` : `/tools/${tool}`;
  const base = `https://${brand.domain}${resolvedPath}`;
  const search = new URLSearchParams({
    utm_source: "export",
    utm_medium: medium,
    utm_tool: tool,
    ...params
  });
  return `${base}?${search.toString()}`;
}
function buildExportFilename({
  brand,
  tool,
  titleOrDate,
  ext
}) {
  const brandSlug = slugify(brand.name);
  const titleSlug = slugify(titleOrDate);
  const middle = titleSlug ? `${tool}-${titleSlug}` : tool;
  return `${brandSlug}-${middle}.${ext}`;
}
function slugify(input) {
  if (!input) return "";
  return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
}

// src/pdf-exports/pdf-chrome.tsx
var import_renderer = require("@react-pdf/renderer");
var import_jsx_runtime = require("react/jsx-runtime");
var FOOTER_SAFE_AREA_PT = 72;
function makeChromeStyles(brand) {
  return import_renderer.StyleSheet.create({
    headerRow: {
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "space-between",
      borderBottomWidth: 3,
      borderBottomColor: brand.colors.primary,
      paddingBottom: 10,
      marginBottom: 12,
      gap: 16
    },
    headerLeft: { flexDirection: "column", flexGrow: 1, flexShrink: 1 },
    eyebrow: {
      fontSize: 9,
      letterSpacing: 1.5,
      color: brand.colors.muted,
      textTransform: "uppercase",
      fontFamily: "Helvetica-Bold",
      marginBottom: 2
    },
    title: {
      fontSize: 22,
      fontFamily: "Helvetica-Bold",
      color: brand.colors.ink,
      lineHeight: 1.15
    },
    subtitle: {
      fontSize: 10,
      color: brand.colors.muted,
      marginTop: 3
    },
    lockupRow: {
      flexDirection: "row",
      alignItems: "center",
      gap: 8
    },
    wordmark: {
      fontSize: 13,
      fontFamily: "Helvetica-Bold",
      color: brand.colors.secondary,
      letterSpacing: -0.2
    },
    footerRow: {
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "space-between",
      borderTopWidth: 2,
      borderTopColor: brand.colors.primary,
      paddingTop: 8,
      marginTop: 10,
      gap: 16
    },
    footerLeft: { flexDirection: "row", alignItems: "center", gap: 8 },
    footerMid: {
      flexDirection: "column",
      alignItems: "flex-end",
      flexShrink: 1
    },
    footerUrl: {
      fontSize: 9,
      fontFamily: "Helvetica-Bold",
      color: brand.colors.secondary
    },
    footerDate: {
      fontSize: 8,
      color: brand.colors.muted,
      marginTop: 2
    },
    footerTagline: {
      fontSize: 8,
      color: brand.colors.muted
    },
    footerName: {
      fontSize: 11,
      fontFamily: "Helvetica-Bold",
      color: brand.colors.secondary
    },
    qr: {
      width: 44,
      height: 44
    },
    qrRefined: {
      width: 32,
      height: 32
    },
    // `flex: 1` makes the body fill the page's available flow area between the
    // header and the footer's flow anchor. `marginBottom: FOOTER_SAFE_AREA_PT`
    // carves an explicit safe-zone INSIDE that flow area so overflow children
    // (e.g., a flex column with `justifyContent: "space-around"` and content
    // exceeding the container height) cannot render past the body's bottom
    // edge into the footer's render band. Combined with the page-level
    // `paddingBottom: FOOTER_SAFE_AREA_PT`, this is a 2x defensive carve that
    // covers both normal-flow pagination (where `paddingBottom` is sufficient)
    // and non-paginating distributions (where only `marginBottom` saves you).
    // See the JSDoc on `FOOTER_SAFE_AREA_PT` above for the full rationale.
    pageBody: {
      flex: 1,
      marginBottom: FOOTER_SAFE_AREA_PT
    }
  });
}
function ExportHeaderPdf({
  brand,
  title,
  toolLabel,
  subtitle,
  prominence = "maximum"
}) {
  const styles = makeChromeStyles(brand);
  const lockupSize = prominence === "maximum" ? 32 : 26;
  const titleSize = prominence === "maximum" ? 22 : 18;
  const Logo = brand.renderLogoMarkPdf;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.headerRow, fixed: false, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.headerLeft, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.eyebrow, children: toolLabel }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: [styles.title, { fontSize: titleSize }], children: title }),
      subtitle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.subtitle, children: subtitle }) : null
    ] }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.lockupRow, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Logo, { size: lockupSize, variant: "original" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.wordmark, children: brand.name })
    ] })
  ] });
}
function ExportFooterPdf({
  brand,
  url,
  dateLabel,
  qrDataUrl,
  prominence = "maximum",
  fixed = true
}) {
  const styles = makeChromeStyles(brand);
  const isRefined = prominence === "refined";
  const showTagline = prominence === "maximum" && Boolean(brand.tagline);
  const markSize = isRefined ? 20 : 26;
  const showQr = Boolean(qrDataUrl);
  const Logo = brand.renderLogoMarkPdf;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.footerRow, fixed, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.footerLeft, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Logo, { size: markSize, variant: "original" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.footerName, children: brand.name }),
        showTagline ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.footerTagline, children: brand.tagline }) : null
      ] })
    ] }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: styles.footerMid, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.footerUrl, children: url }),
      dateLabel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: styles.footerDate, children: dateLabel }) : null
    ] }),
    showQr && qrDataUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_renderer.Image,
      {
        src: qrDataUrl,
        style: isRefined ? styles.qrRefined : styles.qr
      }
    ) : null
  ] });
}
function BrandedPdfPage({
  brand,
  title,
  toolLabel,
  subtitle,
  url,
  dateLabel,
  qrDataUrl,
  prominence = "maximum",
  pageStyle,
  size = "LETTER",
  children
}) {
  const styles = makeChromeStyles(brand);
  const defaultPageStyle = {
    paddingTop: 36,
    paddingHorizontal: 36,
    paddingBottom: FOOTER_SAFE_AREA_PT,
    fontFamily: "Helvetica",
    backgroundColor: brand.colors.surface ?? "#ffffff",
    fontSize: 10,
    color: brand.colors.ink
  };
  const mergedPageStyle = { ...defaultPageStyle, ...pageStyle };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.Page, { size, style: mergedPageStyle, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      ExportHeaderPdf,
      {
        brand,
        title,
        toolLabel,
        subtitle,
        prominence
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.View, { style: styles.pageBody, children }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      ExportFooterPdf,
      {
        brand,
        url,
        dateLabel,
        qrDataUrl,
        prominence
      }
    )
  ] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BrandedPdfPage,
  ExportFooterPdf,
  ExportHeaderPdf,
  FOOTER_SAFE_AREA_PT,
  buildExportFilename,
  buildExportUrl,
  generateQrDataUrl,
  resolveProminence,
  tierToProminence
});
//# sourceMappingURL=index.js.map