import React from "react";


type Meta = {title:string, description:string, keywords:string, image:string, canonical:string }
type MetaKeys = keyof Meta;
export const Meta:Meta = {
    title:"",
    description:"",
    keywords:"",
    image:"",
    canonical:""
};

type MetasInputs = { [Property in MetaKeys]?: string };
export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null=>
{
    const    additive = props.concatListed ? (key:MetaKeys, value:string)=> Meta[key] += value : (key:MetaKeys, value:string)=> Meta[key] = value;
    const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta[key] = "" : (key:MetaKeys)=> {};

    Object.keys(Meta).forEach((key)=>{
        const metaKey = key as MetaKeys;
        const propValue = props[metaKey]||"";
        propValue ? additive(metaKey, propValue) : subtractive(metaKey);
    })

    console.log(`rendering metas`, Meta)

    if(window.innerWidth)
    {
        document.title = Meta.title;
    }

    return null;
}