import Container from "@/components/Container/Container";
import Section from "@/components/Section/Section";
import React from "react";
import Image from "next/image";
import { getCachedUser, getCachedMedia } from "@/services/wp";

const TeamQuestion = async (props: any) => {
  const user = await getCachedUser(props.team_member);

  if (!user) return <></>;
  if (!user?.acf?.profile_image) return <></>;

  const image = await getCachedMedia(user.acf.profile_image);

  let userTwo;
  let imageTwo;

  if (props.second_team_member) {
    userTwo = await getCachedUser(props.second_team_member);

    if (userTwo && userTwo?.acf?.profile_image) {
      imageTwo = await getCachedMedia(userTwo?.acf.profile_image);
    }
  }

  return (
    <Container id={props.anchor}>
      <Section gridArea="thin" className={"overflow-visible"}>
        <h3 className={"h1"}>{props.title}</h3>
        <div>
          <Image
            className={"rounded-xl xl:block hidden absolute -left-[120px]"}
            src={image.source_url}
            alt={user.name}
            width={"100"}
            height={"100"}
          />
          <p>
            <strong>&quot;</strong>
            {props.content}
            <strong>&quot;</strong>
          </p>
        </div>
        <p className={"h3 flex justify-start items-center gap-xs"}>
          <Image
            className={"rounded-xl block xl:hidden"}
            src={image.source_url}
            alt={user.name}
            width={"100"}
            height={"100"}
          />
          {user.name.split(" ")[0]}, {user.acf.role}
        </p>
        {props.second_team_member && (
          <>
            <div>
              <Image
                className={"rounded-xl xl:block hidden absolute -right-[120px]"}
                src={imageTwo.source_url}
                alt={"test"}
                width={"100"}
                height={"100"}
              />
              <p className={"text-right"}>
                <strong>&quot;</strong>
                {props.answer}
                <strong>&quot;</strong>
              </p>
            </div>
            <p
              className={
                "h3 flex justify-start items-center gap-xs justify-end"
              }
            >
              {userTwo.name.split(" ")[0]}, {userTwo.acf.role}
              <Image
                className={"rounded-xl block xl:hidden"}
                src={imageTwo.source_url}
                alt={"test"}
                width={"100"}
                height={"100"}
              />
            </p>
          </>
        )}
      </Section>
    </Container>
  );
};

export default TeamQuestion;
