var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import React, { useContext } from "react";
import classnames from "classnames";
import { addUnit, getSizeStyle } from "../utils";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const DEFAULT_ROW_WIDTH = "100%";
const DEFAULT_LAST_ROW_WIDTH = "60%";
const Skeleton = (_a) => {
  var _b = _a, {
    children,
    className,
    style
  } = _b, props = __objRest(_b, [
    "children",
    "className",
    "style"
  ]);
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("skeleton", prefixCls);
  const getRowWidth = (index) => {
    const {
      rowWidth
    } = props;
    if (rowWidth === DEFAULT_ROW_WIDTH && index === +props.row - 1) {
      return DEFAULT_LAST_ROW_WIDTH;
    }
    if (Array.isArray(rowWidth)) {
      return rowWidth[index];
    }
    return rowWidth;
  };
  const getRowHeight = (index) => {
    const {
      rowHeight
    } = props;
    if (Array.isArray(rowHeight)) {
      return rowHeight[index];
    }
    return rowHeight;
  };
  const renderAvatar = () => {
    if (props.avatar) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("avatar", props.avatarShape)),
        style: getSizeStyle(props.avatarSize)
      });
    }
    return null;
  };
  const renderTitle = () => {
    if (props.title) {
      const width = addUnit(props.titleWidth);
      const height = addUnit(getRowHeight(0));
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("title")),
        style: {
          width,
          height
        }
      });
    }
    return null;
  };
  const renderRows = () => Array(props.row).fill("").map((_, i) => {
    const width = addUnit(getRowWidth(i));
    const height = addUnit(getRowHeight(i));
    return /* @__PURE__ */ React.createElement("div", {
      key: i,
      className: classnames(bem("row")),
      style: {
        width,
        height
      }
    });
  });
  if (!props.loading)
    return children;
  return /* @__PURE__ */ React.createElement("div", {
    className: classnames(className, bem({
      animate: props.animate,
      round: props.round
    })),
    style
  }, renderAvatar(), /* @__PURE__ */ React.createElement("div", {
    className: classnames(bem("content"))
  }, renderTitle(), renderRows()));
};
Skeleton.defaultProps = {
  loading: true,
  animate: true,
  round: true,
  row: 3,
  avatarShape: "round",
  rowWidth: DEFAULT_ROW_WIDTH
};
var stdin_default = Skeleton;
export {
  stdin_default as default
};
