import { _ as _typeof } from './typeof-6c6d8d7a.js';
import { _ as _unsupportedIterableToArray } from './unsupportedIterableToArray-577176bf.js';
import './es.array.join-3984659f.js';
import './es.array.map-5d0928f8.js';
import './regexp-exec-abstract-944a9b6c.js';
import './es.string.split-44ac9129.js';
import './es.array.slice-675b5831.js';
import './es.object.to-string-591fd1f0.js';
import './es.regexp.to-string-3c444345.js';
import './es.string.replace-1135723d.js';
import './es.array.includes-4e9a9edc.js';
import './es.string.includes-cb8157da.js';
import './es.array.sort-74fd0dd4.js';
import './web.dom-collections.for-each-ee588afd.js';
import './es.object.keys-5378897a.js';

function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}

function _iterableToArrayLimit(arr, i) {
  var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);

  if (_i == null) return;
  var _arr = [];
  var _n = true;
  var _d = false;

  var _s, _e;

  try {
    for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
      _arr.push(_s.value);

      if (i && _arr.length === i) break;
    }
  } catch (err) {
    _d = true;
    _e = err;
  } finally {
    try {
      if (!_n && _i["return"] != null) _i["return"]();
    } finally {
      if (_d) throw _e;
    }
  }

  return _arr;
}

function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

function _slicedToArray(arr, i) {
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}

var createId = function createId() {
  return Math.random().toString(36).substr(2, 9);
};
/**
 *
 * @param {string} string - the nested object property path in dot notation
 * @param {Object} object - the object from which the property value should be extracted
 * @returns {*} - the value contained in the nested object
 */

var extractNestedPropertyValue = function extractNestedPropertyValue(string, object) {
  return string.split('.').reduce(function (a, b) {
    return a[b];
  }, object);
};
/**
 * function taking a string and returning returning any name format in an array
 * with primary compare value (=last name) first and
 * secondary compare value (=first name) second
 *
 * @param compareString {string}
 * @returns {[string, string]}
 */

var getNameSortValue = function getNameSortValue(compareString) {
  var compareStringSansNumbers = compareString.replace(/,? [0-9-]+/g, '');

  if (compareStringSansNumbers.includes(',')) {
    var compareArray = compareStringSansNumbers.split(', ');
    return [compareArray[0], compareArray.splice(1).join()];
  }

  var compArray = compareStringSansNumbers.split(' ');
  return [compArray.pop(), compareStringSansNumbers];
};
/**
 * function for sorting also allowing special sorting of objects for specified
 * attribute
 *
 * @param list {Array}: the list to sort
 * @param objectProp {String}: the property to sort an object by
 * @param sortByName {Boolean}: does it require special name sorting
 * @param valueFunction {Function}: possibility to apply a special function to
 * the value before any further handling (e.g. used for getting language specific
 * label
 * @returns {[*]}
 */

var sort = function sort(list) {
  var objectProp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  var sortByName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var valueFunction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  return list.sort(function (a, b) {
    // assign respective list values to variables
    var compareValueA = a;
    var compareValueB = b; // if a property name was passed use its value for comparison

    if (objectProp) {
      compareValueA = compareValueA[objectProp];
      compareValueB = compareValueB[objectProp];
    } // if a special function was provided apply it to the value


    if (valueFunction) {
      compareValueA = valueFunction(compareValueA);
      compareValueB = valueFunction(compareValueB);
    } // if sortByName was specified, get the respective compare values


    if (sortByName) {
      var secondaryCompareValueA = '';
      var secondaryCompareValueB = '';

      var _getNameSortValue = getNameSortValue(compareValueA);

      var _getNameSortValue2 = _slicedToArray(_getNameSortValue, 2);

      compareValueA = _getNameSortValue2[0];
      secondaryCompareValueA = _getNameSortValue2[1];

      var _getNameSortValue3 = getNameSortValue(compareValueB);

      var _getNameSortValue4 = _slicedToArray(_getNameSortValue3, 2);

      compareValueB = _getNameSortValue4[0];
      secondaryCompareValueB = _getNameSortValue4[1];

      // if primary compare values are equal - use secondary compare value
      if (compareValueA.toLowerCase() === compareValueB.toLowerCase()) {
        compareValueA = secondaryCompareValueA;
        compareValueB = secondaryCompareValueB;
      }
    } // now do the actual value comparison


    if (compareValueA.toLowerCase() > compareValueB.toLowerCase()) {
      return 1;
    }

    return -1;
  });
};
var hasData = function hasData(fieldValues) {
  var hasContent = false;

  if (fieldValues && _typeof(fieldValues) === 'object') {
    if (fieldValues.length >= 0) {
      fieldValues.forEach(function (values) {
        hasContent = hasData(values) || hasContent;
      });
    } else {
      var objectKeys = Object.keys(fieldValues);
      objectKeys.forEach(function (key) {
        hasContent = hasData(fieldValues[key]) || hasContent;
      });
    }
  } else {
    hasContent = fieldValues === 0 || !!fieldValues || hasContent;
  }

  return hasContent;
};

export { _slicedToArray as _, _arrayWithHoles as a, _nonIterableRest as b, createId as c, extractNestedPropertyValue as e, hasData as h, sort as s };
