import styles from "./styles.module.scss";
import Blob from "../../images/SVG/Blob";
import { images } from "../../data";
import Title from "@/components/Title";
import Button from "../../components/Button";
import Blob2 from "../../images/SVG/Blob2";
import { useNavigate } from "react-router-dom";
import routes from "@/routes";
import { usePaywall } from "@/hooks/paywall/usePaywall";
import { EPlacementKeys } from "@/api/resources/Paywall";
import { addCurrency, ELocalesPlacement } from "@/locales";
import { useTranslations } from "@/hooks/translations";
import { useEffect } from "react";
import metricService, { EGoals, EMetrics } from "@/services/metric/metricService";

const placementKey = EPlacementKeys["aura.placement.compatibility.v2.secret.discount"]

function SaveOff() {
    const { translate } = useTranslations(ELocalesPlacement.EmailMarketingCompatibilityV2);
    const { products, currency, getText } = usePaywall({
        placementKey,
        localesPlacement: ELocalesPlacement.EmailMarketingCompatibilityV2,
    });
    // const activeProductFromStore = useSelector(selectors.selectActiveProduct);
    // const activeProduct = products.find(product => product?.trialPrice === activeProductFromStore?.trialPrice) || products[0]
    const activeProduct = products[0]
    const trialPrice = (activeProduct?.trialPrice || 0) / 100;

    const navigate = useNavigate();

    const handleNext = () => {
        navigate(routes.client.compatibilityV2SecretDiscount());
    }

    useEffect(() => {
        metricService.reachGoal(EGoals.DISCOUNT_PAGE_VISIT, [EMetrics.YANDEX, EMetrics.KLAVIYO]);
    }, []);

    return (
        <>
            <Blob className={styles.blob} />
            <Blob2 className={styles.blob2} />
            <img className={styles.gift} src={images("discount/gift.svg")} alt="gift" />
            <Title className={styles.title}>
                {translate("save-off.title", { discount: getText("discount") })}
            </Title>
            <p className={styles.description}>
                {translate("save-off.instead", {
                    price: <span className={styles.price}>{addCurrency(trialPrice, currency)}</span>,
                    oldPrice: <span className={styles.discount}>
                        {translate("save-off.instead-old-price", {
                            oldPrice: addCurrency(getText("old.price") as string, currency)
                        })}
                    </span>
                })}
            </p>
            <p className={styles.point} style={{ marginTop: 12 }}>
                <img src={images("discount/fire.png")} alt="fire" />
                {translate("save-off.trial-duration", {
                    // days: trialDuration
                    trialDuration: getText("trial.duration"),
                    oldTrialDuration: <s>{translate("save-off.old-trial-duration", {
                        oldTrialDuration: getText("old.trial.duration")
                    })}</s>,
                })}
            </p>
            <p className={styles.point}>
                <img src={images("discount/gift.png")} alt="gift" />
                {translate("save-off.discount-offer", { discount: getText("discount") })}
            </p>
            <Button className={styles.button} onClick={handleNext}>
                {translate("save-off.button-trial", { days: getText("trial.duration") })}
            </Button>
        </>
    )
}

export default SaveOff