"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDocumentTitle = useDocumentTitle;
const react_1 = require("react");
const react_native_1 = require("react-native");
const streamplace_store_1 = require("../streamplace-store");
/**
 * Hook to set the document title, description, and favicon on web based on branding.
 * No-op on native platforms.
 */
function useDocumentTitle() {
    const siteTitle = (0, streamplace_store_1.useSiteTitle)();
    const siteDescription = (0, streamplace_store_1.useSiteDescription)();
    const favicon = (0, streamplace_store_1.useFavicon)();
    (0, react_1.useEffect)(() => {
        if (react_native_1.Platform.OS === "web" && typeof document !== "undefined") {
            // set title
            document.title = siteTitle;
            // set or update meta description
            let metaDescription = document.querySelector('meta[name="description"]');
            if (!metaDescription) {
                metaDescription = document.createElement("meta");
                metaDescription.setAttribute("name", "description");
                document.head.appendChild(metaDescription);
            }
            metaDescription.setAttribute("content", siteDescription);
            // set or update favicon
            if (favicon) {
                let link = document.querySelector('link[rel="icon"]');
                if (!link) {
                    link = document.createElement("link");
                    link.rel = "icon";
                    document.head.appendChild(link);
                }
                link.href = favicon;
            }
        }
    }, [siteTitle, siteDescription, favicon]);
}
//# sourceMappingURL=useDocumentTitle.js.map