<script lang="ts" setup>
import { computed } from 'vue'
import type { CSSProperties } from 'vue'

defineOptions({ name: 'SvgIcon' })

const props = defineProps({
  prefix: {
    type: String,
    default: 'icon',
  },
  name: {
    type: String,
    required: true,
  },
  size: {
    type: [Number, String],
    default: 64,
  },
  color: {
    type: String,
    default: '',
  },
  width: {
    type: [Number, String],
    default: 0,
  },
  height: {
    type: [Number, String],
    default: 0,
  },
})

const symbolId = computed(() => `#${props.prefix}-${props.name}`)

const getStyle = computed((): CSSProperties => {
  const { size, color, width, height } = props
  let s = `${size}`
  s = `${s.replace('px', '')}px`
  return {
    width: width || size,
    height: height || size,
    fill: color,
  }
})
</script>

<template>
  <svg class="svg-icon" :style="getStyle" aria-hidden="true">
    <use :xlink:href="symbolId" />
  </svg>
</template>

<style lang="less" scoped>
.svg-icon {
  display: inline-block;
  overflow: hidden;
}
</style>
