import { defineWebPage } from "nuxt-schema-org/schema";

interface ProjectParams {
  name: string;
  description: string;
  image: string;
  url: string;
}

export const useProjectSchema = ({
  name,
  description,
  image,
  url,
}: ProjectParams) => {
  const { locale } = useI18n();
  const config = useRuntimeConfig();
  const siteUrl = config.public.BASE_URL;

  const toAbs = (path: string) => new URL(path, siteUrl).toString();

  useSchemaOrg([
    defineWebPage({
      "@id": `${toAbs(url)}#webpage`,
      name: name,
      description: description,
      url: toAbs(url),
      inLanguage: locale.value,
      primaryImageOfPage: {
        "@type": "ImageObject",
        url: image,
      },
      isPartOf: {
        "@id": "https://webstdy.com/#identity",
      },
    }),
  ]);
};
