import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.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/es.object.to-string.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 _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["block", "loading", "type", "shape", "styleType", "size", "preIcon", "preIconProps", "postIcon", "postIconProps", "disabled", "onClick", "extra", "className", "onHover"];
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 React, { useState } from 'react';
import { FcrPopover } from '../popover';
import classnames from 'classnames';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import './index.css';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var FcrButton = function FcrButton(props) {
  var block = props.block,
    loading = props.loading,
    _props$type = props.type,
    type = _props$type === void 0 ? 'primary' : _props$type,
    _props$shape = props.shape,
    shape = _props$shape === void 0 ? 'rounded' : _props$shape,
    styleType = props.styleType,
    _props$size = props.size,
    size = _props$size === void 0 ? 'L' : _props$size,
    preIcon = props.preIcon,
    preIconProps = props.preIconProps,
    postIcon = props.postIcon,
    postIconProps = props.postIconProps,
    disabled = props.disabled,
    _onClick = props.onClick,
    extra = props.extra,
    className = props.className,
    onHover = props.onHover,
    otherProps = _objectWithoutProperties(props, _excluded);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    hover = _useState2[0],
    setHover = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    extraPopoverVisible = _useState4[0],
    setExtraPopoverVisible = _useState4[1];
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    extraHover = _useState6[0],
    setExtraHover = _useState6[1];
  var iconColor = styleType === 'white' ? type === 'primary' ? hover ? "var(--)" : "var(--)" : undefined : undefined;
  return /*#__PURE__*/_jsxs("button", _objectSpread(_objectSpread({
    onMouseEnter: function onMouseEnter() {
      if (disabled) return;
      setHover(true);
      onHover === null || onHover === void 0 || onHover(true);
    },
    onMouseLeave: function onMouseLeave() {
      if (disabled) return;
      setHover(false);
      onHover === null || onHover === void 0 || onHover(false);
    }
  }, otherProps), {}, {
    onClick: function onClick() {
      return !disabled && (_onClick === null || _onClick === void 0 ? void 0 : _onClick());
    },
    className: classNames('fcr-button', "fcr-button-".concat(type), "fcr-button-".concat(shape), "fcr-button-".concat(size), 'fcr-btn-click-effect', _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "fcr-button-".concat(styleType), !!styleType), 'fcr-button-icon-only', !props.children), 'fcr-button-block', block), 'fcr-button-with-extra', extra), 'fcr-button-extra-active', (extra === null || extra === void 0 ? void 0 : extra.visible) || extraPopoverVisible || extraHover), 'fcr-button-disabled', disabled), className),
    children: [preIcon && /*#__PURE__*/_jsx("div", {
      className: "fcr-button-icon fcr-button-preicon",
      children: /*#__PURE__*/_jsx(FcrIcon, _objectSpread({
        type: preIcon
      }, preIconProps))
    }), /*#__PURE__*/_jsx("div", {
      children: props.children
    }), extra && /*#__PURE__*/_jsx("div", {
      className: "fcr-button-extra fcr-divider",
      children: /*#__PURE__*/_jsx(FcrPopover, _objectSpread(_objectSpread({
        trigger: "click",
        showArrow: true,
        visible: extraPopoverVisible,
        mouseEnterDelay: 0,
        onVisibleChange: setExtraPopoverVisible
      }, extra), {}, {
        children: /*#__PURE__*/_jsx("div", {
          onMouseEnter: function onMouseEnter() {
            setExtraHover(true);
          },
          onMouseLeave: function onMouseLeave() {
            setExtraHover(false);
          },
          onClick: function onClick(e) {
            e.preventDefault();
            e.stopPropagation();
          },
          className: classnames('fcr-button-extra-inner', {
            'fcr-button-extra-inner-active': (extra === null || extra === void 0 ? void 0 : extra.visible) || extraPopoverVisible || extraHover
          }),
          children: /*#__PURE__*/_jsx(FcrIcon, {
            type: FcrIconType.FCR_MORE2
          })
        })
      }))
    }), (loading || postIcon) && !extra && /*#__PURE__*/_jsx("div", {
      className: "fcr-button-icon-wrapper",
      children: /*#__PURE__*/_jsx(FcrIcon, _objectSpread({
        className: classNames('fcr-button-icon fcr-button-posticon', {
          'fcr-button-loading': loading
        }),
        type: loading ? FcrIconType.FCR_BTN_LOADING : postIcon,
        colors: loading ? {
          iconPrimary: 'white'
        } : undefined
      }, postIconProps))
    })]
  }));
};