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

'use strict';

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

var Vue = require('vue');
var _mergeWith = require('lodash/mergeWith');
var configProvider_context = require('./context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');

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

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var _mergeWith__default = /*#__PURE__*/_interopDefaultLegacy(_mergeWith);

function getConfigReceiverMixins(_componentName) {
  return Vue__default["default"].extend({
    name: "TConfigProvider",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    computed: {
      global: function global() {
        var data = this.globalConfig || configProvider_context.defaultGlobalConfig;
        return data[_componentName];
      },
      classPrefix: function classPrefix() {
        var _this$globalConfig;

        return ((_this$globalConfig = this.globalConfig) === null || _this$globalConfig === void 0 ? void 0 : _this$globalConfig.classPrefix) || (configProvider_context.defaultGlobalConfig === null || configProvider_context.defaultGlobalConfig === void 0 ? void 0 : configProvider_context.defaultGlobalConfig.classPrefix);
      },
      componentName: function componentName() {
        var _this$globalConfig2;

        var classPrefix = ((_this$globalConfig2 = this.globalConfig) === null || _this$globalConfig2 === void 0 ? void 0 : _this$globalConfig2.classPrefix) || (configProvider_context.defaultGlobalConfig === null || configProvider_context.defaultGlobalConfig === void 0 ? void 0 : configProvider_context.defaultGlobalConfig.classPrefix);
        return "".concat(classPrefix, "-").concat(_componentName);
      },
      commonSizeClassName: function commonSizeClassName() {
        return {
          small: "".concat(this.classPrefix, "-size-s"),
          medium: "".concat(this.classPrefix, "-size-m"),
          large: "".concat(this.classPrefix, "-size-l"),
          "default": "",
          xs: "".concat(this.classPrefix, "-size-xs"),
          xl: "".concat(this.classPrefix, "-size-xl"),
          block: "".concat(this.classPrefix, "-size-full-width")
        };
      },
      commonStatusClassName: function commonStatusClassName() {
        return {
          loading: "".concat(this.classPrefix, "-is-loading"),
          loadMore: "".concat(this.classPrefix, "-is-load-more"),
          disabled: "".concat(this.classPrefix, "-is-disabled"),
          focused: "".concat(this.classPrefix, "-is-focused"),
          success: "".concat(this.classPrefix, "-is-success"),
          error: "".concat(this.classPrefix, "-is-error"),
          warning: "".concat(this.classPrefix, "-is-warning"),
          selected: "".concat(this.classPrefix, "-is-selected"),
          active: "".concat(this.classPrefix, "-is-active"),
          checked: "".concat(this.classPrefix, "-is-checked"),
          current: "".concat(this.classPrefix, "-is-current"),
          hidden: "".concat(this.classPrefix, "-is-hidden"),
          visible: "".concat(this.classPrefix, "-is-visible"),
          expanded: "".concat(this.classPrefix, "-is-expanded"),
          indeterminate: "".concat(this.classPrefix, "-is-indeterminate")
        };
      }
    },
    methods: {
      t: function t(pattern, placement) {
        if (typeof pattern === "string") {
          if (!placement) return pattern;
          var regexp = /\{\s*([\w-]+)\s*\}/g;
          var translated = pattern.replace(regexp, function (match, key) {
            if (placement) {
              return String(placement[key]);
            }

            return "";
          });
          return translated;
        }

        if (typeof pattern === "function") {
          return pattern(placement);
        }

        return "";
      }
    }
  });
}
function getGlobalIconMixins() {
  return Vue__default["default"].extend({
    name: "TGlobalIcon",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    methods: {
      useGlobalIcon: function useGlobalIcon(tdIcon) {
        var iconGlobalData = (this.globalConfig || configProvider_context.defaultGlobalConfig).icon;
        var resultIcon = {};
        Object.keys(tdIcon).forEach(function (key) {
          resultIcon[key] = (iconGlobalData === null || iconGlobalData === void 0 ? void 0 : iconGlobalData[key]) || tdIcon[key];
        });
        return resultIcon;
      }
    }
  });
}
function getKeepAnimationMixins() {
  return Vue__default["default"].extend({
    name: "TKeepAnimation",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    computed: {
      keepAnimation: function keepAnimation() {
        var animationConfig = {
          include: ["ripple", "expand", "fade"],
          exclude: []
        };

        if (this.globalConfig && this.globalConfig.animation) {
          animationConfig = _mergeWith__default["default"](animationConfig, this.globalConfig.animation, function (objValue, srcValue) {
            if (Array.isArray(objValue)) {
              return srcValue;
            }
          });
        }

        var isKeep = function isKeep(type) {
          return animationConfig && !animationConfig.exclude.includes(type) && animationConfig.include.includes(type);
        };

        return {
          ripple: isKeep("ripple"),
          expand: isKeep("expand"),
          fade: isKeep("fade")
        };
      }
    }
  });
}
function getClassPrefixMixins(_componentName2) {
  return Vue__default["default"].extend({
    name: "TClassPrefixProvider",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    computed: {
      classPrefix: function classPrefix() {
        var _this$globalConfig3;

        return ((_this$globalConfig3 = this.globalConfig) === null || _this$globalConfig3 === void 0 ? void 0 : _this$globalConfig3.classPrefix) || configProvider_context.defaultGlobalConfig.classPrefix;
      },
      componentName: function componentName() {
        var _this$globalConfig4;

        var classPrefix = ((_this$globalConfig4 = this.globalConfig) === null || _this$globalConfig4 === void 0 ? void 0 : _this$globalConfig4.classPrefix) || configProvider_context.defaultGlobalConfig.classPrefix;
        return "".concat(classPrefix, "-").concat(_componentName2);
      },
      commonSizeClassName: function commonSizeClassName() {
        return {
          small: "".concat(this.classPrefix, "-size-s"),
          medium: "".concat(this.classPrefix, "-size-m"),
          large: "".concat(this.classPrefix, "-size-l"),
          "default": "",
          xs: "".concat(this.classPrefix, "-size-xs"),
          xl: "".concat(this.classPrefix, "-size-xl"),
          block: "".concat(this.classPrefix, "-size-full-width")
        };
      },
      commonStatusClassName: function commonStatusClassName() {
        return {
          loading: "".concat(this.classPrefix, "-is-loading"),
          loadMore: "".concat(this.classPrefix, "-is-load-more"),
          disabled: "".concat(this.classPrefix, "-is-disabled"),
          focused: "".concat(this.classPrefix, "-is-focused"),
          success: "".concat(this.classPrefix, "-is-success"),
          error: "".concat(this.classPrefix, "-is-error"),
          warning: "".concat(this.classPrefix, "-is-warning"),
          selected: "".concat(this.classPrefix, "-is-selected"),
          active: "".concat(this.classPrefix, "-is-active"),
          checked: "".concat(this.classPrefix, "-is-checked"),
          current: "".concat(this.classPrefix, "-is-current"),
          hidden: "".concat(this.classPrefix, "-is-hidden"),
          visible: "".concat(this.classPrefix, "-is-visible"),
          expanded: "".concat(this.classPrefix, "-is-expanded"),
          indeterminate: "".concat(this.classPrefix, "-is-indeterminate")
        };
      }
    }
  });
}

exports["default"] = getConfigReceiverMixins;
exports.getClassPrefixMixins = getClassPrefixMixins;
exports.getGlobalIconMixins = getGlobalIconMixins;
exports.getKeepAnimationMixins = getKeepAnimationMixins;
//# sourceMappingURL=config-receiver.js.map
