/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isNumber from 'lodash/isNumber';
import { renderContent } from '../utils/render-tnode.js';
import props from './props.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';

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 classPrefixMixins = getClassPrefixMixins("skeleton");
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 _Skeleton = mixins(classPrefixMixins).extend({
  name: "TSkeleton",
  props: _objectSpread({}, props),
  data: function data() {
    return {
      delayShowLoading: this.delay <= 0 ? this.loading : false,
      delayTimer: 0
    };
  },
  watch: {
    loading: {
      handler: function handler(val) {
        if (this.delay <= 0) {
          this.delayShowLoading = this.loading;
          return;
        }

        this.handleDelay(val);
      },
      immediate: true
    }
  },
  methods: {
    handleDelay: function handleDelay(loading) {
      var _this = this;

      if (loading) {
        clearTimeout(this.delayTimer);
        this.delayTimer = window.setTimeout(function () {
          _this.delayShowLoading = _this.loading;
        }, this.delay);
      } else {
        this.delayShowLoading = loading;
      }
    },
    renderCols: function renderCols(_cols) {
      var _this2 = this;

      var h = this.$createElement;

      var getColItemClass = function getColItemClass(obj) {
        return ["".concat(_this2.componentName, "__col"), "".concat(_this2.componentName, "--type-").concat(obj.type || "text"), _defineProperty({}, "".concat(_this2.componentName, "--animation-").concat(_this2.animation), _this2.animation)];
      };

      var getColItemStyle = function getColItemStyle(obj) {
        var styleName = ["width", "height", "marginRight", "marginLeft", "margin", "size", "background", "backgroundColor"];
        var style = {};
        styleName.forEach(function (name) {
          if (name in obj) {
            var px = isNumber(obj[name]) ? "".concat(obj[name], "px") : obj[name];

            if (name === "size") {
              var _ref2 = [px, px];
              style.width = _ref2[0];
              style.height = _ref2[1];
            } else {
              style[name] = px;
            }
          }
        });
        return style;
      };

      var cols = [];

      if (Array.isArray(_cols)) {
        cols = _cols;
      } else if (isNumber(_cols)) {
        cols = new Array(_cols).fill({
          type: "text"
        });
      } else {
        cols = [_cols];
      }

      return cols.map(function (obj) {
        return h("div", {
          "class": getColItemClass(obj),
          "style": getColItemStyle(obj)
        }, [typeof obj.content === "function" ? obj.content(_this2.$createElement) : obj.content]);
      });
    },
    renderRowCol: function renderRowCol(_rowCol) {
      var _this3 = this;

      var h = this.$createElement;
      var rowCol = _rowCol || this.rowCol;

      var getBlockClass = function getBlockClass() {
        return ["".concat(_this3.componentName, "__row")];
      };

      return rowCol.map(function (item) {
        return h("div", {
          "class": getBlockClass()
        }, [_this3.renderCols(item)]);
      });
    }
  },
  render: function render() {
    var h = arguments[0];
    var content = renderContent(this, "default", "content");

    if (this.$scopedSlots["default"] && !this.delayShowLoading) {
      return h("div", [content]);
    }

    if (!this.delayShowLoading) {
      return;
    }

    var children = [];

    if (this.theme) {
      children.push(this.renderRowCol(ThemeMap[this.theme]));
    }

    if (this.rowCol) {
      children.push(this.renderRowCol(this.rowCol));
    }

    if (!this.theme && !this.rowCol) {
      children.push(this.renderRowCol([1, 1, 1, {
        width: "70%"
      }]));
    }

    return h("div", {
      "class": this.componentName
    }, [children]);
  }
});

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