function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { useState } from 'react';
import InputComponents from '../../../InputComponents';

const Accordion1 = ({
  sections,
  configuration,
  handleSetAttribute,
  languageData
}) => {
  const [selectedSection, setSelectedSection] = useState(null);

  const handleClickSelect = idx => {
    setSelectedSection(selectedSection === idx ? null : idx);
  };

  const convertArrayToObject = (array, key) => {
    const initialValue = {};
    return array.reduce((obj, item) => {
      return { ...obj,
        [item[key]]: item
      };
    }, initialValue);
  };

  if (!sections || sections.length === 0) return null;
  console.log('languageData =>', languageData);
  console.log('configuration =>', configuration);
  console.log('sections =>', sections);
  return /*#__PURE__*/React.createElement(React.Fragment, null, sections.map(({
    label,
    selected,
    heading,
    description,
    component: Component,
    inputs
  }, i) => /*#__PURE__*/React.createElement("div", {
    className: "template-wrapper regular-wapper accordion1-container"
  }, /*#__PURE__*/React.createElement("div", {
    className: "accordion1-component-box"
  }, /*#__PURE__*/React.createElement("div", {
    className: "accordion1-component-container"
  }, /*#__PURE__*/React.createElement("div", {
    className: "accordion1-heading"
  }, heading), /*#__PURE__*/React.createElement("div", {
    className: "accordion1-description"
  }, description), /*#__PURE__*/React.createElement("div", {
    className: "accordion1-section-container"
  }, Component ? /*#__PURE__*/React.createElement(Component, null) : inputs && inputs.length > 0 ? inputs.map((input, index) => /*#__PURE__*/React.createElement(InputComponents, _extends({
    index: index,
    languageData: languageData
  }, input, {
    value: languageData && Object.entries(languageData).length !== 0 && languageData[configuration && configuration[input.attribute]] ? languageData[configuration[input.attribute]] : configuration[input.attribute],
    onChange: val => {
      const attrObject = convertArrayToObject(input.data.options, 'label');
      handleSetAttribute(Array.isArray(input.attribute) ? input.attribute.reduce((output, attribute) => Object.assign(output, {
        [attribute]: val,
        'assetId': attrObject[val].assetId,
        'parent': input.attribute,
        'value': val
      }), {}) : {
        [input.attribute]: val,
        'assetId': attrObject[val].assetId,
        'parent': input.attribute,
        'value': val
      });
    }
  }))) : null))))));
};

export default Accordion1;