/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, watch, createVNode, h } from 'vue';
import isNumber from 'lodash/isNumber';
import isFunction from 'lodash/isFunction';
import isArray from 'lodash/isArray';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useContent } from '../hooks/tnode.js';
import props from './props.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-c9c789a8.js';
import 'dayjs';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var ThemeMap = {
  "text": [1],
  "avatar": [{
    type: "circle",
    size: "56px"
  }],
  "paragraph": [1, 1, {
    width: "70%"
  }],
  "avatar-text": [[{
    type: "circle"
  }, {
    type: "text",
    height: "32px"
  }]],
  "tab": [{
    height: "30px"
  }, {
    height: "200px"
  }],
  "article": [{
    type: "rect",
    height: "30px",
    width: "100%"
  }, {
    type: "rect",
    height: "200px",
    width: "100%"
  }, [{
    type: "text",
    height: "30px"
  }, {
    type: "text",
    height: "30px"
  }, {
    type: "text",
    height: "30px"
  }], [{
    type: "text",
    height: "30px"
  }, {
    type: "text",
    height: "30px"
  }], [{
    type: "text",
    height: "30px"
  }, {
    type: "text",
    height: "30px"
  }], [{
    type: "text",
    height: "30px"
  }, {
    type: "text",
    height: "30px"
  }]]
};
var getColItemStyle = function getColItemStyle(obj) {
  var styleName = ["width", "height", "marginRight", "marginLeft", "margin", "size", "background", "backgroundColor"];
  var style = /* @__PURE__ */Object.create(null);
  styleName.forEach(function (name) {
    if (name in obj) {
      var px = isNumber(obj[name]) ? "".concat(obj[name], "px") : obj[name];
      if (name === "size") {
        var _ref = [px, px];
        style.width = _ref[0];
        style.height = _ref[1];
      } else style[name] = px;
    }
  });
  return style;
};
var _Skeleton = defineComponent({
  name: "TSkeleton",
  props: _objectSpread({}, props),
  setup: function setup(props2, _ref2) {
    var slots = _ref2.slots;
    var isShow = ref(false);
    var COMPONENT_NAME = usePrefixClass("skeleton");
    var renderContent = useContent();
    var getColItemClass = function getColItemClass(obj) {
      return ["".concat(COMPONENT_NAME.value, "__col"), "".concat(COMPONENT_NAME.value, "--type-").concat(obj.type || "text"), _defineProperty({}, "".concat(COMPONENT_NAME.value, "--animation-").concat(props2.animation), props2.animation)];
    };
    var renderCols = function renderCols(_cols) {
      var cols = [];
      if (isArray(_cols)) cols = _cols;else if (isNumber(_cols)) cols = new Array(_cols).fill({
        type: "text"
      });else cols = [_cols];
      return cols.map(function (obj) {
        return createVNode("div", {
          "class": getColItemClass(obj),
          "style": getColItemStyle(obj)
        }, [isFunction(obj.content) ? obj.content(h) : obj.content]);
      });
    };
    var renderRowCol = function renderRowCol(_rowCol) {
      var rowCol = _rowCol || props2.rowCol;
      var getBlockClass = function getBlockClass() {
        return ["".concat(COMPONENT_NAME.value, "__row")];
      };
      return rowCol.map(function (item) {
        return createVNode("div", {
          "class": getBlockClass()
        }, [renderCols(item)]);
      });
    };
    watch(function () {
      return props2.loading;
    }, function (val) {
      if (!val || props2.delay === 0) {
        isShow.value = val;
        return;
      }
      setTimeout(function () {
        isShow.value = val;
      }, props2.delay);
    }, {
      immediate: true
    });
    return function () {
      var content = renderContent("default", "content");
      if (slots["default"] && !isShow.value) return createVNode("div", null, [content]);
      if (!isShow.value) return;
      var children = [];
      if (props2.theme) children.push(renderRowCol(ThemeMap[props2.theme]));
      if (props2.rowCol) children.push(renderRowCol(props2.rowCol));
      if (!props2.theme && !props2.rowCol) {
        children.push(renderRowCol([1, 1, 1, {
          width: "70%"
        }]));
      }
      return createVNode("div", {
        "class": COMPONENT_NAME.value
      }, [children]);
    };
  }
});

export { _Skeleton as default };
//# sourceMappingURL=skeleton.js.map
