"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;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSyncedExpandedAttributes = exports.SyncedExpandedAttributesProvider = exports.SyncedExpandedAttributesContext = void 0;
var react_1 = __importStar(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
exports.SyncedExpandedAttributesContext = (0, react_1.createContext)(null);
var SyncedExpandedAttributesProvider = function (_a) {
    var children = _a.children;
    var _b = (0, react_1.useState)([]), expandedAttributes = _b[0], setExpandedAttributes = _b[1];
    var isExpanded = (0, react_1.useCallback)(function (attributeUri) { return expandedAttributes.includes(attributeUri); }, [expandedAttributes]);
    var toggle = (0, react_1.useCallback)(function (attributeUri) {
        setExpandedAttributes(function (prev) {
            if (prev.includes(attributeUri)) {
                return prev.filter(function (uri) { return !(0, mdm_sdk_1.areOneHierarchyUris)(uri, attributeUri); });
            }
            return __spreadArray(__spreadArray([], prev, true), [attributeUri], false);
        });
    }, []);
    var value = (0, react_1.useMemo)(function () { return ({ isExpanded: isExpanded, toggle: toggle }); }, [isExpanded, toggle]);
    return (react_1.default.createElement(exports.SyncedExpandedAttributesContext.Provider, { value: value }, children));
};
exports.SyncedExpandedAttributesProvider = SyncedExpandedAttributesProvider;
var useSyncedExpandedAttributes = function () { return (0, react_1.useContext)(exports.SyncedExpandedAttributesContext); };
exports.useSyncedExpandedAttributes = useSyncedExpandedAttributes;
