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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isNumber = require('lodash/isNumber');
var isFunction = require('lodash/isFunction');
var isArray = require('lodash/isArray');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var skeleton_props = require('./props.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

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__default["default"](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__default["default"](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 = vue.defineComponent({
  name: "TSkeleton",
  props: _objectSpread({}, skeleton_props["default"]),
  setup: function setup(props2, _ref2) {
    var slots = _ref2.slots;
    var isShow = vue.ref(false);
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("skeleton");
    var renderContent = hooks_tnode.useContent();
    var getColItemClass = function getColItemClass(obj) {
      return ["".concat(COMPONENT_NAME.value, "__col"), "".concat(COMPONENT_NAME.value, "--type-").concat(obj.type || "text"), _defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "--animation-").concat(props2.animation), props2.animation)];
    };
    var renderCols = function renderCols(_cols) {
      var cols = [];
      if (isArray__default["default"](_cols)) cols = _cols;else if (isNumber__default["default"](_cols)) cols = new Array(_cols).fill({
        type: "text"
      });else cols = [_cols];
      return cols.map(function (obj) {
        return vue.createVNode("div", {
          "class": getColItemClass(obj),
          "style": getColItemStyle(obj)
        }, [isFunction__default["default"](obj.content) ? obj.content(vue.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 vue.createVNode("div", {
          "class": getBlockClass()
        }, [renderCols(item)]);
      });
    };
    vue.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 vue.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 vue.createVNode("div", {
        "class": COMPONENT_NAME.value
      }, [children]);
    };
  }
});

exports["default"] = _Skeleton;
//# sourceMappingURL=skeleton.js.map
