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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useState } from 'react';
import { propOr } from 'ramda';
import { DataTypes } from '@reltio/mdm-sdk';
import { ShowMore } from '../ShowMore';
import { ShowLess } from '../ShowLess';
import { InlineSimpleAttributesBlock } from './components/InlineSimpleAttributesBlock';
import { InlineNestedAttributesBlock } from './components/InlineNestedAttributesBlock';
import { InlineReferenceAttributesBlock } from './components/InlineReferenceAttributesBlock';
import { InlineImageAttributesBlock } from './components/InlineImageAttributesBlock';
import { useStyles } from './styles';
export var InlineAttributesPager = function (_a) {
    var attributeType = _a.attributeType, _b = _a.attributeValues, attributeValues = _b === void 0 ? [] : _b, _c = _a.paging, paging = _c === void 0 ? {} : _c, _d = _a.max, max = _d === void 0 ? Infinity : _d, props = __rest(_a, ["attributeType", "attributeValues", "paging", "max"]);
    var styles = useStyles();
    var _e = useState(max), visibleValuesCount = _e[0], setVisibleValuesCount = _e[1];
    var totalValues = propOr(attributeValues.length, 'totalValues', paging);
    var hasPaging = max < totalValues;
    var showMore = hasPaging && visibleValuesCount < totalValues;
    var showLess = hasPaging && visibleValuesCount >= totalValues;
    var onShowMore = function () {
        setVisibleValuesCount(visibleValuesCount + max);
    };
    var onShowLess = function () {
        setVisibleValuesCount(max);
    };
    var shownValues = attributeValues.slice(0, visibleValuesCount);
    var hiddenValuesCount = totalValues - visibleValuesCount;
    var renderValues = function (values) {
        switch (attributeType.type) {
            case DataTypes.TYPE_NESTED:
                return (React.createElement(InlineNestedAttributesBlock, __assign({ className: styles.complexAttributesWrapper, attributeValues: values, attributeType: attributeType }, props)));
            case DataTypes.TYPE_REFERENCE: {
                var crosswalksMap = props.crosswalksMap, other = __rest(props, ["crosswalksMap"]);
                return (React.createElement(InlineReferenceAttributesBlock, __assign({ className: styles.complexAttributesWrapper, attributeValues: values, attributeType: attributeType, crosswalksMap: crosswalksMap }, other)));
            }
            case DataTypes.TYPE_IMAGE: {
                return (React.createElement(InlineImageAttributesBlock, __assign({ className: styles.complexAttributesWrapper, attributeValues: values, attributeType: attributeType }, props)));
            }
            default:
                return (React.createElement(InlineSimpleAttributesBlock, __assign({ attributeValues: values, attributeType: attributeType }, props)));
        }
    };
    return (React.createElement("div", { className: styles.wrapper },
        renderValues(shownValues),
        showMore && (React.createElement(ShowMore, { moreNumber: Math.min(max, hiddenValuesCount), valueNumber: hiddenValuesCount, onClick: onShowMore })),
        showLess && React.createElement(ShowLess, { onClick: onShowLess })));
};
