import Title from "@/components/Title";
import styles from "./styles.module.scss";
import { compatibilityV4Prefix } from "@/routes";
import { useMemo, useRef } from "react";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";
import {useSelector} from "react-redux";
import { selectors } from "@/store";

interface IPoint {
  icon: string;
  title: string;
  text: string;
}

function HowWork() {
  const { translate } = useTranslations(ELocalesPlacement.CompatibilityV4);
  const { relationshipStatus } = useSelector(selectors.selectCompatibilityV4Answers);
  const textContainersRef = useRef([] as HTMLDivElement[]);

  const points: IPoint[] = useMemo(
    () => {
        console.log(relationshipStatus)
        console.log(relationshipStatus === "single" ? translate("/trial-payment.how_work.single.point1_title") : translate("/trial-payment.how_work.point1_title"))
        console.log(translate("/trial-payment.how_work.single.point1_title"))
        console.log(translate("/trial-payment.how_work.point1_title"))
        return [
      {
        icon: `${compatibilityV4Prefix}/check-mark.svg`,
        title: relationshipStatus === "single" ? translate("/trial-payment.how_work.single.point1_title") : translate("/trial-payment.how_work.point1_title"),
        text: translate("/trial-payment.how_work.point1_text"),
      },
      {
        icon: `${compatibilityV4Prefix}/check-mark.svg`,
        title: translate("/trial-payment.how_work.point2_title"),
        text: translate("/trial-payment.how_work.point2_text"),
      },
      {
        icon: `${compatibilityV4Prefix}/circle-in-ring.svg`,
        title: translate("/trial-payment.how_work.point3_title"),
        text: translate("/trial-payment.how_work.point3_text"),
      },
      {
        icon: `${compatibilityV4Prefix}/ring.svg`,
        title: translate("/trial-payment.how_work.point4_title"),
        text: translate("/trial-payment.how_work.point4_text"),
      },
    ]},
    [translate]
  );

  return (
    <div className={styles.container}>
      {points.map((point, index) => (
        <div className={styles.block} key={index}>
          <div className={styles["left-side"]}>
            <img src={point.icon} alt="Check mark" />
            <div
              className={styles["vertical-line"]}
              style={{
                height: `${
                  (textContainersRef.current?.[index]?.clientHeight || 0) - 26
                }px`,
              }}
            />
          </div>
          <div
            className={styles["text-container"]}
            ref={(el) =>
              (textContainersRef.current[index] = el as HTMLDivElement)
            }
          >
            <Title variant="h3" className={styles.title}>
              {point.title}
            </Title>
            <p className={styles.text}>{point.text}</p>
          </div>
        </div>
      ))}
      {/* <MoneyBackGuarantee /> */}
    </div>
  );
}

export default HowWork;
