import React__default, { Children, isValidElement } from 'react';
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-es.js';
import { _ as _baseKeys, a as _getTag } from './_getTag-es.js';
import { i as isArguments_1, a as isArray_1, b as isArrayLike_1, c as isBufferExports, _ as _isPrototype, d as isTypedArray_1 } from './isTypedArray-es.js';
import { B as BREAKPOINTS } from './DataList.const-es.js';
import { D as DataListTags } from './DataListTags-es.js';
import { D as DataListHeaderTile } from './DataListHeaderTile-es.js';
import { T as Text } from './Text-es.js';
import { H as Heading } from './Heading-es.js';

var baseKeys = _baseKeys,
    getTag = _getTag,
    isArguments = isArguments_1,
    isArray = isArray_1,
    isArrayLike = isArrayLike_1,
    isBuffer = isBufferExports,
    isPrototype = _isPrototype,
    isTypedArray = isTypedArray_1;

/** `Object#toString` result references. */
var mapTag = '[object Map]',
    setTag = '[object Set]';

/** Used for built-in method references. */
var objectProto = Object.prototype;

/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;

/**
 * Checks if `value` is an empty object, collection, map, or set.
 *
 * Objects are considered empty if they have no own enumerable string keyed
 * properties.
 *
 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
 * jQuery-like collections are considered empty if they have a `length` of `0`.
 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
 *
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Lang
 * @param {*} value The value to check.
 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
 * @example
 *
 * _.isEmpty(null);
 * // => true
 *
 * _.isEmpty(true);
 * // => true
 *
 * _.isEmpty(1);
 * // => true
 *
 * _.isEmpty([1, 2, 3]);
 * // => false
 *
 * _.isEmpty({ 'a': 1 });
 * // => false
 */
function isEmpty(value) {
  if (value == null) {
    return true;
  }
  if (isArrayLike(value) &&
      (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
        isBuffer(value) || isTypedArray(value) || isArguments(value))) {
    return !value.length;
  }
  var tag = getTag(value);
  if (tag == mapTag || tag == setTag) {
    return !value.size;
  }
  if (isPrototype(value)) {
    return !baseKeys(value).length;
  }
  for (var key in value) {
    if (hasOwnProperty.call(value, key)) {
      return false;
    }
  }
  return true;
}

var isEmpty_1 = isEmpty;

var isEmpty$1 = /*@__PURE__*/getDefaultExportFromCjs(isEmpty_1);

/**
 * Return the child component that matches the `type` provided
 */
function getCompoundComponent(children, type) {
    const childrenArray = Children.toArray(children);
    const element = childrenArray.find(child => isValidElement(child) && child.type === type);
    // Comply with the return type without casting it
    return isValidElement(element) ? element : undefined;
}
/**
 * Return all instances child component that matches the `type` provided
 */
function getCompoundComponents(children, type) {
    const childrenArray = Children.toArray(children);
    const elements = childrenArray.filter((child) => isValidElement(child) && child.type === type);
    return elements;
}
/**
 * Generate the default element the DataList would use on the data provided.
 */
function generateListItemElement(item) {
    return Object.keys(item).reduce((acc, key) => {
        const currentItem = item[key];
        if (!currentItem) {
            return acc;
        }
        if (key === "tags" && Array.isArray(currentItem)) {
            acc[key] = React__default.createElement(DataListTags, { items: currentItem });
        }
        else if (key === "label" && typeof currentItem === "string") {
            acc[key] = React__default.createElement(Heading, { level: 5 }, currentItem);
        }
        else if (isValidElement(currentItem)) {
            acc[key] = currentItem;
        }
        else if (currentItem instanceof Date) {
            acc[key] = (React__default.createElement(Text, null, currentItem.toLocaleDateString(undefined, {
                month: "short",
                day: "numeric",
                year: "numeric",
            })));
        }
        else {
            acc[key] = React__default.createElement(Text, null, currentItem);
        }
        return acc;
    }, {});
}
/**
 * Generate the header elements with the default styling
 */
function generateHeaderElements(headers) {
    const headerElements = Object.keys(headers).reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: React__default.createElement(DataListHeaderTile, { headers: headers, headerKey: key }) })), {});
    return isEmpty$1(headerElements) ? undefined : headerElements;
}
function sortBreakpoints(sizeProp) {
    return sizeProp.sort((a, b) => BREAKPOINTS.indexOf(a) - BREAKPOINTS.indexOf(b));
}
function getExposedActions(childrenArray, childCount = 2) {
    const firstNChildren = childrenArray.slice(0, childCount);
    return firstNChildren.reduce((result, child, i) => {
        const hasIcon = Boolean(child.props.icon);
        const isAlwaysVisible = child.props.alwaysVisible; // If true, the child action will always be visible and not nested in the dropdown.
        if (isAlwaysVisible === false ||
            (isAlwaysVisible === undefined && !hasIcon)) {
            return result;
        }
        const isLastChildAdded = result.length === i;
        // If it's the first child or if the previous child was added, then add this child.
        if (i === 0 || (i < childCount && isLastChildAdded)) {
            return [...result, child];
        }
        return result;
    }, []);
}

export { getCompoundComponents as a, getExposedActions as b, generateHeaderElements as c, generateListItemElement as d, getCompoundComponent as g, sortBreakpoints as s };
