import { useState, Fragment } from "react";
import { useTranslation } from "next-i18next";

import { AcademicCapIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { Dialog, Transition } from "@headlessui/react";

import {
  profile1,
  profile2,
  profile3,
  profile4,
  profile5,
  profile6,
  profile7,
  profile8,
  profile9,
  profile10,
  profile11,
} from "../data/profiles";

const profiles = [
  profile1,
  profile2,
  profile3,
  profile4,
  profile5,
  profile6,
  profile7,
  profile8,
  profile9,
  profile10,
  profile11,
];

const Profiles = () => {
  return (
  <div className="mx-auto max-w-7xl py-10 lg:py-20">
    <div className="grid gap-y-8 gap-x-8 xl:gap-x-12 xl:gap-y-12 grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 ">
        {profiles.map((profile, index) => {
          return (
            <div
              key={index}
              className="border p-6 border-zinc-200 bg-white rounded-3xl shadow"
            >
              <Item
                key={index}
                title={profile.title}
                text={profile.description}
                description={profile.description}
              />
            </div>
          );
        })}
      </div>
    </div>
  );
};

const Item = ({ title, text, description }) => {
  const { t: translate } = useTranslation();
  const [open, setOpen] = useState(false);

  return (
    <>
      <div className="cursor-pointer" onClick={() => setOpen(true)}>
        <AcademicCapIcon className="h-8 w-8 mb-4 mx-auto" aria-hidden="true" />
        <p className="font-oswald text-4xl mb-4 text-center">
          {translate(title)}
        </p>
        <p className="font-opensans leading-relaxed text-center">
          {translate(text)}
        </p>
      </div>

      <Transition.Root show={open} as={Fragment}>
        <Dialog
          as="div"
          className="relative z-10"
          onClose={() => setOpen(false)}
        >
          <Transition.Child
            as={Fragment}
            enter="ease-out duration-300"
            enterFrom="opacity-0"
            enterTo="opacity-100"
            leave="ease-in duration-200"
            leaveFrom="opacity-100"
            leaveTo="opacity-0"
          >
            <div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
          </Transition.Child>

          <div className="fixed inset-0 z-10 overflow-y-auto">
            <div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
              <Transition.Child
                as={Fragment}
                enter="ease-out duration-300"
                enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
                enterTo="opacity-100 translate-y-0 sm:scale-100"
                leave="ease-in duration-200"
                leaveFrom="opacity-100 translate-y-0 sm:scale-100"
                leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
              >
                <Dialog.Panel className="relative transform overflow-hidden rounded-xl bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg">
                  <div className="bg-white px-4 pb-4 pt-5 sm:p-6 sm:pb-4">
                    <div className="sm:flex sm:items-start">
                      <div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-zinc-200 sm:mx-0 sm:h-10 sm:w-10">
                        <AcademicCapIcon
                          className="h-6 w-6 text-zinc-800"
                          aria-hidden="true"
                        />
                      </div>
                      <div className="mt-3 text-center sm:mx-4 sm:mt-0 sm:text-left">
                        <Dialog.Title
                          as="h3"
                          className="text-base font-oswald font-semibold leading-6"
                        >
                          {translate(title)}
                        </Dialog.Title>
                        <div className="mt-2">
                          <p className="text-sm text-gray-500">
                            {translate(text)}
                          </p>
                        </div>
                        <div className="mt-2">
                          <p className="text-sm text-gray-500">
                            {translate(description)}
                          </p>
                        </div>
                      </div>
                      <button
                        className="focus:outline-none mx-auto flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full hover:bg-zinc-100 sm:mx-0 sm:h-8 sm:w-8"
                        onClick={() => setOpen(false)}
                      >
                        <XMarkIcon
                          className="h-4 w-4 text-zinc-400 "
                          aria-hidden="true"
                        />
                      </button>
                    </div>
                  </div>
                </Dialog.Panel>
              </Transition.Child>
            </div>
          </div>
        </Dialog>
      </Transition.Root>
    </>
  );
};

export default Profiles;
