import { forwardRef, useContext } from "react";
import cs from "../_util/classNames.js";
import { isObject } from "../_util/is.js";
import text from "./text.js";
import image from "./image.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { pickDataAttributes } from "../_util/pick.js";
import { jsx, jsxs, Fragment } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
function getComponentProps(prop) {
  return isObject(prop) ? prop : {};
}
var defaultProps = {
  text: true,
  loading: true
};
function Skeleton(baseProps, ref) {
  var _a;
  var _b = useContext(ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig, rtl = _b.rtl;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Skeleton);
  var style = props.style, className = props.className, animation = props.animation, loading = props.loading, image$1 = props.image, text$1 = props.text, children = props.children;
  var imageProps = getComponentProps(image$1);
  var textProps = getComponentProps(text$1);
  var prefixCls = getPrefixCls("skeleton");
  var classNames = cs(prefixCls, (_a = {}, _a[prefixCls + "-animate"] = animation, _a[prefixCls + "-rtl"] = rtl, _a), className);
  function renderImage() {
    return image$1 && /* @__PURE__ */ jsx("div", {
      className: prefixCls + "-header",
      children: /* @__PURE__ */ jsx(image, {
        ...__assign({
          prefixCls
        }, imageProps)
      })
    });
  }
  function renderText() {
    return text$1 && /* @__PURE__ */ jsx("div", {
      className: prefixCls + "-content",
      children: /* @__PURE__ */ jsx(text, {
        ...__assign({
          prefixCls
        }, textProps)
      })
    });
  }
  return /* @__PURE__ */ jsx(Fragment, {
    children: loading ? /* @__PURE__ */ jsxs("div", {
      ...__assign({}, pickDataAttributes(props), {
        className: classNames,
        style,
        ref
      }),
      children: [imageProps.position !== "right" && renderImage(), renderText(), imageProps.position === "right" && renderImage()]
    }) : children
  });
}
var SkeletonComponent = forwardRef(Skeleton);
SkeletonComponent.displayName = "Skeleton";
const Skeleton$1 = SkeletonComponent;
export {
  Skeleton$1 as default
};
//# sourceMappingURL=index.js.map
