import { cookies } from "next/headers";
import { categoryService } from "@/services/category";
import { shopService } from "@/services/shop";
import { globalService } from "@/services/global";
import { parseSettings } from "@/utils/parse-settings";
import storyService from "@/services/story";
import { Home2Content } from "./home-2-content";

const HomePage = async () => {
  const lang = (await cookies()).get("lang")?.value || "fa";
  const countryId = (await cookies()).get("country_id")?.value || undefined;
  const cityId = (await cookies()).get("city_id")?.value || undefined;
  const services = await categoryService.getAll({
    lang,
    type: "sub_main",
    perPage: 11,
    column: "input",
    sort: "asc",
  });
  const shops = await shopService.getAll({
    lang,
    perPage: 8,
    country_id: countryId,
    city_id: cityId,
  });
  const stories = await storyService.getAll({ lang });
  const settings = await globalService.settings();
  const parsedSettings = parseSettings(settings?.data);
  return (
    <Home2Content
      settings={parsedSettings}
      services={services}
      shops={shops}
      stories={stories}
    />
  );
};

export default HomePage;
