var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { useCallback, useContext } from 'react';
import classnames from 'classnames';
import { pick } from 'ramda';
import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
import ClearIcon from '@mui/icons-material/Clear';
import i18n from 'ui-i18n';
import { SmallIconButtonWithTooltip } from '../../../../../SmallIconButton';
import { AttributeValuesSortContext } from '../../../contexts/AttributeValuesSortContext';
import { ReadOnlyAttributeValuesBlock } from '../../../../../ReadOnlyAttributeValuesBlock';
import { AttributeTitle } from '../../../../../AttributeTitle';
import { EntityContext } from '../../../../../contexts/EntityContext';
import { useMdmEntity } from '../../../../../contexts/MdmModuleContext';
import { withTableContext } from '../../../../../HOCs/withTableContext';
import { FallbackIndicator } from '../FallbackIndicator';
import { useCommonStyles } from '../../styles';
import { ValueHeightReporter } from '../../../../../SyncedValueHeight';
import styles from './OvValuesRenderer.module.css';
var OvValuesRenderer = function (_a) {
    var _b = _a.value, values = _b.values, attributeType = _b.attributeType, draggableProps = _a.draggableProps, onHideAttributeType = _a.onHideAttributeType, someRowIsDragging = _a.someRowIsDragging;
    var commonStyles = useCommonStyles();
    var entity = useMdmEntity();
    var handleHideClick = useCallback(function () {
        onHideAttributeType === null || onHideAttributeType === void 0 ? void 0 : onHideAttributeType(attributeType);
    }, [onHideAttributeType, attributeType]);
    var sortAttributeValuesForDisplay = useContext(AttributeValuesSortContext);
    return (React.createElement("div", { className: classnames(styles.root, commonStyles.basicCell) },
        React.createElement("div", __assign({}, draggableProps, { className: styles.dragIndicator }),
            React.createElement(DragIndicatorIcon, { className: styles.dragIndicatorIcon })),
        React.createElement(AttributeTitle, { className: styles.attributeTitle, label: attributeType.label }),
        !someRowIsDragging && (React.createElement(EntityContext.Provider, { value: entity },
            React.createElement(ReadOnlyAttributeValuesBlock, { values: sortAttributeValuesForDisplay(values), attributeType: attributeType, valueContainerClassName: styles.ovValue, AttributeValueWrapper: ValueHeightReporter, FallbackSlot: FallbackIndicator }))),
        onHideAttributeType && (React.createElement(SmallIconButtonWithTooltip, { type: "button", className: styles.hideButton, "aria-label": i18n.text('Hide attribute'), tooltipTitle: i18n.text('Hide attribute'), icon: ClearIcon, iconClassName: styles.hideIcon, onClick: handleHideClick }))));
};
export default withTableContext(pick(['onHideAttributeType']))(OvValuesRenderer);
