import _extends from "@babel/runtime/helpers/extends";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "color", "size", "title"];
import React, { useState } from 'react';
import { TextBody, Heading3 } from '../typography';
import Icon from '../icon';
import Box, { pickBoxProps } from '../box';
import { IconChevronDownSmallOutline, IconChevronRightSmallOutline } from '@teamleader/ui-icons';
import theme from './theme.css';

var AdvancedCollapsible = function AdvancedCollapsible(_ref) {
  var children = _ref.children,
      _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'teal' : _ref$color,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'medium' : _ref$size,
      title = _ref.title,
      others = _objectWithoutProperties(_ref, _excluded);

  var _useState = useState(true),
      _useState2 = _slicedToArray(_useState, 2),
      collapsed = _useState2[0],
      setCollapsed = _useState2[1];

  var boxProps = pickBoxProps(others);
  var TitleElement = size === 'large' ? Heading3 : TextBody;

  var handleTitleClick = function handleTitleClick() {
    setCollapsed(!collapsed);
  };

  return /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Box, _extends({
    className: theme['title'],
    display: "flex",
    alignItems: "center",
    onClick: handleTitleClick
  }, boxProps), /*#__PURE__*/React.createElement(Icon, {
    color: color,
    tint: "darkest"
  }, collapsed ? /*#__PURE__*/React.createElement(IconChevronRightSmallOutline, null) : /*#__PURE__*/React.createElement(IconChevronDownSmallOutline, null)), /*#__PURE__*/React.createElement(TitleElement, {
    color: color,
    marginLeft: 2,
    tint: "darkest"
  }, size === 'medium' ? /*#__PURE__*/React.createElement("strong", null, title) : title)), !collapsed && /*#__PURE__*/React.createElement(Box, {
    className: theme['children'],
    marginTop: 2
  }, children));
};

export default AdvancedCollapsible;