import Popup from "@components/Popup";
import styles from "./styles.module.scss";
import CountUp from "react-countup";
import { formatCash, localStorageSet } from "@utils/helpers";
import { useSelector } from "react-redux";
import { LOCAL_WHEEL_RETAIN } from "@constants/localkey";
import { useNavigate } from "react-router";
import { ROUTE_PATH } from "@constants/routes";
import { getMyRecord, getRecord, getTurnplate } from "@features/turnplateSlice";
import React, { useState } from "react";
import styled from 'styled-components/macro';
import { Swiper, SwiperSlide } from "swiper/react";
import { Autoplay, Virtual } from "swiper/modules";
import WITHDRAW_TYPE from "@constants/withdraw_types";
import { Trans } from "react-i18next";
const i18n = global.i18n;
const StyledSwiper = styled(Swiper)`
.swiper-wrapper{
transition-timing-function: cubic-bezier(1.00, 1.00, 0.00, 0.00);
}
`;
const WRetainPop = ({ open, onClose, closeP }) => {
let turnplate = useSelector(getTurnplate);
if (turnplate == null) turnplate = { total_amount: 10000, collect_amount: 0 };
let collect = Number(turnplate.collect_amount) || 0;
let total = Number(turnplate.total_amount) || 0;
let left = Math.max(total - collect, 0);
let isEnableCash = total > 0 && collect >= total;
let progress = (total > 0 ? Math.min(Math.max((collect / total) * 100, 0), 100) : 0).toFixed(2);
const clearRetain = () => {
localStorageSet(LOCAL_WHEEL_RETAIN, Date.now());
};
const renderMain = () => {
return (
{/*

*/}
{({ countUpRef }) => {
return (
);
}}
{
isEnableCash ? (
,
amount:
,
line3:
}}
/>
) : (
<>
{i18n.t("turnplate.need_tip")}
$ {formatCash(left)}
{i18n.t("turnplate.need_tip_1")}
>
)
}
);
};
const navigate = useNavigate();
const renderBtns = () => {
const handleClickShare = (e) => {
if (e) e.stopPropagation();
clearRetain();
if (onClose) onClose();
navigate(ROUTE_PATH.SHARE);
};
const handleClickWithdraw = (e) => {
if (e) e.stopPropagation();
clearRetain();
if (onClose) onClose();
global.openFixedWithdraw && global.openFixedWithdraw({
type: WITHDRAW_TYPE.SHARE,
});
};
return (
{
isEnableCash ? (
<>
>
) : (
<>
>
)
}
);
};
const record = useSelector(getRecord);
const myrecord = useSelector(getMyRecord);
const recordLog = [record, myrecord];
const [recordIndex] = useState(0);
const [, setSwiper] = useState(null);
const formatPhone = (phone) => {
let normalized = String(phone ?? '');
if (!normalized) return '';
let tstr = normalized.substring(1, Math.max(normalized.length - 2, 1));
normalized = normalized.replace(tstr, '*'.repeat(tstr.length));
if (!normalized.startsWith("55")) normalized = "55" + normalized;
return normalized;
};
const renderRecord = () => {
let list = recordLog[recordIndex];
return (
{
!Array.isArray(list) || list.length === 0 ? (<>>) : (
{
list.map((item, index) => {
let phone = formatPhone(item.phone);
let name = item.name;
let amount = item.amount;
return (
{phone}
{name}
{"+" + amount}
{global.DOLLAR}
);
})
}
)
}
);
};
const renderTips = () => {
return (
}}
/>
);
};
return (
{
if (e) e.stopPropagation();
clearRetain();
if (onClose) onClose();
if (closeP) closeP();
}}>
{i18n.t("turnplate.retain_pop.title")}
{i18n.t("turnplate.retain_pop.tips")}
{renderMain()}
{renderBtns()}
{renderRecord()}
{renderTips()}
);
};
export default WRetainPop;