// @flow

import React from 'react';
import type { Node } from 'react';
import classNames from 'classnames';
import { inject, observer } from 'mobx-react';
import { type Store } from '../accordionStore/accordionStore';

const defaultProps = {
    className: 'accordion__body',
    hideBodyClassName: 'accordion__body--hidden',
};

type AccordionItemBodyProps = {
    children: Node,
    className: string,
    hideBodyClassName: string,
    accordionStore: Store,
    uuid: string | number,
};

const AccordionItemBody = (props: AccordionItemBodyProps) => {
    const { uuid, children, className, hideBodyClassName } = props;
    const { items, accordion } = props.accordionStore;
    const foundItem = items.find(item => item.uuid === uuid);
    if (!foundItem) return null;

    const { expanded } = foundItem;
    const id = `accordion__body-${uuid}`;
    const ariaLabelledby = `accordion__title-${uuid}`;
    const role = accordion ? 'tabpanel' : null;

    const bodyClass = classNames(className, {
        [hideBodyClassName]: !expanded,
    });
    const ariaHidden = !expanded;
    return (
        <div
            id={id}
            className={bodyClass}
            aria-hidden={ariaHidden}
            aria-labelledby={ariaLabelledby}
            role={role}
        >
            {children}
        </div>
    );
};

AccordionItemBody.defaultProps = defaultProps;

export default inject('accordionStore', 'uuid')(observer(AccordionItemBody));

@@ -19,41 +19,29 @@
 eact
- from 'react';%0Aimport type %7B Node
+, %7B type ElementProps
  %7D f
@@ -346,52 +346,31 @@
 s = 
-%7B%0A    children: Node,%0A    className: string,
+ElementProps%3C'div'%3E & %7B
 %0A   
@@ -533,24 +533,54 @@
 st %7B
- uuid, children,
+%0A        accordionStore,%0A        uuid,%0A       
  cla
@@ -586,16 +586,24 @@
 assName,
+%0A       
  hideBod
@@ -612,16 +612,37 @@
 lassName
+,%0A        ...rest%0A   
  %7D = pro
@@ -1304,31 +1304,20 @@
     
-%3E%0A            %7Bchildren
+    %7B...rest
 %7D%0A  
@@ -1326,13 +1326,9 @@
     
-%3C/div
+/
 %3E%0A  

Update AccordionItemBody to respect arbitrary user-defined props