import { languages_types } from "@/types";
import PageHeaderSlider from "@/ui/page-header-slider/PageHeaderSlider";
import React from "react";
import { getDictionary } from "../dictionaries";
import { pages_titles } from "@/constants";
import { Metadata } from "next";
export const metadata: Metadata = {
  title: pages_titles.patient_rights_charter["fa"] + " | " + "بیمارستان شمال",
  description: "Shomal Hospital IPD patient rights charter page",
};

interface patientRightsResponseType {
  status: number;
  data: {
    translations: {
      patientsRights: string | null;
      language: {
        title: string;
        slug: string;
      };
    }[];
  };
  message: string;
}

async function getData(): Promise<patientRightsResponseType> {
  const res = await fetch(
    `http://localhost:3500/api/v1/public-apis/get/human-rights`,
    {
      cache: "no-cache",
    },
  );

  if (!res.ok) {
    throw new Error("Error");
  }

  const data = await res.json();

  return data;
}

export default async function PatientRights({
  params,
}: {
  params: Promise<{ lang: languages_types }>;
}) {
  const { lang } = await params;
  const { patient_rights_charter } = await getDictionary(lang);
  const getdata = await getData();

  const filteredData =
    getdata.data.translations.length > 0
      ? getdata?.data?.translations.find((item) => item.language.slug === lang)
      : null;

  return (
    <>
      <PageHeaderSlider
        lang={lang}
        pageTitle={patient_rights_charter?.page_title}
        imageSrc="/header-slider-1.webp"
      />
      <section className="my-16 container">
        <div className="bg-[#F8F9FA] rounded-4xl md:px-20 px-4 md:py-16 py-4">
          <h3 className="md:text-[3em] text-2xl font-black text-blue-primary text-center relative before:absolute before:w-[100px] before:block before:bg-secondary before:-bottom-5 before:h-[2px] before:left-[50%] before:translate-x-[-50%] ">
            {patient_rights_charter?.page_title}
          </h3>
          <div className="mt-16">
            {filteredData ? (
              <div
                className="textResult"
                dangerouslySetInnerHTML={{
                  __html: filteredData.patientsRights ?? "",
                }}
              />
            ) : (
              ""
            )}
          </div>
        </div>
      </section>
    </>
  );
}
