<template>
  <i v-if="CUSTOM_ICONS[type]" class="icon">
    <svg
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
      v-html="CUSTOM_ICONS[type]"
    ></svg>
  </i>
  <FeatherIcon v-else :type="ICON_NAMES[type] || type" class="icon" />
</template>

<script setup lang="ts">
import FeatherIcon from 'vue-feather'

const ICON_NAMES: { [key: string]: string } = {
  add: 'plus',
  close: 'x',
  edit: 'edit-2',
  email: 'mail',
  discord: 'at-sign',
  times: 'x',
  twitter: 'x.com',
  website: 'globe',
  withdraw: 'dollar-sign',
}

const CUSTOM_ICONS: { [key: string]: string } = {
  'x.com': `<path d="M13.5222 10.7749L19.4785 4H18.0671L12.8952 9.88256L8.76437 4H4L10.2466 12.8955L4 20H5.41155L10.8732 13.7878L15.2356 20H20L13.5222 10.7749Z" fill="currentColor"/><path d="M11.5889 12.9738L10.956 12.0881M12.1522 10.728L12.7851 11.6137L18.0677 19.0075M13.5222 10.7749L19.4785 4H18.0671L12.8952 9.88256L8.76437 4H4L10.2466 12.8955L4 20H5.41155L10.8732 13.7878L15.2356 20H20L13.5222 10.7749Z" stroke="currentColor"/>`,
  vv: `<path d="M11 14.0646C11 15.0625 10.6833 15.8796 10.05 16.5162L6.6 20H4.4L0.949997 16.5162C0.316667 15.8796 0 15.0625 0 14.0646V5H2.575V13.9614C2.575 14.3915 2.68333 14.7183 2.9 14.942L5.525 17.6775L8.1 14.942C8.31669 14.7183 8.425 14.3915 8.425 13.9614V5H11V14.0646Z" fill="currentColor"/><path d="M24 14.0646C24 15.0625 23.6833 15.8796 23.05 16.5162L19.6 20H17.4L13.95 16.5162C13.3167 15.8796 13 15.0625 13 14.0646V5H15.575V13.9614C15.575 14.3915 15.6833 14.7183 15.9 14.942L18.525 17.6775L21.1 14.942C21.3167 14.7183 21.425 14.3915 21.425 13.9614V5H24V14.0646Z" fill="currentColor"/>`,
  check: `<path fill-rule="evenodd" clip-rule="evenodd" d="M15.36 3.88585C15.0088 3.30969 14.5152 2.83358 13.9268 2.50331C13.3383 2.17304 12.6748 1.99971 12 2C10.577 2 9.33 2.75494 8.64 3.88685C7.98396 3.72742 7.29792 3.73945 6.64787 3.92179C5.99782 4.10413 5.40562 4.45064 4.92823 4.928C4.45083 5.40536 4.10429 5.99751 3.92194 6.64751C3.73959 7.29751 3.72756 7.98349 3.887 8.63948C3.31061 8.99055 2.83426 9.48402 2.50379 10.0724C2.17331 10.6608 1.99982 11.3244 2 11.9992C2 13.4221 2.755 14.668 3.886 15.359C3.72655 16.0149 3.73859 16.7009 3.92094 17.3509C4.10329 18.0009 4.44983 18.5931 4.92723 19.0704C5.40462 19.5478 5.99682 19.8943 6.64687 20.0766C7.29692 20.259 7.98296 20.271 8.639 20.1116C9.1267 20.913 9.88486 21.5137 10.7766 21.8053C11.6684 22.0968 12.635 22.06 13.502 21.7015C14.2737 21.3815 14.9241 20.8252 15.36 20.1126C16.0161 20.2721 16.7023 20.2601 17.3525 20.0777C18.0026 19.8953 18.5949 19.5487 19.0723 19.0712C19.5498 18.5937 19.8963 18.0014 20.0785 17.3513C20.2608 16.7011 20.2727 16.015 20.113 15.359C20.6894 15.0079 21.1657 14.5144 21.4962 13.926C21.8267 13.3376 22.0002 12.6741 22 11.9992C22.0002 11.3244 21.8267 10.6608 21.4962 10.0724C21.1657 9.48402 20.6894 8.99055 20.113 8.63948C20.2723 7.98354 20.2601 7.29765 20.0776 6.64778C19.8951 5.99791 19.5485 5.40592 19.071 4.92877C18.594 4.45131 18.0022 4.10459 17.3525 3.92194C16.7027 3.7393 16.0169 3.72687 15.361 3.88585H15.36ZM11.402 15.5979L15.964 8.75447C16.53 7.90854 15.213 7.03061 14.648 7.87654L10.622 13.9191L9.251 12.5512C8.534 11.8292 7.415 12.9471 8.135 13.6671L10.305 15.8169C10.3913 15.8749 10.4883 15.9152 10.5903 15.9356C10.6923 15.9559 10.7973 15.9558 10.8993 15.9354C11.0013 15.9149 11.0982 15.8745 11.1845 15.8164C11.2708 15.7583 11.3447 15.6837 11.402 15.5969V15.5979Z" fill="currentColor"/>`,
  context: `<path d="M21 6H3.48181" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M21 11.9102H3.48181" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M21 17.9688H12.2409" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>`,
  checkmark: `<polyline points="20 6 9 17 4 12" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"></polyline>`,
}

const props = defineProps<{ type: string }>()

const type = computed(() => ICON_NAMES[props.type] || props.type)
</script>

<style scoped>
.icon {
  display: inline-block;
  width: var(--size-4);
  height: var(--size-4);

  :deep(svg) {
    width: 100%;
    height: 100%;
  }

  &.spin {
    animation: spin 5s infinite linear;
  }
}
</style>
