import _noop from "lodash/fp/noop";
import _map from "lodash/fp/map";
import _get from "lodash/fp/get";
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import Part from '../part';
import style from './style.css';
const themeStyle = {
  setup: style.setupWrapper,
  default: style.wrapper
};
const Tab = ({
  children,
  index,
  title,
  isOpen,
  iconType,
  onClick,
  theme
}) => {
  const handleOnClick = useMemo(() => evt => onClick(index, evt), [index, onClick]);
  return children ? /*#__PURE__*/React.createElement("div", {
    "data-name": "accordion",
    className: themeStyle[theme]
  }, /*#__PURE__*/React.createElement(Part, {
    iconType: iconType,
    title: title,
    content: children,
    isOpen: isOpen,
    theme: theme,
    onClick: handleOnClick
  })) : /*#__PURE__*/React.createElement("div", {
    "data-name": "accordion",
    className: style.wrapperHidden
  });
};
Tab.propTypes = process.env.NODE_ENV !== "production" ? {
  children: Part.propTypes.content,
  index: PropTypes.number,
  title: Part.propTypes.title,
  iconType: Part.propTypes.iconType,
  isOpen: Part.propTypes.isOpen,
  theme: Part.propTypes.theme,
  onClick: Part.propTypes.onClick
} : {};
const Accordion = props => {
  const {
    tabProps,
    children,
    theme = 'default',
    onClick = _noop
  } = props;
  const accordion = _map.convert({
    cap: false
  })((child, index) => {
    const tabProps_ = _get(index, tabProps);
    return /*#__PURE__*/React.createElement(Tab, _extends({}, tabProps_, {
      key: index,
      index: index,
      theme: theme,
      onClick: onClick
    }), child);
  }, children);
  return /*#__PURE__*/React.createElement("div", null, accordion);
};
Accordion.defaultProps = {
  children: []
};
Accordion.propTypes = process.env.NODE_ENV !== "production" ? {
  children: PropTypes.arrayOf(Tab.propTypes.children),
  tabProps: PropTypes.arrayOf(PropTypes.shape({
    title: Tab.propTypes.title,
    iconType: Tab.propTypes.iconType,
    isOpen: Tab.propTypes.isOpen
  })),
  onClick: Tab.propTypes.onClick,
  theme: Tab.propTypes.theme
} : {};
export default Accordion;
//# sourceMappingURL=index.js.map