<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;
  background-color: $primary;
  border-radius: $default_border_radius;
  padding-block: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 1;

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

  &.secondary {
    background-color: $main;
    border: 1px solid $border;
    color: $secondary;

    @include hover {
      background-color: $border;
    }

    &.active {
      background-color: $border;
    }

    &:disabled {
      cursor: not-allowed;
      background-color: $disabled_secondary;
    }

    &:disabled:hover, &.active {
      background-color: $disabled_secondary;
    }
  }

  @include hover {
    background-color: $primary_hover;
  }

  &.active {
    background-color: $primary_hover;
  }

  &:disabled {
    cursor: not-allowed;
    background-color: $disabled;
  }

  &:disabled:hover, &.active {
    background-color: $disabled;
  }

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