import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
import { defineComponent, computed, h } from 'vue';
import { isObject, isString } from 'lodash-es';
import getPrefixCls from '../_util/getPrefixCls';
import { useTheme } from '../_theme/useTheme';
import { getSlot } from '../_util/vnode';
import { degfy } from '../_util/utils';
import { textProps } from './props';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
const prefixCls = getPrefixCls('text');
var text = defineComponent({
  name: 'FText',
  components: {},
  props: _objectSpread({}, textProps),
  setup(props) {
    useTheme();
    const isGradient = computed(() => {
      return isObject(props.gradient) && props.gradient.from && props.gradient.to;
    });
    const textClass = computed(() => ({
      [prefixCls]: true,
      [`${prefixCls}-type--${props.type}`]: props.type,
      [`${prefixCls}-size--${props.size}`]: props.size,
      [`${prefixCls}-text--strong`]: props.strong,
      [`${prefixCls}-text--italic`]: props.italic,
      [`${prefixCls}-tag--mark`]: props.tag === 'mark',
      // 定义mark样式
      [`${prefixCls}-gradient`]: isGradient.value
    }));
    const gradientStyle = computed(() => {
      if (isGradient.value) {
        const gradient = props.gradient;
        const deg = degfy(gradient.deg || 0);
        return {
          backgroundImage: `linear-gradient(${deg}, ${gradient.from}, ${gradient.to})`
        };
      } else if (isString(props.gradient)) {
        // 纯色
        return {
          color: props.gradient
        };
      }
      return {};
    });
    return {
      prefixCls,
      textClass,
      gradientStyle
    };
  },
  render() {
    const children = getSlot(this.$slots);
    return h(this.tag || 'span', {
      class: this.textClass,
      style: this.gradientStyle
    }, children);
  }
});

export { text as default };
