@import '~@palmetto/palmetto-design-tokens/build/scss/variables-size';

:root {
  --button-box-shadow-focus: 0 0 0 4px var(--color-brand-primary-200);
  --button-neutral-box-shadow-focus: 0 0 0 4px var(--color-brand-grey-200);
  --button-danger-box-shadow-focus: 0 0 0 4px var(--color-brand-danger-200);
}

@mixin size-xs {
  border-radius: var(
    --button-size-xs-border-radius,
    var(--INTERNAL_form-control-size-sm-border-radius)
  );
  padding: var(--button-size-xs-padding-vertical, var(--size-spacing-2xs))
    var(--button-size-xs-padding-horizontal, var(--size-spacing-xs));
  min-height: 20px;
  font-size: var(
    --button-size-xs-font-size,
    var(--INTERNAL_form-control-size-xs-font-size)
  );
  letter-spacing: 0.2px;

  &.outline {
    padding: calc(
        var(--button-size-xs-padding-vertical, var(--size-spacing-2xs)) - 1px
      )
      calc(
        var(--button-size-xs-padding-horizontal, var(--size-spacing-xs)) - 1px
      );
  }
}

%size-xs {
  @include size-xs;
}

.size-xs {
  @extend %size-xs;
}

@mixin size-sm {
  border-radius: var(
    --button-size-sm-border-radius,
    var(--INTERNAL_form-control-size-sm-border-radius)
  );
  padding: calc(
      var(
          --button-size-sm-padding-vertical,
          var(--INTERNAL_form-control-size-sm-padding)
        ) - 1px
    )
    calc(var(--button-size-sm-padding-horizontal, var(--size-spacing-sm)) - 1px);
  min-height: 32px;
  font-size: var(
    --button-size-sm-font-size,
    var(--INTERNAL_form-control-size-sm-font-size)
  );
  letter-spacing: 0.2px;

  &.outline {
    padding: calc(
        var(
            --button-size-sm-padding-vertical,
            var(--INTERNAL_form-control-size-sm-padding)
          ) - 1px
      )
      calc(
        var(--button-size-sm-padding-horizontal, var(--size-spacing-sm)) - 1px
      );
  }
}

%size-sm {
  @include size-sm;
}

.size-sm {
  @extend %size-sm;
}

@mixin size-md {
  border-radius: var(
    --button-size-md-border-radius,
    var(--INTERNAL_form-control-size-md-border-radius)
  );
  padding: calc(
      var(
          --button-size-md-padding-vertical,
          var(--INTERNAL_form-control-size-md-padding)
        ) - 1px
    )
    calc(var(--button-size-md-padding-horizontal, var(--size-spacing-md)) - 1px);
  font-size: var(
    --button-size-md-font-size,
    var(--INTERNAL_form-control-size-md-font-size)
  );
  letter-spacing: 0.2px;

  &.outline {
    padding: calc(
        var(
            --button-size-md-padding-vertical,
            var(--INTERNAL_form-control-size-md-padding)
          ) - 1px
      )
      calc(
        var(--button-size-md-padding-horizontal, var(--size-spacing-md)) - 1px
      );
  }
}

%size-md {
  @include size-md;
}

.size-md {
  @extend %size-md;
}

@mixin size-lg {
  border-radius: var(
    --button-size-lg-border-radius,
    var(--INTERNAL_form-control-size-lg-border-radius)
  );
  padding: calc(
      var(
          --button-size-lg-padding-vertical,
          var(--INTERNAL_form-control-size-lg-padding)
        ) - 1px
    )
    calc(var(--button-size-lg-padding-horizontal, var(--size-spacing-lg)) - 1px);
  min-height: 55px;
  letter-spacing: 1px;
  font-size: var(
    --button-size-lg-font-size,
    var(--INTERNAL_form-control-size-lg-font-size)
  );
}

%size-lg {
  @include size-lg;
}

.size-lg {
  @extend %size-lg;
}

.button {
  border: 1px solid transparent;
  cursor: pointer;
  background-color: transparent;
  padding: 0;
  color: inherit;
  line-height: var(--size-line-height-input);
  font-family: var(--asset-fonts-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition-duration: 0.1s;
  transition-property: background-color, border, box-shadow, color;
  transition-timing-function: cubic-bezier(0.67, 0.83, 0.67);
  text-align: center;
  text-decoration: none;
  font-weight: var(--button-font-weight, var(--size-font-weight-medium));

  &:hover {
    text-decoration: none;
  }

  &:disabled {
    opacity: 0.65;
    cursor: not-allowed;
  }

  &.primary {
    background-color: var(--color-background-button-primary);
    color: var(--color-text-button-primary);

    &:focus {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    // Show focus styles on keyboard focus.
    &:focus-visible {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    // Hide focus styles if they are not needed, for example,
    // when an element receives focus via the mouse.
    &:focus:not(:focus-visible) {
      outline: 0;
      box-shadow: none;
    }

    &:not(:disabled):hover {
      background-color: var(--color-background-button-primary-hover);
      color: var(--color-text-button-primary-hover);
    }

    &:not(:disabled):active {
      background-color: var(--color-background-button-primary-active);
    }

    &.neutral {
      background-color: var(--color-background-button-primary-neutral);
      color: var(--color-text-button-primary-neutral);

      &:focus {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        background-color: var(--color-background-button-primary-neutral-hover);
        color: var(--color-text-button-primary-neutral-hover);
      }

      &:not(:disabled):active {
        background-color: var(--color-background-button-primary-neutral-active);
      }
    }

    &.danger {
      background-color: var(--color-background-button-primary-danger);
      color: var(--color-text-button-primary-danger);

      &:focus {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        background-color: var(--color-background-button-primary-danger-hover);
        color: var(--color-text-button-primary-danger-hover);
      }

      &:not(:disabled):active {
        background-color: var(--color-background-button-primary-danger-active);
      }
    }
  }

  &.secondary {
    border: 1px solid;
    border-color: var(--color-border-button-secondary);
    background-color: var(--color-background-button-secondary);
    color: var(--color-text-button-secondary);

    &:focus {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    // Show focus styles on keyboard focus.
    &:focus-visible {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    &:focus:not(:focus-visible) {
      outline: 0;
      box-shadow: none;
    }

    &:not(:disabled):hover {
      border-color: var(--color-border-button-secondary-hover);
      background-color: var(--color-background-button-secondary-hover);
      color: var(--color-text-button-secondary-hover);
    }

    &:not(:disabled):active {
      background-color: var(--color-background-button-secondary-active);
    }

    &.neutral {
      background-color: var(--color-background-button-secondary-neutral);
      border: 1px solid;
      border-color: var(--color-border-button-secondary-neutral);
      color: var(--color-text-button-secondary-neutral);

      &:focus {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      // Show focus styles on keyboard focus.
      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        border-color: var(--color-border-button-secondary-neutral-hover);
        background-color: var(
          --color-background-button-secondary-neutral-hover
        );
        color: var(--color-text-button-secondary-neutral-hover);
      }

      &:not(:disabled):active {
        background-color: var(
          --color-background-button-secondary-neutral-active
        );
      }
    }

    &.danger {
      background-color: var(--color-background-button-secondary-danger);
      border: 1px solid;
      border-color: var(--color-border-button-secondary-danger);
      color: var(--color-text-button-secondary-danger);

      &:focus {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        border-color: var(--color-border-button-secondary-danger-hover);
        background-color: var(--color-background-button-secondary-danger-hover);
        color: var(--color-text-button-secondary-danger-hover);
      }

      &:not(:disabled):active {
        background-color: var(
          --color-background-button-secondary-danger-active
        );
      }
    }
  }

  &.tertiary {
    background-color: var(--color-background-button-tertiary);
    color: var(--color-text-button-tertiary);

    &:focus {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    // Show focus styles on keyboard focus.
    &:focus-visible {
      outline: 0;
      box-shadow: var(--button-box-shadow-focus);
    }

    &:focus:not(:focus-visible) {
      outline: 0;
      box-shadow: none;
    }

    &:not(:disabled):hover {
      background-color: var(--color-background-button-tertiary-hover);
      border-color: var(--color-background-button-tertiary-hover);
      color: var(--color-text-button-tertiary-hover);
    }

    &:not(:disabled):active {
      background-color: var(--color-background-button-tertiary-active);
      border-color: var(--color-background-button-tertiary-active);
    }

    &.neutral {
      background-color: var(--color-background-button-tertiary-neutral);
      color: var(--color-text-button-tertiary-neutral);

      &:focus {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      // Show focus styles on keyboard focus.
      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-neutral-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        background-color: var(--color-background-button-tertiary-neutral-hover);
        border-color: var(--color-background-button-tertiary-neutral-hover);
        color: var(--color-text-button-tertiary-neutral-hover);
      }

      &:not(:disabled):active {
        background-color: var(
          --color-background-button-tertiary-neutral-active
        );
      }
    }

    &.danger {
      background-color: var(--color-background-button-tertiary-danger);
      color: var(--color-text-button-tertiary-danger);

      &:focus {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus-visible {
        outline: 0;
        box-shadow: var(--button-danger-box-shadow-focus);
      }

      &:focus:not(:focus-visible) {
        outline: 0;
        box-shadow: none;
      }

      &:not(:disabled):hover {
        background-color: var(--color-background-button-tertiary-danger-hover);
        border-color: var(--color-background-button-tertiary-danger-hover);
        color: var(--color-text-button-tertiary-danger-hover);
      }

      &:not(:disabled):active {
        background-color: var(--color-background-button-tertiary-danger-active);
      }
    }
  }

  &.xs {
    border-radius: var(--button-size-xs-border-radius);
    padding: var(--button-size-xs-padding-vertical)
      var(--button-size-xs-padding-horizontal);
    min-height: 20px;
    font-size: var(--button-size-xs-font-size);

    &.outline {
      padding: calc(var(--button-size-xs-padding-vertical) - 1px)
        calc(var(--button-size-xs-padding-horizontal) - 1px);
    }
  }

  &.sm {
    border-radius: var(--button-size-sm-border-radius);
    padding: var(--button-size-sm-padding-vertical)
      var(--button-size-sm-padding-horizontal);
    min-height: 32px;
    font-size: var(--button-size-sm-font-size);
  }

  &.size-xs {
    @extend %size-xs;
  }

  &.size-sm {
    @extend %size-sm;
  }

  &.size-md {
    @extend %size-md;
  }

  &.size-lg {
    @extend %size-lg;
  }

  @media (min-width: $size-breakpoint-tablet) {
    &.size-xs-tablet {
      @include size-xs;
    }

    &.size-sm-tablet {
      @include size-sm;
    }

    &.size-md-tablet {
      @include size-md;
    }

    &.size-lg-tablet {
      @include size-lg;
    }
  }

  @media (min-width: $size-breakpoint-desktop) {
    &.size-xs-desktop {
      @include size-xs;
    }

    &.size-sm-desktop {
      @include size-sm;
    }

    &.size-md-desktop {
      @include size-md;
    }

    &.size-lg-desktop {
      @include size-lg;
    }
  }

  @media (min-width: $size-breakpoint-hd) {
    &.size-xs-hd {
      @include size-xs;
    }

    &.size-sm-hd {
      @include size-sm;
    }

    &.size-md-hd {
      @include size-md;
    }

    &.size-lg-hd {
      @include size-lg;
    }
  }

  &.loading {
    .label {
      visibility: hidden;
    }
  }

  &.full-width {
    width: 100%;
  }
}

.spinner-wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
