import { useIsServer, useViewed } from "../../../hooks";
import { User, useUserData } from "../../../user-context";
import "./index.scss";
import { useGleanClick } from "../../../telemetry/glean-context";
import { Status, usePlacement } from "../../../placement-context";
import { Payload as PlacementData } from "../../../../../libs/pong/types";
import {
BANNER_SCRIMBA_CLICK,
BANNER_SCRIMBA_VIEW,
} from "../../../telemetry/constants";
interface PlacementRenderArgs {
place: any;
extraClassNames?: string[];
click: string;
image: string;
alt?: string;
imageWidth: number;
imageHeight: number;
copy?: string;
cta?: string;
user: User;
style: object;
version?: number;
typ: string;
heading?: string;
showNoAds: boolean;
}
function viewed(pong?: PlacementData) {
pong?.view &&
navigator.sendBeacon?.(
`/pong/viewed?code=${encodeURIComponent(pong?.view)}${
pong?.version ? `&version=${pong.version}` : ""
}`
);
}
export function SidePlacement({
extraClasses = [],
}: {
extraClasses?: string[];
} = {}) {
const placementData = usePlacement();
const { textColor, backgroundColor, textColorDark, backgroundColorDark } =
placementData?.side?.colors || {};
const css = Object.fromEntries(
[
["--place-new-side-background-light", backgroundColor],
["--place-new-side-color-light", textColor],
[
"--place-new-side-background-dark",
backgroundColorDark || backgroundColor,
],
["--place-new-side-color-dark", textColorDark || textColor],
].filter(([_, v]) => Boolean(v))
);
return !placementData?.side ? (
) : placementData.side.cta && placementData.side.heading ? (
Learn front-end development with high quality, interactive courses from{" "} { gleanClick(BANNER_SCRIMBA_CLICK); }} > Scrimba .{" "} {now < Date.parse("2025-01-08") ? "Enroll now and save 25% this New Year!" : "Enroll now!"}
); } export function TopPlacement() { const isServer = useIsServer(); const placementData = usePlacement(); const data = placementData?.hpTop || placementData?.top; const { textColor, backgroundColor, ctaTextColor, ctaBackgroundColor, textColorDark, backgroundColorDark, ctaTextColorDark, ctaBackgroundColorDark, } = data?.colors || {}; const css = Object.fromEntries( [ ["--place-top-background-light", backgroundColor], ["--place-top-color-light", textColor], ["--place-top-cta-background-light", ctaBackgroundColor], ["--place-top-cta-color-light", ctaTextColor], ["--place-top-background-dark", backgroundColorDark || backgroundColor], ["--place-top-color-dark", textColorDark || textColor], [ "--place-top-cta-background-dark", ctaBackgroundColorDark || ctaBackgroundColor, ], ["--place-top-cta-color-dark", ctaTextColorDark || ctaBackgroundColor], ].filter(([_, v]) => Boolean(v)) ); const status = isServer || placementData?.status === Status.loading ? "loading" : data ? "visible" : "fallback"; return (
click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
target="_blank"
rel="sponsored noreferrer"
>
{copy}
{cta && (
click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
target="_blank"
rel="sponsored noreferrer"
>
{cta}
)}
Ad