/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import Vue from 'vue';
import mergeWith from 'lodash/mergeWith';
import { toUpper, camelCase } from 'lodash';
import { defaultGlobalConfig } from './context.js';
import '../../_chunks/dep-a0f2090c.js';

function getConfigReceiverMixins(_componentName) {
  return Vue.extend({
    name: "ConfigProvider",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    computed: {
      global: function global() {
        var data = this.globalConfig || 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) || (defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.classPrefix);
      },
      componentName: function componentName() {
        var _this$globalConfig2;

        var classPrefix = ((_this$globalConfig2 = this.globalConfig) === null || _this$globalConfig2 === void 0 ? void 0 : _this$globalConfig2.classPrefix) || (defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.classPrefix);
        return "".concat(classPrefix, "-").concat(_componentName);
      },
      installName: function installName() {
        var _this$globalConfig3;

        var classPrefix = ((_this$globalConfig3 = this.globalConfig) === null || _this$globalConfig3 === void 0 ? void 0 : _this$globalConfig3.classPrefix) || (defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.classPrefix);
        return "".concat(toUpper(classPrefix)).concat(camelCase(_componentName));
      },
      commonSizeClassName: function commonSizeClassName() {
        return {
          small: "".concat(this.classPrefix, "-size-small"),
          medium: "".concat(this.classPrefix, "-size-medium"),
          large: "".concat(this.classPrefix, "-size-large"),
          "default": "",
          xs: "".concat(this.classPrefix, "-size-mini"),
          xl: "".concat(this.classPrefix, "-size-huge"),
          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 getKeepAnimationMixins() {
  return Vue.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(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.extend({
    name: "ClassPrefixProvider",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    computed: {
      classPrefix: function classPrefix() {
        var _this$globalConfig4;

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

        var classPrefix = ((_this$globalConfig5 = this.globalConfig) === null || _this$globalConfig5 === void 0 ? void 0 : _this$globalConfig5.classPrefix) || defaultGlobalConfig.classPrefix;
        return "".concat(classPrefix, "-").concat(_componentName2);
      },
      commonSizeClassName: function commonSizeClassName() {
        return {
          small: "".concat(this.classPrefix, "-size-small"),
          medium: "".concat(this.classPrefix, "-size-medium"),
          large: "".concat(this.classPrefix, "-size-large"),
          "default": "",
          xs: "".concat(this.classPrefix, "-size-mini"),
          xl: "".concat(this.classPrefix, "-size-huge"),
          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")
        };
      }
    }
  });
}
function getGlobalIconMixins() {
  return Vue.extend({
    name: "LGlobalIcon",
    inject: {
      globalConfig: {
        "default": void 0
      }
    },
    methods: {
      useGlobalIcon: function useGlobalIcon(tdIcon) {
        var iconGlobalData = (this.globalConfig || 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;
      }
    }
  });
}

export { getConfigReceiverMixins as default, getClassPrefixMixins, getGlobalIconMixins, getKeepAnimationMixins };
//# sourceMappingURL=config-receiver.js.map
