import Contact1 from "@/components/contact/Contact1";
import React from "react";
import Banner from "@/components/banner/Banner";
import { getPageData, getSiteSettings, fetchComponentData } from "@/utils/data";
import { notFound } from 'next/navigation';

export const revalidate = 3600;

export async function generateMetadata() {
  const slugArr = ["contact"];
  const { data, error, page_info } = await getPageData({
    slug_list: slugArr,
    downloadFiles: false // Do not download files for metadata
  });
  const siteSettings = await getSiteSettings();
  const siteName = siteSettings.site_name || '';
  const siteNameInPageTitles = siteSettings.site_name_in_page_titles || 'None';

  if (error) {
    return {
      title: error.title || 'Contact Error',
      description: error.message || '',
    };
  }

  let title = '';
  if (Array.isArray(data) && page_info) {
    title = page_info.meta_title || page_info.title || '';
  } else {
    title = data?.meta_title || data?.title || '';
  }

  if (siteName && title) {
    if (siteNameInPageTitles === 'After') {
      title = `${title} - ${siteName}`;
    } else if (siteNameInPageTitles === 'Before') {
      title = `${siteName} - ${title}`;
    }
  }

  return {
    title,
    description: data?.meta_description || data?.description || '',
  };
}

export default async function Page() {
  const slugArr = ["contact"];
  
  // 获取页面数据
  const { data, error } = await getPageData({
    slug_list: slugArr,
    downloadFiles: false,
    rewriteToProxy: true
  });

  if (error) {
    notFound();
  }

  return (
    <>
      <div className="grow shrink-0">
        <Banner
          componentName="Banner-contact"
          className="contact-banner"
        />
        <Contact1 />
      </div>
    </>
  );
}
