'use strict';

/**
 * It takes a record / HTMLElement and a path, and returns the value at that path
 *
 * @param {Record<string, unknown> | HTMLElement} record - The record object or HTMLElement that you want to get the value from.
 * @param {string} path - The path to the value you want to get.
 * @returns {unknown} The value of the path in the record.
 */
function getValueByPath(record, path = '') {
  if (path.includes('.') && path !== '.') {
    return path.split('.').reduce((pre, cur) => pre === null || pre === void 0 ? void 0 : pre[cur], record);
  }
  return record[path];
}
/**
 * The `deepEqual` function compares two objects deeply to determine if they are equal.
 *
 * @param {unknown} obj - `obj` is the first object you want to compare for deep equality.
 * @param {unknown} compareTo - The `compareTo` parameter is the object that you want to compare for
 * deep equality with the `obj` parameter.
 * @returns {boolean} The `deepEqual` function is returning a boolean value indicating whether the two input
 * objects `obj` and `compareTo` are deeply equal. It checks if both inputs are objects, have the same
 * number of keys, and recursively compares the key-value pairs to determine equality. If the objects
 * are not objects, it directly compares them for equality.
 */
function deepEqual(obj, compareTo) {
  return obj && compareTo && typeof obj === 'object' && typeof compareTo === 'object'
    ? Object.keys(obj).length === Object.keys(compareTo).length &&
      Object.keys(obj).reduce(function (isEqual, key) {
        return isEqual && deepEqual(obj[key], compareTo[key]);
      }, true)
    : obj === compareTo;
}
/**
 * Cleans an object by removing properties with null or undefined values.
 *
 * @template T - The type of the input object.
 * @param {T} obj - The object to be cleaned.
 * @param {{ cleanEmptyString?: boolean }} [options] - Optional settings for cleaning the object.
 * @param {boolean} [options.cleanEmptyString=false] - If true, also removes properties with empty string values.
 * @returns {Partial<T>} A new object with properties that have non-null and non-undefined and empty string (optional) values.
 */
function cleanObject(obj, options) {
  return Object.fromEntries(Object.entries(obj).filter(
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  ([_k, v]) => v !== null && v !== undefined && ((options === null || options === void 0 ? void 0 : options.cleanEmptyString) ? v !== '' : true)));
}

exports.cleanObject = cleanObject;
exports.deepEqual = deepEqual;
exports.getValueByPath = getValueByPath;
