'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var styles = require('./styles.js');
var utils = require('./utils.js');
var index$1 = require('./components/ListItemPrefix/index.js');
var index$2 = require('./components/ListItemContent/index.js');
var index$3 = require('./components/ListItemSuffix/index.js');
var index = require('../../utils/index.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

const ListItem = (props) => {
    const { variant = 'default', state = 'default', primaryText, prefix, suffix, divider = false, dividerStartsFromText = false, disabled, onClick, } = props;
    const ListItemWrapper = utils.getListItemWrapperByVariant(variant);
    const prefixRef = React.createRef();
    const [prefixWidth, setPrefixWidth] = React.useState(0);
    React.useEffect(() => {
        var _a;
        if ((_a = prefixRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) {
            setPrefixWidth(prefixRef.current.clientWidth);
        }
    }, [prefixRef.current, prefix]);
    return (React__default['default'].createElement(ListItemWrapper, { divider: divider, onClick: state === 'default' && !disabled ? onClick : index.noop, state: state, prefixWidth: prefixWidth, dividerStartsFromText: dividerStartsFromText, disabled: disabled },
        React__default['default'].createElement(styles.ListItemFlexContainer, { variant: variant },
            prefix && (React__default['default'].createElement(index$1.ListItemPrefix, { prefix: prefix, variant: variant, ref: prefixRef })),
            props.variant === 'multi-line' ? (React__default['default'].createElement(index$2.ListItemContent, { primaryText: primaryText, secondaryText: props.secondaryText, variant: variant, prefix: prefix, suffix: suffix })) : (React__default['default'].createElement(index$2.ListItemContent, { primaryText: primaryText, variant: variant, prefix: prefix, suffix: suffix })),
            suffix && React__default['default'].createElement(index$3.ListItemSuffix, { suffix: suffix, variant: variant }))));
};

exports.ListItem = ListItem;
