import { defineComponent } from 'vue'

export const getAssetsHomeFile = (fileName: string) => {
  const path = `./icons/${fileName}.svg`
  // @ts-ignore
  const modules = import.meta.globEager('./icons/*.svg')
  return modules[path]?.default
}

export type ButtonIcon = {
  name: string
}

/**
 * 用于操作按钮的组件
 */
export default defineComponent({
  name: 'ButtonIcon',
  props: {
    name: {
      type: String,
    },
  },
  setup(props) {
    return () =>
      props.name ? <img src={getAssetsHomeFile(props.name)} /> : null
  },
})
