import DefaultLayout from "@/components/layout/default-layout";
import HomeSearchPageRender from "@/components/search-search/home-search-page-render";
import { PAGE_CONFIG } from "@/lib/appConstant";
import { getSeoSettings } from "@/lib/common/fetch-seo-settings";
import { fetchViewSettings } from "@/lib/common/fetch-view-settings";
import { redirectDefaultPage } from "@/lib/utils";
import { PageConfig, SEO } from "@/types/common";
import { Metadata } from "next";


const config: PageConfig = PAGE_CONFIG.homeSearch;


export default async function HomeSearchPage(props: any) {
  const viewSettings = await fetchViewSettings();

  if (viewSettings) {
    const layoutViewPage = viewSettings.layoutSettingResponse?.viewPage;
    if (config.layout && config.layout.filter(item => layoutViewPage === item).length === 0) {
      const servicePath = viewSettings.servicePath ? `/${viewSettings.servicePath}` : '';
      redirectDefaultPage(layoutViewPage, servicePath);
    }
  }
  return (
    <DefaultLayout sideBar={true} header={true} footer={true} banner={true} bodyMegreLayout={true} autoIpLogin={true} page="home-search" sort={true}>
      <HomeSearchPageRender { ...props }/>
    </DefaultLayout>
  );
}


export const generateMetadata = async (): Promise<Metadata> => {
  const settings: SEO = await getSeoSettings(config);
  return {
    title: settings.title,
    description: settings.metaDescription
  };
};
