"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseData = exports.equalChanges = exports.setValue = exports.getValue = void 0;
const react_1 = __importDefault(require("react"));
const getValue = (field, values) => {
    const path = field.split('.');
    let v = values;
    for (const f of path) {
        if (v === undefined || v === null) {
            return undefined; // or emptty string...
        }
        v = v[f];
    }
    return v;
};
exports.getValue = getValue;
const setValue = (field, values, value) => {
    const path = field.split('.');
    let v = values;
    for (let i = 0; i < path.length - 1; i++) {
        const f = path[i];
        v = v[f] ?? (v[f] = {});
    }
    v[path[path.length - 1]] = value;
    if (Object.keys(values).length > 0 && !Array.isArray(values)) {
        //lets do smth here if
    }
};
exports.setValue = setValue;
const equalChanges = (changes, values) => {
    for (const key in changes) {
        const c = changes[key];
        const v = values[key];
        const cType = typeof c;
        const vType = typeof v;
        if (Array.isArray(c) && c.length === 0) {
            return false;
        }
        if (cType !== vType) {
            return false;
        }
        if (cType === 'object' && c !== null) {
            if (v === null) {
                return false;
            }
            if (!(0, exports.equalChanges)(c, v)) {
                return false;
            }
        }
        else if (c !== v) {
            return false;
        }
    }
    return true;
};
exports.equalChanges = equalChanges;
const parseData = (properties) => {
    let parsedData;
    if (!Array.isArray(properties)) {
        parsedData = [];
        for (const field in properties) {
            const item = properties[field];
            if (item === null) {
                continue;
            }
            if (typeof item === 'object' && !react_1.default.isValidElement(item)) {
                parsedData.push({ ...item, field });
            }
            else {
                parsedData.push({
                    field,
                    label: item,
                });
            }
        }
    }
    else {
        parsedData = properties;
    }
    return parsedData;
};
exports.parseData = parseData;
//# sourceMappingURL=utils.js.map