import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "core-js/modules/web.timers.js";
import React, { useEffect, useState } from 'react';
import { FcrButton } from '../button';
import './index.css';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var LoginConfirmDialog = function LoginConfirmDialog(_ref) {
  var title = _ref.title,
    desc = _ref.desc,
    id = _ref.id,
    btnTxt = _ref.btnTxt,
    isShowCoutDown = _ref.isShowCoutDown,
    onConfirm = _ref.onConfirm,
    _ref$showImg = _ref.showImg,
    showImg = _ref$showImg === void 0 ? true : _ref$showImg,
    imgSrc = _ref.imgSrc;
  var _useState = useState(6),
    _useState2 = _slicedToArray(_useState, 2),
    countDown = _useState2[0],
    setCountDown = _useState2[1];
  useEffect(function () {
    var timer;
    if (isShowCoutDown) {
      timer = setInterval(function () {
        if (countDown === 0) {
          clearInterval(timer);
          onConfirm && onConfirm();
        }
        setCountDown(countDown - 1);
      }, 1000);
    }
    return function () {
      clearInterval(timer);
    };
  }, [countDown, isShowCoutDown]);
  return /*#__PURE__*/_jsxs("div", {
    className: "fcr-login-confirm-dialog-content",
    children: [showImg && /*#__PURE__*/_jsx("div", {
      className: "fcr-login-confirm-dialog-img",
      children: /*#__PURE__*/_jsx("img", {
        style: {
          width: 280,
          height: 192
        },
        src: imgSrc,
        alt: ""
      })
    }), title && /*#__PURE__*/_jsx("div", {
      className: "fcr-login-confirm-dialog-title",
      children: title
    }), /*#__PURE__*/_jsx("div", {
      className: "fcr-login-confirm-dialog-desc",
      children: desc
    }), /*#__PURE__*/_jsx("div", {
      className: "fcr-login-confirm-dialog-btn",
      children: /*#__PURE__*/_jsxs(FcrButton, {
        size: "S",
        shape: "rounded",
        onClick: function onClick() {
          onConfirm && onConfirm();
        },
        children: [btnTxt, isShowCoutDown && "(".concat(countDown, "s)")]
      })
    })]
  });
};