import DoctorPage from "@/components/doctor";
import Layout from "@/components/layout/StLayout";
import axios from "axios";

async function Doctor({ params: { slug } }) {
  let doctor = null;
  let comments = null;
  const API_URL = process.env.NEXT_PUBLIC_API_URL;

  try {
    const resDoctor = await axios.get(`${API_URL}/api/v1/doctor/${slug}`);

    doctor = resDoctor.data;
    if (doctor) {
      const resComments = await axios.get(
        `${API_URL}/api/v1/clinicpro/comments/${doctor.id}`
      );
      comments = resComments?.data?.data;
    }
  } catch (error) {
    // console.error("problem with req:", error.message);
    // return redirect("/unauthorized");
  }

  return (
    <Layout>
      <DoctorPage doctor={doctor} comments={comments} />
    </Layout>
  );
}

export default Doctor;
