/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var Vue = require('vue');
var mergeWith = require('lodash/mergeWith');
var lodash = require('lodash');
var components_configProvider_context = require('./context.js');
require('../../chunks/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: "ConfigProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      global() {
        const data = this.globalConfig || components_configProvider_context.defaultGlobalConfig;
        return data[componentName];
      },
      classPrefix() {
        var _this$globalConfig;
        return ((_this$globalConfig = this.globalConfig) === null || _this$globalConfig === void 0 ? void 0 : _this$globalConfig.classPrefix) || (components_configProvider_context.defaultGlobalConfig === null || components_configProvider_context.defaultGlobalConfig === void 0 ? void 0 : components_configProvider_context.defaultGlobalConfig.classPrefix);
      },
      componentName() {
        var _this$globalConfig2;
        const classPrefix = ((_this$globalConfig2 = this.globalConfig) === null || _this$globalConfig2 === void 0 ? void 0 : _this$globalConfig2.classPrefix) || (components_configProvider_context.defaultGlobalConfig === null || components_configProvider_context.defaultGlobalConfig === void 0 ? void 0 : components_configProvider_context.defaultGlobalConfig.classPrefix);
        return `${classPrefix}-${componentName}`;
      },
      installName() {
        var _this$globalConfig3;
        const classPrefix = ((_this$globalConfig3 = this.globalConfig) === null || _this$globalConfig3 === void 0 ? void 0 : _this$globalConfig3.classPrefix) || (components_configProvider_context.defaultGlobalConfig === null || components_configProvider_context.defaultGlobalConfig === void 0 ? void 0 : components_configProvider_context.defaultGlobalConfig.classPrefix);
        return `${lodash.toUpper(classPrefix)}${lodash.camelCase(componentName)}`;
      },
      commonSizeClassName() {
        return {
          small: `${this.classPrefix}-size-small`,
          medium: `${this.classPrefix}-size-medium`,
          large: `${this.classPrefix}-size-large`,
          default: "",
          xs: `${this.classPrefix}-size-mini`,
          xl: `${this.classPrefix}-size-huge`,
          block: `${this.classPrefix}-size-full-width`
        };
      },
      commonStatusClassName() {
        return {
          loading: `${this.classPrefix}-is-loading`,
          loadMore: `${this.classPrefix}-is-load-more`,
          disabled: `${this.classPrefix}-is-disabled`,
          focused: `${this.classPrefix}-is-focused`,
          success: `${this.classPrefix}-is-success`,
          error: `${this.classPrefix}-is-error`,
          warning: `${this.classPrefix}-is-warning`,
          selected: `${this.classPrefix}-is-selected`,
          active: `${this.classPrefix}-is-active`,
          checked: `${this.classPrefix}-is-checked`,
          current: `${this.classPrefix}-is-current`,
          hidden: `${this.classPrefix}-is-hidden`,
          visible: `${this.classPrefix}-is-visible`,
          expanded: `${this.classPrefix}-is-expanded`,
          indeterminate: `${this.classPrefix}-is-indeterminate`
        };
      }
    },
    methods: {
      t(pattern, placement) {
        if (typeof pattern === "string") {
          if (!placement) return pattern;
          const regexp = /\{\s*([\w-]+)\s*\}/g;
          const translated = pattern.replace(regexp, (match, key) => {
            if (placement) return String(placement[key]);
            return "";
          });
          return translated;
        }
        if (typeof pattern === "function") return pattern(placement);
        return "";
      }
    }
  });
}
function getKeepAnimationMixins() {
  return Vue__default["default"].extend({
    name: "TKeepAnimation",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      keepAnimation() {
        let animationConfig = mergeWith__default["default"]({}, components_configProvider_context.defaultGlobalConfig.animation);
        if (this.globalConfig && this.globalConfig.animation) {
          animationConfig = mergeWith__default["default"](animationConfig, this.globalConfig.animation, (objValue, srcValue) => {
            if (Array.isArray(objValue)) return srcValue;
          });
        }
        const isKeep = type => animationConfig && !animationConfig.exclude.includes(type) && animationConfig.include.includes(type);
        return {
          ripple: isKeep("ripple"),
          expand: isKeep("expand"),
          fade: isKeep("fade")
        };
      }
    }
  });
}
function getClassPrefixMixins(componentName) {
  return Vue__default["default"].extend({
    name: "ClassPrefixProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      classPrefix() {
        var _this$globalConfig4;
        return ((_this$globalConfig4 = this.globalConfig) === null || _this$globalConfig4 === void 0 ? void 0 : _this$globalConfig4.classPrefix) || components_configProvider_context.defaultGlobalConfig.classPrefix;
      },
      componentName() {
        var _this$globalConfig5;
        const classPrefix = ((_this$globalConfig5 = this.globalConfig) === null || _this$globalConfig5 === void 0 ? void 0 : _this$globalConfig5.classPrefix) || components_configProvider_context.defaultGlobalConfig.classPrefix;
        return `${classPrefix}-${componentName}`;
      },
      commonSizeClassName() {
        return {
          small: `${this.classPrefix}-size-small`,
          medium: `${this.classPrefix}-size-medium`,
          large: `${this.classPrefix}-size-large`,
          default: "",
          xs: `${this.classPrefix}-size-mini`,
          xl: `${this.classPrefix}-size-huge`,
          block: `${this.classPrefix}-size-full-width`
        };
      },
      commonStatusClassName() {
        return {
          loading: `${this.classPrefix}-is-loading`,
          loadMore: `${this.classPrefix}-is-load-more`,
          disabled: `${this.classPrefix}-is-disabled`,
          focused: `${this.classPrefix}-is-focused`,
          success: `${this.classPrefix}-is-success`,
          error: `${this.classPrefix}-is-error`,
          warning: `${this.classPrefix}-is-warning`,
          selected: `${this.classPrefix}-is-selected`,
          active: `${this.classPrefix}-is-active`,
          checked: `${this.classPrefix}-is-checked`,
          current: `${this.classPrefix}-is-current`,
          hidden: `${this.classPrefix}-is-hidden`,
          visible: `${this.classPrefix}-is-visible`,
          expanded: `${this.classPrefix}-is-expanded`,
          indeterminate: `${this.classPrefix}-is-indeterminate`
        };
      }
    }
  });
}
function getGlobalIconMixins() {
  return Vue__default["default"].extend({
    name: "LGlobalIcon",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    methods: {
      useGlobalIcon(tdIcon) {
        const iconGlobalData = (this.globalConfig || components_configProvider_context.defaultGlobalConfig).icon;
        const resultIcon = {};
        Object.keys(tdIcon).forEach(key => {
          resultIcon[key] = (iconGlobalData === null || iconGlobalData === void 0 ? void 0 : iconGlobalData[key]) || tdIcon[key];
        });
        return resultIcon;
      }
    }
  });
}

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