<template>
  <button
    :disabled="isLoading || disabled"
    :type="type"
    :class="[look, 'default', { disabled: disabled || isLoading }]"
    @click="$emit('trigger')"
  >
    <i v-if="icon" :class="[icon, 'icon']"></i>
    <span v-if="text.length" class="text">{{ text }}</span>
    <span v-if="tooltip && tooltip.length" class="tooltip-button">{{
      tooltip
    }}</span>
  </button>
</template>

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

type TypeInterface = 'button' | 'submit' | 'reset'
defineProps({
  icon: { type: String, default: null },
  disabled: { type: Boolean, default: false },
  isLoading: { type: Boolean, default: false },
  text: { type: String, default: '' },
  tooltip: { type: String, default: '' },
  look: { type: String, default: '' },
  type: { type: String as PropType<TypeInterface>, default: 'button' }
})
</script>

<style lang="scss" scoped>
@media (min-width: toRem(76.8)) {
  .default:hover {
    opacity: 0.8;
  }
}
.default {
  height: toRem(3);
  min-width: toRem(3.5);
  @include text(s-regular);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background-color: transparent;
  position: relative;
  z-index: 1;
  border-radius: toRem(1);
  padding: toRem(1.3);

  .icon {
    font-size: toRem(2);
  }
  &:hover .tooltip-button {
    visibility: visible;
  }
}
.button--black {
  color: var(--white);
  background-color: var(--black);
}
.button--blue {
  color: var(--white);
  background-color: var(--blue);
  &.disabled {
    opacity: 0.6;
    color: var(--white);
    cursor: not-allowed;
  }
}

.button--transparent {
  border: toRem(0.1) solid var(--white);
  background-color: var(--black);
  color: var(--white);
}
.button--red {
  color: var(--red);
  background-color: transparent;
  border: toRem(0.1) solid var(--red);
  .icon {
    margin-right: 0;
    font-size: toRem(1.4);
    color: var(--red);
  }
  .text {
    margin-left: toRem(1);
  }
}
.button--white {
  color: var(--blue);
  border: toRem(0.1) solid var(--blue);
  .icon {
    font-size: toRem(1.4);
    color: var(--blue);
    margin-right: 0;
  }
  .text {
    margin-left: toRem(1);
  }
}
.no-text {
  height: toRem(3);
  width: toRem(3);
  padding: 0;
  .icon {
    color: var(--black);
    font-size: toRem(1.8);
    margin-right: 0;
  }
}
.no-text-white .icon {
  color: var(--white);
  margin-right: 0;
}
.background-white {
  background-color: var(--white);
}
.link--grey {
  color: var(--grey-semi-dark);
  .icon {
    font-size: toRem(1.4);
    color: var(--grey-semi-dark);
  }
}
.link--red {
  color: var(--red);
  background-color: var(--white);
  .icon {
    font-size: toRem(1.4);
    color: var(--red);
  }
}

.icon {
  margin-right: toRem(1);
  font-size: toRem(2);
  color: var(--white);
}
.button--rounded {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  padding: 0;
  height: toRem(2.5);
  width: toRem(2.5);
  .icon {
    color: var(---black);
    font-size: toRem(1.8);
    margin-right: 0;
  }
}
.tooltip-button {
  background-color: var(--black);
  color: var(--white);
  text-align: center;
  border-radius: toRem(0.5);
  padding: toRem(0.5) toRem(1);
  position: absolute;
  bottom: -100%;
  visibility: hidden;
  width: toRem(20);
  right: 0;
  @include text(xss-regular);
}

.disabled {
  color: var(--grey-pale);
  border-color: var(--grey-pale);
  cursor: not-allowed;
  .icon {
    color: var(--grey-pale);
  }
}
</style>
