/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import isNumber from 'lodash/isNumber';
import { prefix } from '../config.js';
import { renderContent } from '../utils/render-tnode.js';
import props from './props.js';
import '@babel/runtime/helpers/typeof';
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 name = "".concat(prefix, "-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 = Vue.extend({
  name: "TSkeleton",
  props: _objectSpread({}, props),
  data: function data() {
    return {};
  },
  methods: {
    renderCols: function renderCols(_cols) {
      var _this = this;

      var h = this.$createElement;

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

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

            if (name2 === "size") {
              var _ref2 = [px, px];
              style.width = _ref2[0];
              style.height = _ref2[1];
            } else {
              style[name2] = 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(_this.$createElement) : obj.content]);
      });
    },
    renderRowCol: function renderRowCol(_rowCol) {
      var _this2 = this;

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

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

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

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

    if (!this.loading) {
      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": name
    }, [children]);
  }
});

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