<template>
  <button
      class="button"
      :disabled="isDisabled"
      :class="[
          { active: isLoading },
          { secondary: style === 'secondary' }
      ]"
      :type="type"
  >
    <ui-loader class="button__loader" v-if="isLoading" />
    <slot v-else />
  </button>
</template>

<script setup lang="ts">
const props = defineProps<{
  type: 'submit' | 'button';
  isDisabled?: boolean;
  isLoading?: boolean;
  style?: string;
}>();
</script>

<style lang="scss" scoped>
.button {
  position: relative;
  width: 100%;
  cursor: pointer;
  flex-shrink: 0;
  transition: 0.2s;
  background-color: #111827;
  border-radius: 8px;
  padding-block: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 1;

  color: $white;
  text-align: center;
  font-size: 16px;
  font-weight: 500;

  &.secondary {
    background-color: $white;
    border: 1px solid #d1d5db;
    color: #374151;

    @include hover {
      background-color: #d1d5db;
    }

    &.active {
      background-color: #d1d5db;
    }

    &:disabled {
      cursor: not-allowed;
      background-color: #9a9a9a;
    }

    &:disabled:hover, &.active {
      background-color: #9a9a9a;
    }
  }

  @include hover {
    background-color: #222c41;
  }

  &.active {
    background-color: #222c41;
  }

  &:disabled {
    cursor: not-allowed;
    background-color: #0a0f1a;
  }

  &:disabled:hover, &.active {
    background-color: #0a0f1a;
  }

  &__loader {
    margin-block: 4px;
  }
}
</style>