import { useQuery } from '@tanstack/react-query';

import { staticFetch } from '@/api';

const fetchAboutPage = async (slug: string, locale?: string) => {
  const filename = `${slug}${locale ? `.${locale}` : ''}.html`;

  const { data } = await staticFetch(`/instance/about/${filename}`);

  if (data.includes('<div id="plfe">')) return '';

  return data;
};

const useAboutPage = (slug = 'index', locale?: string) =>
  useQuery({
    queryKey: ['pl-fe', 'aboutPages', slug, locale],
    queryFn: () => fetchAboutPage(slug, locale),
  });

export { useAboutPage };
