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

import Vue from 'vue';
import mergeWith from 'lodash/mergeWith';
import { defaultGlobalConfig } from './context.js';
import './type.js';
import 'lodash/merge';
import '../../chunks/zh_CN.js';

function getConfigReceiverMixins(componentName) {
  return Vue.extend({
    name: "TConfigProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      global() {
        const data = this.globalConfig || defaultGlobalConfig;
        return data[componentName];
      },
      classPrefix() {
        return this.globalConfig?.classPrefix || defaultGlobalConfig?.classPrefix;
      },
      componentName() {
        const classPrefix = this.globalConfig?.classPrefix || 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.extend({
    name: "TGlobalIcon",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    methods: {
      useGlobalIcon(tdIcon) {
        const iconGlobalData = (this.globalConfig || defaultGlobalConfig).icon;
        const resultIcon = {};
        Object.keys(tdIcon).forEach(key => {
          resultIcon[key] = iconGlobalData?.[key] || tdIcon[key];
        });
        return resultIcon;
      }
    }
  });
}
function getKeepAnimationMixins() {
  return Vue.extend({
    name: "TKeepAnimation",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      keepAnimation() {
        let animationConfig = mergeWith({}, defaultGlobalConfig.animation);
        if (this.globalConfig && this.globalConfig.animation) {
          animationConfig = mergeWith(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.extend({
    name: "TClassPrefixProvider",
    inject: {
      globalConfig: {
        default: void 0
      }
    },
    computed: {
      classPrefix() {
        return this.globalConfig?.classPrefix || defaultGlobalConfig.classPrefix;
      },
      componentName() {
        const classPrefix = this.globalConfig?.classPrefix || 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`
        };
      }
    }
  });
}

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