// import { fetchCompanyCategories, fetchCompanys } from "@/app/api/companys";
import React, { useState, } from "react";
import CompanyHoliday from "./CompanyHoliday";
import CompanyHolidayLoading from "./CompanyHolidayLoading";
import { fetchCompanys } from "@/app/api/companys";
import Holidays from "date-holidays";
import { HolidaysResult, fetchHolidays, HolidaysList } from "@/app/api/holidays";
import { convertDateArrayToString } from "@/app/utils/formatUtil";
import { fetchUserAbilities } from "@/app/utils/fetchUtil";

interface SubComponents {
  Loading: typeof CompanyHolidayLoading;
}

const CompanyHolidayWrapper: React.FC & SubComponents = async () => {
  // const Companys = await fetchCompanys();

 const [companyHolidays, abilities] = await Promise.all([fetchHolidays(), fetchUserAbilities()])

//  console.log(companyHolidays)
 const convertedHolidays = companyHolidays.map((holiday) => {
  return {
    id: holiday.id.toString(),
    title: holiday.name,
    date: convertDateArrayToString(holiday.date, "YYYY-MM-DD", false)
  }
 })
 

  return <CompanyHoliday holidays={convertedHolidays as HolidaysList[]} abilities={abilities}/>;
};

CompanyHolidayWrapper.Loading = CompanyHolidayLoading;

export default CompanyHolidayWrapper;
