// import { fetchSalaryCategories, fetchSalarys } from "@/app/api/companys";
import React from "react";
import SalarySearch from "./SalarySearch";
import SalarySearchLoading from "./SalarySearchLoading";
import { fetchSalarys } from "@/app/api/salarys";
import { fetchUserAbilities } from "@/app/utils/fetchUtil";

interface SubComponents {
  Loading: typeof SalarySearchLoading;
}

// function calculateHourlyRate(loweLimit: number, upperLimit: number, numOfWorkingDay: number, workingHour: number){
//   const hourlyRate = (loweLimit + upperLimit)/2/numOfWorkingDay/workingHour
//   return hourlyRate.toLocaleString()
// }

const SalarySearchWrapper: React.FC & SubComponents = async () => {
  const [Salarys, abilities] = await Promise.all([fetchSalarys(), fetchUserAbilities()]);
  // const Salarys:any[] = []
  const salarysWithHourlyRate = Salarys.map((salary) => {
    // const hourlyRate = calculateHourlyRate(Number(salary.lowerLimit), Number(salary.upperLimit),22, 8)
    return {
      ...salary,
      upperLimit: salary.upperLimit.toLocaleString(),
      lowerLimit: salary.lowerLimit.toLocaleString(),
      hourlyRate: salary.hourlyRate.toLocaleString(),
    }
  })
  // console.log(salarysWithHourlyRate)

  return <SalarySearch salarys={salarysWithHourlyRate} abilities={abilities}/>;
};

SalarySearchWrapper.Loading = SalarySearchLoading;

export default SalarySearchWrapper;
