function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React from 'react';
import Accordion from './Accordion';
import AccordionItem from './AccordionItem';
import { useArgs } from '@storybook/client-api';
export default {
  title: 'Components/Accordion',
  component: Accordion,
  argTypes: {},
  args: {
    bordered: true,
    openItems: [0]
  },
  subcomponents: {
    AccordionItem: AccordionItem
  }
};

var Template = function Template(args) {
  return /*#__PURE__*/React.createElement(Accordion, args);
};

export var Default = Template.bind({});
Default.argTypes = {
  openItems: {
    table: {
      disable: true
    }
  }
};
Default.args = {
  children: [/*#__PURE__*/React.createElement(AccordionItem, {
    key: "1",
    heading: "First Amendment",
    contentClassName: "first-amendment",
    defaultOpen: true
  }, /*#__PURE__*/React.createElement("p", null, "We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.")), /*#__PURE__*/React.createElement(AccordionItem, {
    key: "2",
    heading: "Second Amendment",
    defaultOpen: true
  }, /*#__PURE__*/React.createElement("p", null, "A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."))]
};
export var Controlled = function Controlled(args) {
  var _useArgs = useArgs(),
      _useArgs2 = _slicedToArray(_useArgs, 2),
      openItems = _useArgs2[0].openItems,
      setOpenItems = _useArgs2[1];

  var handleChange = function handleChange(index) {
    if (openItems.includes(index)) {
      setOpenItems({
        openItems: openItems.filter(function (item) {
          return item !== index;
        })
      });
    } else {
      setOpenItems({
        openItems: [].concat(_toConsumableArray(openItems), [index]).sort()
      });
    }
  };

  return /*#__PURE__*/React.createElement(Accordion, args, /*#__PURE__*/React.createElement(AccordionItem, {
    heading: "Controlled accordion",
    defaultOpen: true,
    isControlledOpen: openItems.includes(0),
    onChange: function onChange() {
      return handleChange(0);
    }
  }, /*#__PURE__*/React.createElement("p", null, "In a controlled accordion, the accordion panel's open state is controlled by the application, by passing ", /*#__PURE__*/React.createElement("code", null, "isControlledOpen"), " and ", /*#__PURE__*/React.createElement("code", null, "onChange"), "props. The ", /*#__PURE__*/React.createElement("code", null, "isControlledOpen"), " boolean flag sets the panel to an open or close state.")), /*#__PURE__*/React.createElement(AccordionItem, {
    heading: "Controlled accordion second header",
    defaultOpen: false,
    isControlledOpen: openItems.includes(1),
    onChange: function onChange() {
      return handleChange(1);
    }
  }, /*#__PURE__*/React.createElement("p", null, "In the args below you will notice the openItems array being updated with the changes set using ", /*#__PURE__*/React.createElement("code", null, "isControlledOpen"), " and ", /*#__PURE__*/React.createElement("code", null, "onChange"))));
};