import type { Review, Settings } from "~/types/Contact";

export const useContactSchema = (
  settings = {} as Settings,
  reviews: Review[] = [],
  t: any,
) => {
  const localPath = useLocalePath();
  const config = useRuntimeConfig();
  const siteUrl = config.public.BASE_URL;

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

  const socialLinks = [
    settings?.facebook_link,
    settings?.instagram_link,
    settings?.tiktok_link,
    settings?.X_link,
    settings?.linkedIn_link,
    settings?.snapchat_link,
    settings?.youtube_link,
  ].filter(Boolean);

  const contactPoints = [
    {
      "@type": "ContactPoint",
      telephone: "+9661000025705",
      contactType: "customer service",
      email: "info@webstdy.com",
      areaServed: "Worldwide",
      availableLanguage: ["en", "ar"],
      additionalProperty: {
        "@type": "PropertyValue",
        name: "WhatsApp",
        value: "+9661000025705",
      },
    },
  ];

  const mainAddress = {
    "@type": "PostalAddress",
    streetAddress: "38 شارع الثورة، الدقي، الجيزة",
    addressLocality: "الجيزة",
    postalCode: "12345",
    addressCountry: "EG",
  };

  const aggregateRating = {
    "@type": "AggregateRating",
    ratingValue: "4.9",
    bestRating: "5",
    worstRating: "1",
    reviewCount: "57",
  };

  useSchemaOrg([
    {
      "@type": "ContactPage",
      name: t("contact"),
      description: t("contactSeo.description"),
    },
    {
      "@type": ["LocalBusiness", "ProfessionalService"],
      "@id": `${toAbs(localPath("/contact"))}#business`,
      name: "WebSTDY - Software Development Company",
      description:
        "Professional software development agency specializing in web applications, mobile apps, and custom software solutions",
      url: toAbs(localPath("/contact")),
      image:
        settings?.light_logo ||
        "https://webstdy.com/web/img/2022/new-share-image.png",
      telephone: "+9661000025705",
      email: "info@webstdy.com",
      address: mainAddress,
      contactPoint: contactPoints,
      openingHoursSpecification: {
        "@type": "OpeningHoursSpecification",
        dayOfWeek: ["Monday", "Tuesday", "Wednesday", "Thursday", "Sunday"],
        opens: "10:00",
        closes: "20:00",
      },
      aggregateRating,
      review: reviews.map((review) => ({
        "@type": "Review",
        author: {
          "@type": "Person",
          name: review.author,
        },
        reviewRating: {
          "@type": "Rating",
          ratingValue: review.rating.toString(),
          bestRating: "5",
          worstRating: "1",
        },
        reviewBody: review.body,
        datePublished: "2025-11-10",
      })),
      ...(socialLinks.length > 0 && { sameAs: socialLinks }),
      parentOrganization: {
        "@id": "https://webstdy.com/#identity",
      },
    },
  ]);
};
