{"version":3,"sources":["../src/points-history/types.ts","../src/points-history/LegionPointsHistory.tsx"],"names":["LegionPointsHistory"],"mappings":";;;;;;AA6DO,IAAM,oCAAA,GAGT;AAAA,EACF,qBAAA,EAAuB,UAAA;AAAA,EACvB,4BAAA,EAA8B,iBAAA;AAAA,EAC9B,qBAAA,EAAuB,UAAA;AAAA,EACvB,sBAAA,EAAwB,WAAA;AAAA,EACxB,wBAAA,EAA0B,aAAA;AAAA,EAC1B,+BAAA,EAAiC,oBAAA;AAAA,EACjC,kCAAA,EAAoC,uBAAA;AAAA,EACpC,uBAAA,EAAyB,YAAA;AAAA,EACzB,sBAAA,EAAwB,WAAA;AAAA,EACxB,qBAAA,EAAuB;AACzB;ACnDO,SAAS,4BACd,KAAA,EACQ;AACR,EAAA,MAAM,EAAE,OAAA,EAAS,KAAA,GAAQ,OAAA,EAAS,WAAU,GAAI,KAAA;AAEhD,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,wBAAA,EAA0B,OAAO,CAAA;AACrD,EAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,OAAA,EAAS,KAAK,CAAA;AACnC,EAAA,IAAI,SAAA,EAAW,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,aAAa,MAAM,CAAA;AAGvD,EAAA,MAAM,cAAc,MAAA,CAAO,IAAA;AAAA,IACzB;AAAA,GACF;AACA,EAAA,KAAA,MAAW,OAAO,WAAA,EAAa;AAC7B,IAAA,MAAM,KAAA,GAAQ,MAAM,GAAG,CAAA;AACvB,IAAA,IAAI,KAAA,KAAU,UAAa,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAK,CAAA,CAAE,SAAS,CAAA,EAAG;AACrE,MAAA,GAAA,CAAI,YAAA,CAAa,GAAA;AAAA,QACf,qCAAqC,GAAG,CAAA;AAAA,QACxC,OAAO,KAAK;AAAA,OACd;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,IAAI,QAAA,EAAS;AACtB;AAqBO,IAAM,mB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,IAAA,GAAA,MAAA,GAAA,MAAA,CAAS,EAAE,MAAA,EAAQ,gBAAA,EAAkB,KAAA,EAAM,CAAA;AAAA,EAC7C,GAAG,CAAC,MAAA,EAAQ,KAAA,EAAO,SAAA,EAAW,OAAO,CAAC,CAAA;AAEtC,EAAA,MAAM,WAAA,GAAc,YAAY,MAAM;AACpC,IAAA,OAAA,IAAA,IAAA,GAAA,MAAA,GAAA,OAAA,CAAU,sCAAA,CAAA;AAAA,EACZ,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,MAAM,cAAA,GAAsC;AAAA,IAC1C,OAAA,EAAS,OAAA;AAAA,IACT,KAAA;AAAA,IACA,eAAA,EAAiB,aAAA;AAAA,IACjB,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,WAAA,GAAmC;AAAA,IACvC,MAAA,EAAQ,MAAA;AAAA,IACR,QAAA,EAAU,QAAA;AAAA,IACV,KAAA,EAAO,MAAA;AAAA,IACP;AAAA,GACF;AAEA,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,SAAA;AAAA,MACA,KAAA,EAAO,cAAA;AAAA,MACP,aAAA,EAAY,uBAAA;AAAA,MAEZ,QAAA,kBAAA,GAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,GAAA,EAAK,SAAA;AAAA,UACL,GAAA;AAAA,UACA,KAAA,EAAM,uBAAA;AAAA,UACN,KAAA,EAAM,MAAA;AAAA,UACN,OAAA,EAAQ,MAAA;AAAA,UACR,KAAA,EAAO,WAAA;AAAA,UACP,MAAA,EAAQ,UAAA;AAAA,UACR,OAAA,EAAS;AAAA;AAAA;AACX;AAAA,GACF;AAEJ,CAAC","file":"points-history.mjs","sourcesContent":["/**\n * Theming props for the Points History Widget.\n * These map 1:1 to the camelCase URL query params the host page reads.\n */\nexport interface PointsHistoryThemingProps {\n  /** Header row background color */\n  pointsHistoryHeaderBg?: string;\n  /** Header row text color */\n  pointsHistoryHeaderTextColor?: string;\n  /** Alternate row background color (zebra striping) */\n  pointsHistoryAltRowBg?: string;\n  /** Body text color */\n  pointsHistoryTextColor?: string;\n  /** Row border color */\n  pointsHistoryBorderColor?: string;\n  /** Active page button background color */\n  pointsHistoryPaginationActiveBg?: string;\n  /** Active page button text color */\n  pointsHistoryPaginationActiveColor?: string;\n  /** Container font family */\n  pointsHistoryFontFamily?: string;\n  /** Title font size, e.g. \"24px\" */\n  pointsHistoryTitleSize?: string;\n  /** Cell font size, e.g. \"14px\" */\n  pointsHistoryCellSize?: string;\n}\n\n/**\n * Core configuration props for the Points History Widget.\n */\nexport interface PointsHistoryWidgetProps extends PointsHistoryThemingProps {\n  /** Base URL of the Legion application (required) */\n  baseUrl: string;\n  /** JWT auth token (sent via postMessage, never via URL) */\n  authToken?: string;\n  /** Theme preset. Default: \"light\" */\n  theme?: \"light\" | \"dark\";\n  /**\n   * Show a close (✕) button that emits a `CLOSE_WIDGET` postMessage to the\n   * parent window when clicked. Default: false.\n   */\n  showClose?: boolean;\n  /** Widget width CSS value. Default: \"100%\" */\n  width?: string;\n  /** Widget height CSS value. Default: \"600px\" */\n  height?: string;\n  /** Additional CSS class name for the container */\n  className?: string;\n  /** Additional inline styles for the container */\n  style?: React.CSSProperties;\n  /** Callback when the widget iframe has loaded */\n  onLoad?: (detail: { widget: string; theme: string }) => void;\n  /** Callback when the widget iframe fails to load */\n  onError?: (message: string) => void;\n}\n\n/**\n * Mapping from camelCase theming prop names to the camelCase query\n * parameter names the host points-history page reads from\n * `useSearchParams()`.\n */\nexport const POINTS_HISTORY_THEMING_PROP_TO_PARAM: Record<\n  keyof PointsHistoryThemingProps,\n  string\n> = {\n  pointsHistoryHeaderBg: \"headerBg\",\n  pointsHistoryHeaderTextColor: \"headerTextColor\",\n  pointsHistoryAltRowBg: \"altRowBg\",\n  pointsHistoryTextColor: \"textColor\",\n  pointsHistoryBorderColor: \"borderColor\",\n  pointsHistoryPaginationActiveBg: \"paginationActiveBg\",\n  pointsHistoryPaginationActiveColor: \"paginationActiveColor\",\n  pointsHistoryFontFamily: \"fontFamily\",\n  pointsHistoryTitleSize: \"titleSize\",\n  pointsHistoryCellSize: \"cellSize\",\n};\n","import {\n  useRef,\n  useCallback,\n  useMemo,\n  forwardRef,\n  useImperativeHandle,\n} from \"react\";\nimport {\n  type PointsHistoryWidgetProps,\n  type PointsHistoryThemingProps,\n  POINTS_HISTORY_THEMING_PROP_TO_PARAM,\n} from \"./types\";\n\n/**\n * Ref handle exposed by LegionPointsHistory for imperative control.\n */\nexport interface LegionPointsHistoryHandle {\n  /** Reload the widget iframe */\n  refresh: () => void;\n}\n\n/**\n * Build the iframe src URL from widget props.\n */\nexport function buildPointsHistoryWidgetUrl(\n  props: PointsHistoryWidgetProps\n): string {\n  const { baseUrl, theme = \"light\", showClose } = props;\n\n  const url = new URL(\"/widget/points-history\", baseUrl);\n  url.searchParams.set(\"theme\", theme);\n  if (showClose) url.searchParams.set(\"showClose\", \"true\");\n\n  // Append theming params (camelCase param names matching host expectations)\n  const themingKeys = Object.keys(\n    POINTS_HISTORY_THEMING_PROP_TO_PARAM\n  ) as Array<keyof PointsHistoryThemingProps>;\n  for (const key of themingKeys) {\n    const value = props[key];\n    if (value !== undefined && value !== null && String(value).length > 0) {\n      url.searchParams.set(\n        POINTS_HISTORY_THEMING_PROP_TO_PARAM[key],\n        String(value)\n      );\n    }\n  }\n\n  return url.toString();\n}\n\n/**\n * LegionPointsHistory – a React component that embeds the Legion\n * Points History widget via an iframe.\n *\n * @example\n * ```tsx\n * import { LegionPointsHistory } from '@legionhandtech/lht-react-widgets';\n *\n * function App() {\n *   return (\n *     <LegionPointsHistory\n *       baseUrl=\"https://your-legion-domain.com\"\n *       authToken=\"your-jwt-token\"\n *       theme=\"light\"\n *     />\n *   );\n * }\n * ```\n */\nexport const LegionPointsHistory = forwardRef<\n  LegionPointsHistoryHandle,\n  PointsHistoryWidgetProps\n>(function LegionPointsHistory(props, ref) {\n  const {\n    theme = \"light\",\n    authToken,\n    showClose,\n    width = \"100%\",\n    height = \"600px\",\n    className,\n    style,\n    onLoad,\n    onError,\n    baseUrl,\n    ...rest\n  } = props;\n\n  const iframeRef = useRef<HTMLIFrameElement>(null);\n\n  useImperativeHandle(\n    ref,\n    () => ({\n      refresh: () => {\n        const iframe = iframeRef.current;\n        if (iframe?.contentWindow) {\n          iframe.contentWindow.location.reload();\n        }\n      },\n    }),\n    []\n  );\n\n  const src = useMemo(\n    () => buildPointsHistoryWidgetUrl(props),\n    [\n      baseUrl,\n      theme,\n      showClose,\n      ...Object.keys(POINTS_HISTORY_THEMING_PROP_TO_PARAM).map(\n        (k) => rest[k as keyof typeof rest]\n      ),\n    ]\n  );\n\n  const handleLoad = useCallback(() => {\n    const iframe = iframeRef.current;\n    if (authToken && iframe?.contentWindow) {\n      iframe.contentWindow.postMessage(\n        { type: \"AUTH_TOKEN\", token: authToken },\n        baseUrl\n      );\n    }\n    onLoad?.({ widget: \"points-history\", theme });\n  }, [onLoad, theme, authToken, baseUrl]);\n\n  const handleError = useCallback(() => {\n    onError?.(\"Failed to load points history widget\");\n  }, [onError]);\n\n  const containerStyle: React.CSSProperties = {\n    display: \"block\",\n    width,\n    backgroundColor: \"transparent\",\n    ...style,\n  };\n\n  const iframeStyle: React.CSSProperties = {\n    border: \"none\",\n    overflow: \"hidden\",\n    width: \"100%\",\n    height,\n  };\n\n  return (\n    <div\n      className={className}\n      style={containerStyle}\n      data-testid=\"legion-points-history\"\n    >\n      <iframe\n        ref={iframeRef}\n        src={src}\n        title=\"Points History Widget\"\n        width=\"100%\"\n        loading=\"lazy\"\n        style={iframeStyle}\n        onLoad={handleLoad}\n        onError={handleError}\n      />\n    </div>\n  );\n});\n"]}