/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var Vue = require('vue');
var mergeWith = require('lodash/mergeWith');
var components_configProvider_context = require('./context.js');
require('lodash/merge');
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: "TConfigProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      global() {
        const data = this.globalConfig || components_configProvider_context.defaultGlobalConfig;
        return data[componentName];
      },
      classPrefix() {
        return this.globalConfig?.classPrefix || components_configProvider_context.defaultGlobalConfig?.classPrefix;
      },
      componentName() {
        const classPrefix = this.globalConfig?.classPrefix || components_configProvider_context.defaultGlobalConfig?.classPrefix;
        return `${classPrefix}-${componentName}`;
      },
      commonSizeClassName() {
        return {
          small: `${this.classPrefix}-size-s`,
          medium: `${this.classPrefix}-size-m`,
          large: `${this.classPrefix}-size-l`,
          default: "",
          xs: `${this.classPrefix}-size-xs`,
          xl: `${this.classPrefix}-size-xl`,
          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 getGlobalIconMixins() {
  return Vue__default["default"].extend({
    name: "TGlobalIcon",
    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?.[key] || tdIcon[key];
        });
        return resultIcon;
      }
    }
  });
}
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: "TClassPrefixProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      classPrefix() {
        return this.globalConfig?.classPrefix || components_configProvider_context.defaultGlobalConfig.classPrefix;
      },
      componentName() {
        const classPrefix = this.globalConfig?.classPrefix || components_configProvider_context.defaultGlobalConfig.classPrefix;
        return `${classPrefix}-${componentName}`;
      },
      commonSizeClassName() {
        return {
          small: `${this.classPrefix}-size-s`,
          medium: `${this.classPrefix}-size-m`,
          large: `${this.classPrefix}-size-l`,
          default: "",
          xs: `${this.classPrefix}-size-xs`,
          xl: `${this.classPrefix}-size-xl`,
          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`
        };
      }
    }
  });
}

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