import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.reverse.js";
import "core-js/modules/es.object.to-string.js";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import classnames from 'classnames';
import { useState, useEffect, useRef, useMemo } from 'react';
import { FcrIcon } from '../icon';
import { FcrButton } from '../button';
import { FcrIconType } from '../icon/type';
import './index.css';
import { useI18n } from '../../i18n';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var ConfirmContent = function ConfirmContent(props) {
  var t = useI18n();
  var onOk = props.onOk,
    onCancel = props.onCancel,
    onClose = props.onClose,
    _props$closable = props.closable,
    closable = _props$closable === void 0 ? true : _props$closable,
    closeIcon = props.closeIcon,
    _props$cancelText = props.cancelText,
    cancelText = _props$cancelText === void 0 ? t('fmt_popup_button_cancel') : _props$cancelText,
    _props$okText = props.okText,
    okText = _props$okText === void 0 ? t('fmt_uimanager_button_determine') : _props$okText,
    _props$showCancel = props.showCancel,
    showCancel = _props$showCancel === void 0 ? true : _props$showCancel,
    _props$showOk = props.showOk,
    showOk = _props$showOk === void 0 ? true : _props$showOk,
    width = props.width,
    title = props.title,
    content = props.content,
    icon = props.icon,
    alignCenter = props.alignCenter,
    cancelButtonProps = props.cancelButtonProps,
    okButtonProps = props.okButtonProps,
    reverseButton = props.reverseButton,
    tip = props.tip,
    className = props.className;
  var wrapperRef = useRef(null);
  var defaultColor = 'var(--fcr_ui_scene_icontext1)';
  var hoverColor = 'var(--fcr_ui_scene_ramp_brand6)';
  var _useState = useState(defaultColor),
    _useState2 = _slicedToArray(_useState, 2),
    color = _useState2[0],
    setColor = _useState2[1];
  var handleHover = function handleHover() {
    setColor(hoverColor);
  };
  var handleLeave = function handleLeave() {
    setColor(defaultColor);
  };
  useEffect(function () {
    if (wrapperRef.current && width) {
      wrapperRef.current.style.setProperty('width', width + 'px');
    }
  }, [width]);
  var buttons = [showCancel && /*#__PURE__*/_jsx(FcrButton, _objectSpread(_objectSpread({
    size: "XS",
    type: "secondary",
    onClick: onCancel
  }, cancelButtonProps), {}, {
    children: cancelText
  }), 0), showOk && /*#__PURE__*/_jsx(FcrButton, _objectSpread(_objectSpread({
    size: "XS",
    onClick: onOk
  }, okButtonProps), {}, {
    children: okText
  }), 1)];
  var layoutType = useMemo(function () {
    return alignCenter ? 'center' : 'space-between';
  }, [alignCenter]);
  var isCenter = layoutType === 'center' && buttons.filter(function (btn) {
    return btn;
  }).length === 1;
  return /*#__PURE__*/_jsxs("div", {
    ref: wrapperRef,
    className: classnames('fcr-confirm-content-wrapper', className, {
      'fcr-confirm-content-wrapper__center': layoutType === 'center'
    }),
    children: [closable ? closeIcon ? closeIcon : /*#__PURE__*/_jsx("div", {
      onClick: onClose || onCancel,
      className: classnames('fcr-confirm-content-dialog-close'),
      onMouseEnter: handleHover,
      onMouseLeave: handleLeave,
      children: /*#__PURE__*/_jsx(FcrIcon, {
        type: FcrIconType.FCR_CLOSE,
        colors: {
          iconPrimary: color
        },
        size: 14
      })
    }) : null, /*#__PURE__*/_jsxs("div", {
      className: classnames("fcr-confirm-container", {
        'align-center': alignCenter && !icon,
        icon: icon
      }),
      children: [icon && /*#__PURE__*/_jsx("div", {
        className: "fcr-confirm-content-icon",
        children: /*#__PURE__*/_jsx(FcrIcon, {
          type: icon,
          size: 40
        })
      }), title && /*#__PURE__*/_jsx("div", {
        className: "fcr-confirm-content-title",
        children: title
      }), /*#__PURE__*/_jsxs("div", {
        className: "fcr-confirm-content-content",
        children: [content, tip && /*#__PURE__*/_jsx("p", {
          className: "fcr-confirm-content-tip fcr-confirm-content-tip-".concat(tip.type || 'error'),
          children: tip.message
        })]
      })]
    }), (showCancel || showOk) && /*#__PURE__*/_jsx("div", {
      className: classnames('fcr-confirm-content-footer', {
        'fcr-button-flex-column': (cancelButtonProps === null || cancelButtonProps === void 0 ? void 0 : cancelButtonProps.block) || (okButtonProps === null || okButtonProps === void 0 ? void 0 : okButtonProps.block),
        'fcr-confirm-content-footer__center': layoutType === 'center',
        'fcr-confirm-content-footer__center-button': isCenter
      }),
      children: reverseButton ? buttons.reverse() : buttons
    })]
  });
};
export { ConfirmContent };