"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SourceCrosswalksRow = void 0;
var react_1 = __importStar(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var CrosswalksDisplayContext_1 = require("../../../contexts/CrosswalksDisplayContext");
var DummyCrosswalkRow_1 = require("../DummyCrosswalkRow");
var CrosswalkRow_1 = require("../CrosswalkRow");
var ShowDependentLink_1 = require("../ShowDependentLink");
var types_1 = require("../types");
var SourceCrosswalksRow = function (_a) {
    var source = _a.source, crosswalksByTypes = _a.crosswalksByTypes, _b = _a.showCrosswalkColors, showCrosswalkColors = _b === void 0 ? true : _b, _c = _a.crosswalksFocusEnabled, crosswalksFocusEnabled = _c === void 0 ? true : _c, expanded = _a.expanded, disableEditCrosswalk = _a.disableEditCrosswalk, disableDeleteCrosswalk = _a.disableDeleteCrosswalk, onEdit = _a.onEdit, onDelete = _a.onDelete, onToggleExpanded = _a.onToggleExpanded;
    var highlightedCrosswalks = (0, CrosswalksDisplayContext_1.useHighlightedCrosswalks)();
    (0, react_1.useEffect)(function () {
        if (!expanded &&
            crosswalksFocusEnabled &&
            crosswalksByTypes[types_1.CrosswalkType.Dependent].some(function (dependentCrosswalk) {
                return highlightedCrosswalks.some((0, mdm_sdk_1.eqCrosswalks)(dependentCrosswalk));
            })) {
            onToggleExpanded();
        }
    }, [highlightedCrosswalks]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        crosswalksByTypes[types_1.CrosswalkType.Simple].length === 0 &&
            crosswalksByTypes[types_1.CrosswalkType.Empty].length === 0 && (react_1.default.createElement(DummyCrosswalkRow_1.DummyCrosswalkRow, { crosswalkType: source, focusable: crosswalksFocusEnabled })),
        crosswalksByTypes[types_1.CrosswalkType.Simple].map(function (crosswalk) { return (react_1.default.createElement(CrosswalkRow_1.CrosswalkRow, { key: crosswalk.uri, crosswalk: crosswalk, focusable: crosswalksFocusEnabled, disableEdit: disableEditCrosswalk, disableDelete: disableDeleteCrosswalk, onDelete: onDelete, onEdit: onEdit, isColored: showCrosswalkColors })); }),
        crosswalksByTypes[types_1.CrosswalkType.Empty].map(function (crosswalk) { return (react_1.default.createElement(CrosswalkRow_1.CrosswalkRow, { key: crosswalk.uri, crosswalk: crosswalk, focusable: crosswalksFocusEnabled, isEmpty: true, disableEdit: disableEditCrosswalk, disableDelete: disableDeleteCrosswalk, onDelete: onDelete, onEdit: onEdit, isColored: showCrosswalkColors })); }),
        expanded &&
            crosswalksByTypes[types_1.CrosswalkType.Dependent].map(function (crosswalk) { return (react_1.default.createElement(CrosswalkRow_1.CrosswalkRow, { key: crosswalk.uri, crosswalk: crosswalk, isDependent: true, disableEdit: disableEditCrosswalk, disableDelete: disableDeleteCrosswalk, onDelete: onDelete, onEdit: onEdit, focusable: crosswalksFocusEnabled, isColored: showCrosswalkColors })); }),
        crosswalksByTypes[types_1.CrosswalkType.Dependent].length > 0 && (react_1.default.createElement(ShowDependentLink_1.ShowDependentLink, { showMore: !expanded, onClick: function () { return onToggleExpanded(); } }))));
};
exports.SourceCrosswalksRow = SourceCrosswalksRow;
