'use strict';

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

var propTypes = {
  /** Component children's to be rendered */
  children: PropTypes__default.default.node.isRequired,
  /** Section title */
  title: PropTypes__default.default.string,
  /** Section is open or not */
  isOpen: PropTypes__default.default.bool,
  /** Callback for accordion item click */
  onClick: PropTypes__default.default.func,
  testId: PropTypes__default.default.string
};
var defaultProps = {
  isOpen: true,
  onClick: function onClick() {},
  title: null,
  testId: 'tile-gallery-section'
};
var TileGallerySection = function TileGallerySection(_ref) {
  var children = _ref.children,
    title = _ref.title,
    isOpen = _ref.isOpen,
    onClick = _ref.onClick,
    testId = _ref.testId;
  var _useState = React.useState(isOpen),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var galleryItems = /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": "".concat(testId, "-items"),
    className: "tile-gallery--section--items"
  }, children);
  return /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": testId,
    className: "tile-gallery--section"
  }, title ? /*#__PURE__*/React__default.default.createElement(react.Accordion, {
    "data-testid": "".concat(testId, "-accordion")
  }, /*#__PURE__*/React__default.default.createElement(react.AccordionItem, {
    title: title,
    onHeadingClick: function onHeadingClick(evt) {
      setOpen(!open);
      onClick(evt);
    },
    open: open,
    "data-testid": "".concat(testId, "-accordion-item")
  }, galleryItems)) : galleryItems);
};
TileGallerySection.propTypes = propTypes;
TileGallerySection.defaultProps = defaultProps;
TileGallerySection.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TileGallerySection",
  "props": {
    "isOpen": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "description": "Section is open or not",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "onClick": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "Callback for accordion item click",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "title": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Section title",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'tile-gallery-section'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "children": {
      "description": "Component children's to be rendered",
      "type": {
        "name": "node"
      },
      "required": true
    }
  }
};
var TileGallerySection$1 = TileGallerySection;

module.exports = TileGallerySection$1;
