<template>
  <span
    class="iconify"
    :data-icon="iconIdentifier"
    :style="iconStyle"
  ></span>
</template>

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

interface Props {
  iconIdentifier: string
  width?: string | number
  height?: string | number
  color?: string
  size?: string | number
}

const props = withDefaults(defineProps<Props>(), {
  width: '1em',
  height: '1em',
  color: undefined,
  size: undefined
})

const iconStyle = computed(() => {
  const style: Record<string, string> = {}
  
  if (props.width) {
    style.width = typeof props.width === 'number' ? `${props.width}px` : props.width
  }
  if (props.height) {
    style.height = typeof props.height === 'number' ? `${props.height}px` : props.height
  }
  if (props.color) {
    style.color = props.color
  }
  if (props.size) {
    const size = typeof props.size === 'number' ? `${props.size}px` : props.size
    style.fontSize = size
  }
  
  return style
})
</script>

<style scoped lang="scss">
.iconify {
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
}
</style>
