import React, { useContext, useMemo } from 'react';
import clsx from 'clsx';
import { Button } from '../button';
import ActionBarContext from './ActionBarContext';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var ActionBarButton = function ActionBarButton(props) {
  var type = props.type,
      icon = props.icon,
      text = props.text,
      color = props.color,
      loading = props.loading,
      disabled = props.disabled,
      index = props.index;

  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('action-bar-button', prefixCls),
      bem = _createNamespace[0];

  var _useContext2 = useContext(ActionBarContext),
      parent = _useContext2.parent;

  var isFirst = useMemo(function () {
    if (parent) {
      var prev = parent.children[index - 1];
      return !(prev && 'isButton' in prev.type);
    }

    return false;
  }, [index, parent]);
  var isLast = useMemo(function () {
    if (parent) {
      var next = parent.children[index + 1];
      return !(next && 'isButton' in next.type);
    }

    return false;
  }, [index, parent]);
  return /*#__PURE__*/React.createElement(Button, {
    className: clsx(props.className, bem([type, {
      last: isLast,
      first: isFirst
    }])),
    style: props.style,
    size: "large",
    type: type,
    icon: icon,
    color: color,
    loading: loading,
    disabled: disabled,
    onClick: props.onClick
  }, props.children ? props.children : text);
};

var ActionBarButtonNameSpace = Object.assign(ActionBarButton, {
  isButton: true
});
export default ActionBarButtonNameSpace;