"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const lodash_1 = require("lodash");
const react_native_1 = require("react-native");
const Accordion_1 = tslib_1.__importDefault(require("react-native-collapsible/Accordion"));
const react_native_markdown_display_1 = tslib_1.__importDefault(require("react-native-markdown-display"));
const styles_1 = require("./styles");
const AccordionContainer = ({ StyledTitle = react_native_1.Text, StyledBody = react_native_1.Text, StyledHeader = react_native_1.View, StyledContent = react_native_1.View, data, hasIcon = false, iconUpName = 'chevron-up', iconDownName = 'chevron-down', activeIconColor, inactiveIconColor, isMarkdown = false, onChange, }) => {
    const [activeSections, setActiveSections] = (0, react_1.useState)([]);
    const isActive = (section) => {
        const element = (item) => item.title === section.title;
        const index = data.findIndex(element);
        return index.toString() === activeSections.join('');
    };
    const getIconName = (section) => isActive(section) ? iconUpName : iconDownName;
    const renderHeader = (section) => {
        return (<StyledHeader isActive={isActive(section)}>
        <StyledTitle isActive={isActive(section)}>{section.title}</StyledTitle>
        {hasIcon && (<styles_1.Icon name={getIconName(section)} color={isActive(section) ? activeIconColor : inactiveIconColor} id={iconUpName} accessibility={isActive(section) ? 'Fechar' : 'Abrir'}/>)}
      </StyledHeader>);
    };
    const renderContent = (section) => {
        return (<StyledContent>
        {isMarkdown && <react_native_markdown_display_1.default>{section.content}</react_native_markdown_display_1.default>}
        {!isMarkdown && <StyledBody>{section.content}</StyledBody>}
      </StyledContent>);
    };
    const handleChange = (activeSectionsArray) => {
        const index = (0, lodash_1.head)(activeSectionsArray) || 0;
        if (onChange)
            onChange(data[index].title);
        setActiveSections(activeSectionsArray);
    };
    return (<Accordion_1.default sections={data} touchableComponent={react_native_1.TouchableOpacity} activeSections={activeSections} renderHeader={renderHeader} renderContent={renderContent} onChange={handleChange}/>);
};
exports.default = AccordionContainer;
//# sourceMappingURL=index.js.map