<template>
	<svg v-on="$attrs" class="svg-icon" :class="svgClass" :style="getStyle" aria-hidden="true">
		<use :xlink:href="symbolId" :fill="props.color" />
	</svg>
</template>

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

const props = defineProps({
	prefix: {
		type: String,
		default: 'svg-icon'
	},
	name: {
		type: String,
		required: true
	},
	color: {
		type: String,
		default: ''
	},
	size: {
		type: [Number, String],
		default: 16
	},
	className: {
		type: String,
		default: ''
	}
})
const symbolId = computed(() => `#${props.prefix}-${props.name}`)
const svgClass = computed(() => {
	if (props.className) {
		return `svg-icon ${props.className}`
	} else {
		return 'svg-icon'
	}
})
const getStyle = computed((): CSSProperties => {
	const { size } = props
	const s = `${size}`.replace('px', '').concat('px')
	return {
		width: s,
		height: s
	}
})
</script>

<style>
.svg-icon {
	overflow: hidden;
	vertical-align: -0.15em;
}
</style>
