<template>
  <a :class="iconStyle" @click="props.iconClick" v-if="props.isClickDiff">
    {{ props.isMatIcon ? props.iconContent.indexOf('img') != -1 ? '' : props.iconContent : '' }}
    <img v-if="isExist(props.iconContent)" @click="props.iconClick" :src="'./' + analysis(props.iconContent)"
      style="height:28px;width:28px;" /></a>
  <a :class="iconStyle" @click.stop="props.iconClick" v-else>{{ props.isMatIcon ? props.iconContent : '' }}</a>
</template>
<script lang="ts" setup>
import { PropType, ref } from 'vue';
import { iconNames, icons } from './icons';

// const env = ref(process.env.NODE_ENV);
// env === 'production' ? '../../public/statics/icons/' : 
const props = defineProps({
  icon: {
    type: String as PropType<iconNames>,
    default: 'menu',
  },
  isIconPointer: {
    type: Boolean,
    default: false,
  },
  iconClick: {
    type: Function as PropType<(e: any) => void>,
  },
  isClickDiff: {
    type: Boolean,
    default: true,
  },
  isMatIcon: {
    type: Boolean,
    default: false,
  },
  iconContent: {
    type: String,
    default: ''
  }
});
const pointStyle = props.isIconPointer ? ' pointer' : '';
const iconStyle = ref(icons[props.icon] + pointStyle);

if (props.isMatIcon) {
  iconStyle.value = 'material-icons';
}


const analysis = (icon: any) => {
  let iconSrc = ''
  if (icon?.indexOf('img') != -1) {
    iconSrc = icon?.substring(icon?.indexOf(':') + 1, icon.length)
  }
  return iconSrc
}

const isExist = (icon: any) => {
  return icon?.indexOf('img') != -1
}
</script>
<style lang="scss" scoped>
.textIcon {
  font-size: 15px;
  -webkit-user-select: none;
  /* 禁止 DIV 中的文本被鼠标选中 */
  -moz-user-select: none;
  /* 禁止 DIV 中的文本被鼠标选中 */
  -ms-user-select: none;
  /* 禁止 DIV 中的文本被鼠标选中 */
  user-select: none;
  /* 禁止 DIV 中的文本被鼠标选中 */
  margin-right: 0.24vw;
  font-family: 'iconfont';
  margin-top: 0.11439vh;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  text-align: center;

  &.home:before {
    content: '\e6a5';
  }

  &.menu:before {
    content: '\e60b';
  }

  &.search:before {
    content: '\e8d6';
  }

  &.useHead:before {
    content: '\e639';
  }

  &.remind:before {
    content: '\e608';
  }

  &.close:before {
    content: '\e655';
  }

  &.dropDown:before {
    content: '\e650';
  }

  &.folder:before {
    content: '\e61d';
  }

  &.delete:before {
    content: '\e63f';
  }

  &.edit:before {
    content: '\e61b';
  }

  &.ballot:before {
    content: '\e657';
  }

  &.dict:before {
    content: '\e656';
  }

  &.log:before {
    content: '\e69d';
  }

  &.add:before {
    content: '\e70b';
  }

  &.pointer {
    cursor: pointer;
  }
}

.mat {
  &.textIcon {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 15px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    -webkit-user-select: none;
    /* 禁止 DIV 中的文本被鼠标选中 */
    -moz-user-select: none;
    /* 禁止 DIV 中的文本被鼠标选中 */
    -ms-user-select: none;
    /* 禁止 DIV 中的文本被鼠标选中 */
    user-select: none;

    /* 禁止 DIV 中的文本被鼠标选中 */
    &.home:before {
      content: '\e6a5';
    }

    &.menu:before {
      content: '\e60b';
    }

    &.search:before {
      content: '\e8d6';
    }

    &.useHead:before {
      content: '\e639';
    }

    &.remind:before {
      content: '\e608';
    }

    &.close:before {
      content: '\e655';
    }

    &.dropDown:before {
      content: '\e650';
    }

    &.folder:before {
      content: '\e61d';
    }

    &.delete:before {
      content: '\e63f';
    }

    &.edit:before {
      content: '\e61b';
    }

    &.ballot:before {
      content: '\e657';
    }

    &.dict:before {
      content: '\e656';
    }

    &.log:before {
      content: '\e69d';
    }

    &.add:before {
      content: '\e70b';
    }

    &.pointer {
      cursor: pointer;
    }
  }
}
</style>
