// Copyright 2018-Present Okta, Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

.button {
  display: inline-block;
  position: relative;
  margin: 0;
  padding: $em-tiny-spacing $em-base-spacing;
  // ASA: https://github.com/okta/odyssey/issues/255
  border: 2px solid transparent;
  border-radius: $base-border-radius;
  background-color: cv('action');
  box-shadow: 0 0 0 0 fauxpacity(cv('action', 'base'));
  color: $white;
  font-family: $body-font-family;
  font-size: ms(0);
  font-weight: 600;
  line-height: $heading-line-height;

  &:hover,
  &.is-button-hover {
    border-color: cv('action', 'dark');
    background-color: cv('action', 'dark');
    cursor: pointer;
  }

  &:focus,
  &.is-button-focus {
    outline: 0;
    background-color: cv('action', 'dark');
    box-shadow: 0 0 0 4px fauxpacity(cv('action', 'base'));
  }

  &:disabled {
    border-color: transparent;
    background-color: fauxpacity(cv('action', 'base'));
    cursor: not-allowed;
  }
}

.is-button-secondary {
  border-color: cv('action');
  background-color: $white;
  color: cv('action');

  &:hover,
  &.is-button-hover {
    border-color: cv('action', 'dark');
    background-color: cv('action', 'lightest');
    color: cv('action', 'dark');
  }

  &:focus,
  &.is-button-focus {
    border-color: cv('action', 'dark');
    background-color: cv('action', 'lightest');
    color: cv('action', 'dark');
  }

  &:disabled {
    border-color: fauxpacity(cv('action', 'base'));
    background-color: $white;
    color: fauxpacity(cv('action', 'base'));
  }
}

.is-button-danger {
  background-color: cv('danger');

  &:hover,
  &.is-button-hover {
    border-color: cv('danger', 'dark');
    background-color: cv('danger', 'dark');
  }

  &:focus,
  &.is-button-focus {
    background-color: cv('danger', 'dark');
    box-shadow: 0 0 0 4px fauxpacity(cv('danger', 'base'));
  }

  &:disabled {
    background-color: fauxpacity(cv('danger', 'base'));
  }

  &.is-button-secondary {
    border-color: cv('danger');
    background-color: $white;
    color: cv('danger');

    &:focus,
    &.is-button-focus {
      border-color: cv('danger', 'dark');
      background-color: cv('danger', 'lightest');
      color: cv('danger', 'dark');
    }

    &:disabled {
      border-color: fauxpacity(cv('danger', 'base'));
      background-color: $white;
      color: fauxpacity(cv('danger', 'base'));
    }
  }
}

.is-button-overlay {
  background-color: $white;
  color: $text-body;

  &:hover,
  &.is-button-hover {
    border-color: transparent;
    background-color: cv('gray', '000');
  }

  &:focus,
  &.is-button-focus {
    background-color: cv('gray', '000');
    box-shadow: 0 0 0 4px cv('action', 'base');
  }

  &:disabled {
    opacity: $more-opaque;
    background-color: $white;
  }
}

.is-button-clear {
  background-color: transparent;
  color: cv('action', 'base');

  &:hover,
  &.is-button-hover {
    border-color: transparent;
    background-color: cv('action', 'lightest');
    color: cv('action', 'dark');
  }

  &:focus,
  &.is-button-focus {
    background-color: cv('action', 'lightest');
    color: cv('action', 'dark');
  }

  &:disabled {
    background-color: transparent;
    color: fauxpacity(cv('action', 'base'));
  }
}

%button-small {
  font-size: ms(-1);
}

.is-button-small {
  @extend %button-small;
}

/* stylelint-disable-next-line no-descending-specificity */
.button,
o-button {
  & + & {
    margin-left: $small-spacing;
  }
}

.top-bar {
  .button {
    @extend %button-small;
  }
}

.card--footer {
  .button {
    @extend %button-small;
  }
}

.form--header {
  .button {
    @extend %button-small;
  }

  .form:not([data-readonly]) & {
    .button {
      display: none;
    }
  }
}
