import { useNavigate } from "react-router-dom";
import { useTranslations } from "@/hooks/translations";
import routes from "@/routes";
import styles from "./styles.module.css";
import MainButton from "../MainButton";
import Title from "../Title";
import { useApi, useApiCall } from "@/api";
import { useCallback } from "react";
import { Asset } from "@/api/resources/Assets";

function FeedbackPage(): JSX.Element {
  const { translate } = useTranslations();
  const navigate = useNavigate();
  const api = useApi();
  const handleNext = () => navigate(routes.client.freePeriodInfo());

  const assetsData = useCallback(async () => {
    const { assets } = await api.getAssets({ category: String("au") });
    return assets;
  }, [api]);

  const {
    data: assets,
    // isPending
  } = useApiCall<Asset[]>(assetsData);

  const reviews = [
    {
      title: translate("aura.name_1.review"),
      text: translate("aura.review_1.content"),
      imageKey: "au.1.avatar",
    },
    {
      title: translate("aura.name_2.review"),
      text: translate("aura.review_2.content"),
      imageKey: "au.2.avatar",
    },
  ];

  return (
    <section className={`${styles.page} page`}>
      <div className={styles.reviews}>
        {reviews.map(({ title, text, imageKey }, index) => (
          <div className={styles.review} key={index}>
            <div className={styles.images}>
              <img
                className={styles["profile-picture"]}
                src={assets?.find((asset) => asset.key === imageKey)?.url}
                alt="profile picture"
              />
              <div className={styles["header-container"]}>
                <Title variant="h3">{title}</Title>
                <img className={styles.stars} src="/5-stars.webp" alt="stop" />
              </div>
            </div>
            <p className={styles.text}>{text}</p>
          </div>
        ))}
      </div>
      <MainButton onClick={handleNext}>{translate("next")}</MainButton>
    </section>
  );
}

export default FeedbackPage;
