import DoctorsPage from "@/components/doctors";
import Layout from "@/components/layout/StLayout";
import { getStateInfo } from "@/lib/getStateInfo";
import axios from "axios";

async function Doctors({ searchParams }) {
  const { matchedCity, matchedState } = getStateInfo();

  let doctors = null;
  try {
    const response = await axios.get(
      "https://back-dev.clinic-pro.ir/api/v1/doctors"
    );
    doctors = response.data.$data;
  } catch (error) {
    // console.error("problem with req:", error.message);
    // return redirect("/unauthorized");
  }

  return (
    <Layout>
      <DoctorsPage
        list={doctors}
        params={searchParams}
        matchedCity={matchedCity}
        matchedState={matchedState}
      />
    </Layout>
  );
}

export default Doctors;
