import * as React from "react";
import { cloneElement } from "react";
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-DWwsNxpa.js";
import { aU as requireIsArrayLike, L as Layer, E as getValueByDataKey, f as filterProps, ae as findAllByType } from "./RechartsWrapper-B6DckFGn.js";
import { c as Label, i as isLabelContentAFunction } from "./CategoricalChart-B4Tr_94h.js";
import { i as isNullish } from "./ResponsiveContainer-by1DMaUt.js";
var last$3 = {};
var last$2 = {};
var hasRequiredLast$2;
function requireLast$2() {
  if (hasRequiredLast$2) return last$2;
  hasRequiredLast$2 = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function last2(arr) {
      return arr[arr.length - 1];
    }
    exports.last = last2;
  })(last$2);
  return last$2;
}
var toArray = {};
var hasRequiredToArray;
function requireToArray() {
  if (hasRequiredToArray) return toArray;
  hasRequiredToArray = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    function toArray2(value) {
      return Array.isArray(value) ? value : Array.from(value);
    }
    exports.toArray = toArray2;
  })(toArray);
  return toArray;
}
var hasRequiredLast$1;
function requireLast$1() {
  if (hasRequiredLast$1) return last$3;
  hasRequiredLast$1 = 1;
  (function(exports) {
    Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
    const last$12 = /* @__PURE__ */ requireLast$2();
    const toArray2 = /* @__PURE__ */ requireToArray();
    const isArrayLike = /* @__PURE__ */ requireIsArrayLike();
    function last2(array) {
      if (!isArrayLike.isArrayLike(array)) {
        return void 0;
      }
      return last$12.last(toArray2.toArray(array));
    }
    exports.last = last2;
  })(last$3);
  return last$3;
}
var last$1;
var hasRequiredLast;
function requireLast() {
  if (hasRequiredLast) return last$1;
  hasRequiredLast = 1;
  last$1 = requireLast$1().last;
  return last$1;
}
var lastExports = /* @__PURE__ */ requireLast();
const last = /* @__PURE__ */ getDefaultExportFromCjs(lastExports);
var _excluded = ["valueAccessor"], _excluded2 = ["data", "dataKey", "clockWise", "id", "textBreakAll"];
function _extends() {
  return _extends = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends.apply(null, arguments);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == typeof i ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != typeof t || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r);
    if ("object" != typeof i) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
function _objectWithoutProperties(e, t) {
  if (null == e) return {};
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return t;
}
var defaultAccessor = (entry) => Array.isArray(entry.value) ? last(entry.value) : entry.value;
function LabelList(_ref) {
  var {
    valueAccessor = defaultAccessor
  } = _ref, restProps = _objectWithoutProperties(_ref, _excluded);
  var {
    data,
    dataKey,
    clockWise,
    id,
    textBreakAll
  } = restProps, others = _objectWithoutProperties(restProps, _excluded2);
  if (!data || !data.length) {
    return null;
  }
  return /* @__PURE__ */ React.createElement(Layer, {
    className: "recharts-label-list"
  }, data.map((entry, index) => {
    var value = isNullish(dataKey) ? valueAccessor(entry, index) : getValueByDataKey(entry && entry.payload, dataKey);
    var idProps = isNullish(id) ? {} : {
      id: "".concat(id, "-").concat(index)
    };
    return /* @__PURE__ */ React.createElement(Label, _extends({}, filterProps(entry, true), others, idProps, {
      parentViewBox: entry.parentViewBox,
      value,
      textBreakAll,
      viewBox: Label.parseViewBox(isNullish(clockWise) ? entry : _objectSpread(_objectSpread({}, entry), {}, {
        clockWise
      })),
      key: "label-".concat(index),
      index
    }));
  }));
}
LabelList.displayName = "LabelList";
function parseLabelList(label, data) {
  if (!label) {
    return null;
  }
  if (label === true) {
    return /* @__PURE__ */ React.createElement(LabelList, {
      key: "labelList-implicit",
      data
    });
  }
  if (/* @__PURE__ */ React.isValidElement(label) || isLabelContentAFunction(label)) {
    return /* @__PURE__ */ React.createElement(LabelList, {
      key: "labelList-implicit",
      data,
      content: label
    });
  }
  if (typeof label === "object") {
    return /* @__PURE__ */ React.createElement(LabelList, _extends({
      data
    }, label, {
      key: "labelList-implicit"
    }));
  }
  return null;
}
function renderCallByParent(parentProps, data) {
  var checkPropsLabel = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
  if (!parentProps || !parentProps.children && checkPropsLabel && !parentProps.label) {
    return null;
  }
  var {
    children
  } = parentProps;
  var explicitChildren = findAllByType(children, LabelList).map((child, index) => /* @__PURE__ */ cloneElement(child, {
    data,
    // eslint-disable-next-line react/no-array-index-key
    key: "labelList-".concat(index)
  }));
  if (!checkPropsLabel) {
    return explicitChildren;
  }
  var implicitLabelList = parseLabelList(parentProps.label, data);
  return [implicitLabelList, ...explicitChildren];
}
LabelList.renderCallByParent = renderCallByParent;
export {
  LabelList as L,
  last as l
};
