'use client';

import { partner_api } from '@/features/about/lib/api';
import { useQuery } from '@tanstack/react-query';
import { useParams } from 'next/navigation';
import { useEffect } from 'react';

export default function AboutSEO() {
  const { locale } = useParams();

  const { data } = useQuery({
    queryKey: ['aboutData'],
    queryFn: async () => (await partner_api.getAbout()).data,
  });

  useEffect(() => {
    if (!data) return;
    const banner = data.banner;
    const title =
      locale === 'uz'
        ? banner.title_uz
        : locale === 'ru'
          ? banner.title_ru
          : banner.title_en;
    const description =
      locale === 'uz'
        ? banner.description_uz
        : locale === 'ru'
          ? banner.description_ru
          : banner.description_en;

    document.title = title || 'Gastro Market';
    const descMeta = document.querySelector('meta[name="description"]');
    if (descMeta) descMeta.setAttribute('content', description || '');
  }, [data, locale]);

  return null;
}
