import { createEffect, onCleanup } from "solid-js";

const SITE_NAME = "National CD Rateline";

export function createDocumentTitle(title) {
    createEffect(() => {
        const previousTitle = document.title;
        const t = title();
        document.title = t ? `${t} | ${SITE_NAME}` : SITE_NAME;

        onCleanup(() => {
            document.title = previousTitle;
        });
    });
}

export function PageWithTitle(props) {
    createDocumentTitle(() => props.route.title || props.route.label);
    return props.children;
}
