import { getUrl } from "@insite/client-framework/ServerSideRendering";

const prepareSitelinksSearchBoxStructuredPageData = () => {
    const url: { protocol: string; host: string } = IS_SERVER_SIDE ? getUrl()! : window.location;
    const authority = `${url.protocol}//${url.host}`;

    const data = {
        "@context": "https://schema.org",
        "@type": "WebSite",
        url: authority,
        potentialAction: {
            "@type": "SearchAction",
            target: {
                "@type": "EntryPoint",
                urlTemplate: `${authority}/api/v1/autocomplete?query={search_term_string}&spireContent=true`,
            },
            "query-input": "required name=search_term_string",
        },
    } as any;

    return JSON.stringify(data);
};

export default prepareSitelinksSearchBoxStructuredPageData;
