<commit_before><template>
  <div :class="classes" @mouseleave="onMouseleave">
    <div class="co-rate__item" v-for="(item, index) in max" :key="index">
      <co-icon
        :style="iconStyles(index)"
        type="star"
        @mouseenter.native="onMouseenter(index)"
        @click.native="onClick(index)"></co-icon>
      <co-icon
        class="co-rate__icon-half"
        :style="iconStyles(index, true)"
        type="star"
        @mouseenter.native="onMouseenter(index, true)"
        @click.native="onClick(index, true)"></co-icon>
    </div>
  </div>
</template>

<script>
import CoIcon from 'components/icon';

export default {
  name: 'co-rate',
  props: {
    value: {
      type: Number,
      default: 0,
    },
    max: {
      type: Number,
      default: 5,
    },
    voidColor: {
      type: String,
      default: '#e9e9e9',
    },
    colors: {
      type: Array,
      default() {
        return ['#f7ba2a', '#f7ba2a', '#f7ba2a'];
      },
      validator(value) {
        return value.length === 3;
      },
    },
    lowThreshold: {
      type: Number,
      default: 2,
    },
    highThreshold: {
      type: Number,
      default: 4,
    },
    allowHalf: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    icons: {
      type: Array,
      default() {
        return ['star', 'star', 'star'];
      },
    },
    voidIcon: {
      type: String,
      default: 'star',
    },
  },
  data() {
    const { value } = this;

    return {
      currentValue: value,
      hoverCount: value,
    };
  },
  watch: {
    value(newVal) {
      if (newVal !== this.currentValue) {
        this.currentValue = newVal;
      }
    },
  },
  computed: {
    classes() {
      const prefixClass = 'co-rate';

      return [prefixClass, {
        [`${prefixClass}--disabled`]: this.disabled,
      }];
    },
  },
  methods: {
    iconStyles(count, half = false) {
      const styles = {};
      const { hoverCount, lowThreshold, highThreshold, colors, voidColor } = this;
      const n = half ? count + 0.5 : count + 1;

      if (n <= hoverCount) {
        if (hoverCount <= lowThreshold) {
          styles.color = colors[0];
        } else if (hoverCount > lowThreshold && hoverCount < highThreshold) {
          styles.color = colors[1];
        } else {
          styles.color = colors[2];
        }
      } else {
        styles.color = voidColor;
      }

      return styles;
    },
    onMouseenter(count, half = false) {
      if (this.disabled) return;<commit_msg>rate 添加 icons voidIcon 属性<commit_after><template>
  <div :class="classes" @mouseleave="onMouseleave">
    <div class="co-rate__item" v-for="(item, index) in max" :key="index">
      <co-icon
        :style="iconStyles(index)"
        :type="iconType(index)"
        @mouseenter.native="onMouseenter(index)"
        @click.native="onClick(index)"></co-icon>
      <co-icon
        class="co-rate__icon-half"
        :style="iconStyles(index, true)"
        :type="iconType(index)"
        @mouseenter.native="onMouseenter(index, true)"
        @click.native="onClick(index, true)"></co-icon>
    </div>
  </div>
</template>

<script>
import CoIcon from 'components/icon';

export default {
  name: 'co-rate',
  props: {
    value: {
      type: Number,
      default: 0,
    },
    max: {
      type: Number,
      default: 5,
    },
    voidColor: {
      type: String,
      default: '#e9e9e9',
    },
    colors: {
      type: Array,
      default() {
        return ['#f7ba2a', '#f7ba2a', '#f7ba2a'];
      },
      validator(value) {
        return value.length === 3;
      },
    },
    lowThreshold: {
      type: Number,
      default: 2,
    },
    highThreshold: {
      type: Number,
      default: 4,
    },
    allowHalf: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    icons: {
      type: Array,
      default() {
        return ['star', 'star', 'star'];
      },
      validator(value) {
        return value.length === 3;
      },
    },
    voidIcon: {
      type: String,
      default: 'star',
    },
  },
  data() {
    const { value } = this;

    return {
      currentValue: value,
      hoverCount: value,
    };
  },
  watch: {
    value(newVal) {
      if (newVal !== this.currentValue) {
        this.currentValue = newVal;
      }
    },
  },
  computed: {
    classes() {
      const prefixClass = 'co-rate';

      return [prefixClass, {
        [`${prefixClass}--disabled`]: this.disabled,
      }];
    },
  },
  methods: {
    iconStyles(count, half = false) {
      const styles = {};
      const { hoverCount, lowThreshold, highThreshold, colors, voidColor } = this;
      const n = half ? count + 0.5 : count + 1;

      if (n <= hoverCount) {
        if (hoverCount <= lowThreshold) {
          styles.color = colors[0];
        } else if (hoverCount > lowThreshold && hoverCount < highThreshold) {
          styles.color = colors[1];
        } else {
          styles.color = colors[2];
        }
      } else {
        styles.color = voidColor;
      }

      return styles;
    },
    iconType(index) {
      const { hoverCount, lowThreshold, highThreshold, icons } = this;
      const count = index + 1;

      if (count <= hoverCount) {
        if (hoverCount <= lowThreshold) {
          return icons[0];
        } else if (count > lowThreshold && count < highThreshold) {
          return icons[1];
        }

        return icons[2];
      }

      return this.voidIcon;
    },
    onMouseenter(count, half = false) {
      if (this.disabled) return;
{'fraction_non_alphanumeric': 0.15267175572519084, 'fraction_numerical': 0.007988638380969288, 'mean_word_length': 1.9191709844559586, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2618425', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1815, 'n_words': 384}