/*@typescript-eslint/no-explicit-any*/

import { IMAGE_BASE_URL, buildStorageUrl } from "@/components/main/BaseUrl";
import Head from "next/head";

type SEOProps = {
  type: "store" | "user" | "billboard" | "billboardSingle";
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  data: any; // داده مربوط به هر نوع صفحه
};

const SEO: React.FC<SEOProps> = ({ type, data }) => {
  let title = "";
  let description = "";
  let image = "";

  switch (type) {
    case "store":
      title = `${data.title} - ${data?.city?.name} - ${data.neighbourhood} - مدستاگرام`;
      description = `${data.description} - ${data.services}`;
      image = IMAGE_BASE_URL+ data.images[0];
      break;

    case "user":
      title = `${data.first_name} ${data.last_name} `;
      description = `${data.bio} - ${data.user_name} - ${data.expertise}`;
      image = buildStorageUrl(data.profile_image);
      break;

    case "billboard":
      title = `بیلبوردها - ${data.city || "همه شهرها"}`;
      description = data.top10Titles?.join(" - ") || "بیلبوردهای برتر";
      image = data.logo || "/images/logo.png";
      break;

    case "billboardSingle":
      title = `${data.title} - ${data.category} - ${data.neighbourhood} - مدستاگرام`;
      description = `${data.category} - ${data?.city?.name} - ${data.neighbourhood} - ${data?.address || "ادرس"}`;
      image = `${IMAGE_BASE_URL}${data.images[0]}`;
      break;
  }

  // اطمینان از URL کامل برای تصویر
  if (image && !image.startsWith("http")) {
    image = `${process.env.NEXT_PUBLIC_BASE_URL}${image}`;
  }

  return (
    <Head>
      <title>{title}</title>
      <meta name="description" content={description} />

      {/* Open Graph */}
      <meta property="og:title" content={title} />
      <meta property="og:description" content={description} />
      <meta property="og:image" content={image} />
      <meta property="og:type" content="website" />

      {/* Twitter Card */}
      <meta name="twitter:card" content="summary_large_image" />
      <meta name="twitter:title" content={title} />
      <meta name="twitter:description" content={description} />
      <meta name="twitter:image" content={image} />
    </Head>
  );
};

export default SEO;
