@use "../../../scss/shared";
@use "../../wc";

:host {
  display: inline-block;
  position: relative;
  width: auto;
  cursor: pointer;
  user-select: none;

  button, a {
    width: 100%;
  }
}

.button {
  @include shared.button;

  --btn-color: var(--zn-primary);
  --notification-color: rgb(var(--zn-color-error));

  border-width: 1px;
  border-color: transparent;
  height: 100%;
  display: inline-flex;
  position: relative;

  &.button--info {
    --btn-color: var(--zn-color-info);
  }

  &.button--error {
    --btn-color: var(--zn-color-error);
  }

  &.button--warning {
    --btn-color: var(--zn-color-warning);
  }

  &.button--success {
    --btn-color: var(--zn-color-success);
  }

  &__label--hidden {
    visibility: hidden;
  }
}

.button.button--muted-notification {
  --notification-color: rgb(var(--zn-color-info));
}

.button--has-notification {
  position: relative;

  &::after {
    content: attr(data-notification);
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    top: 0;
    inset-inline-end: 0;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    font-size: 10px;
    color: white;
    background-color: var(--notification-color);
  }
}

.button--has-notification.button--notification-dot {
  &:after {
    content: '';
    width: 5px;
    height: 5px;
    top: 5px;
    right: 3px;
  }
}

.button::-moz-focus-inner {
  border: 0;
}

.button:focus {
  outline: none;
}

.button:focus-visible {
  outline: 2px solid rgb(var(--btn-color));
  outline-offset: 2px;
}

[disabled] {
  cursor: not-allowed;
  opacity: 0.5;

  * {
    pointer-events: none;
  }
}

.button--standard {
  &.button--secondary {
    background-color: var(--zn-color-neutral-50);
    border-color: var(--zn-color-neutral-50);
    color: rgb(var(--zn-primary));

    &:hover:not([disabled]) {
      background-color: var(--zn-color-neutral-100)
    }

    &:active:not([disabled]) {
      background-color: var(--zn-color-neutral-100)
    }
  }


  background-color: rgba(var(--btn-color), .85);
  border-color: rgb(var(--btn-color));
  color: rgba(255, 255, 255, 0.9);

  &:hover:not([disabled]) {
    background-color: rgba(var(--btn-color), 0.8);
  }

  &:active:not([disabled]) {
    background-color: rgba(var(--btn-color));
  }
}

.button--outline {
  background: none;
  border-width: 1px;
  border-color: rgb(var(--btn-color));
  color: rgb(var(--btn-color));

  &:hover:not([disabled]), &:active:not([disabled]) {
    background-color: rgb(var(--btn-color));
    color: white;
  }

  &.button--secondary {
    border-color: #F3EFFF;

    &:hover:not([disabled]), &:active:not([disabled]) {
      background-color: rgb(221, 218, 236);
    }
  }
}


.button--text {
  background: none;
  color: rgb(var(--btn-color));

  &:hover:not([disabled]), &:active:not([disabled]) {
    background-color: rgba(var(--btn-color), 0.1);
  }

  &.button--secondary {
    font-weight: normal;
  }
}

.button--x-small {
  padding: 2px 10px;
  font-size: 12px;
}

.button--content {
  padding: 0 0;
  font-size: 12px;

  zn-icon {
    line-height: 0;
  }
}

.button--grow {
  width: 100%;
}

.button--small {
  padding: 4px 14px;
}

.button--large {
  padding: 10px 20px;
}

.button--with-icon:not(.button--with-content) {
  &.button--x-small,
  &.button--small {
    padding: 4px;
  }

  &.button--medium {
    padding: 7px;
  }

  &.button--large {
    padding: 10px;
    font-size: 16px;
  }
}

.button--with-icon.button--with-content {
  &.button--x-small,
  &.button--small {
    padding-left: 10px;

    &.button--icon-left {
      padding-left: 10px;

      zn-icon {
        margin-right: 4px;
      }
    }

    &.button--icon-right {
      padding-right: 10px;

      zn-icon {
        margin-left: 4px;
      }
    }
  }

  &.button--medium {
    &.button--icon-left {
      padding-left: 10px;

      zn-icon {
        margin-right: 6px;
      }
    }

    &.button--icon-right {
      padding-right: 10px;

      zn-icon {
        margin-left: 6px;
      }
    }
  }

  &.button--large {
    &.button--icon-left {
      padding-left: 14px;

      zn-icon {
        margin-right: 8px;
      }
    }

    &.button--icon-right {
      padding-right: 14px;

      zn-icon {
        margin-left: 8px;
      }
    }
  }
}

.button--square {
  border-radius: 0;
}

.button--transparent {
  background-color: transparent;
  border-color: transparent !important;
  color: inherit;

  &:hover:not([disabled]) {
    background-color: rgba(var(--zn-primary), 0.1);
  }

  &:active:not([disabled]) {
    background-color: rgba(var(--zn-primary), 0.2);
  }
}

.button--star {
  --btn-color: var(--zn-orange);
  background-color: rgb(var(--btn-color));
  border-color: rgb(var(--btn-color));
  color: white;
  opacity: 1 !important;

  &:hover:not([disabled]) {
    background-color: rgb(var(--btn-color));
  }

  &:active {
    background-color: rgb(var(--btn-color));
  }

  &.button--outline {
    background-color: transparent;
    border-color: rgb(var(--btn-color));
    color: rgb(var(--btn-color));

    &:hover:not([disabled]), &:active:not([disabled]) {
      background-color: rgba(var(--btn-color));
      color: white;
    }
  }
}

.button--loading-bg {
  &-transparent {
    background-color: transparent;
  }
}

.button--loading {
  &-fill {
    pointer-events: none;
    position: absolute;
    z-index: 1;
    background-color: rgba(var(--btn-color), .85);
    border-radius: inherit;
    transition: width 0s;
    animation: loading-fill-grow var(--loading-duration, 2s) linear forwards;
    inset: -1px;

    &-transparent {
      background-color: rgba(var(--zn-primary), 0.1);
    }
  }

  &-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }

  &-text {
    z-index: 5;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    font-weight: inherit;
    user-select: none;
    position: absolute;
    pointer-events: none;
    color: inherit;

    .loading-countdown {
      margin-left: 3px;
    }

    &-left {
      justify-content: flex-start;
      padding-inline-start: 7px;
    }

    &-right {
      justify-content: flex-end;
      padding-inline-end: 7px;
    }
  }
}

.button--relative-wrapper {
  position: relative;
  display: inline-flex;
  height: 100%;
  width: 100%;
}

@keyframes loading-fill-grow {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

:host([vertical-align="center"]) {
  align-self: center;
}

:host([vertical-align="end"]) {
  align-self: end;
}

:host([vertical-align="start"]) {
  align-self: start;
}

:host([grow]) {
  width: 100%;

  button {
    width: 100%;
  }
}

:host([data-zn-button-group__button--grow]) {
  flex-grow: 1;
  flex-basis: 0;
}

:host([data-zn-button-group__button--inner]) .button {
  border-radius: 0 !important;
  border-left: 0 !important;
  border-right: 0 !important;
}

:host([data-zn-button-group__button]:not([data-zn-button-group__button--first]):not(:hover)) {
  .button:after {
    content: '';
    position: absolute;
    top: 0;
    inset-inline-start: 0;
    bottom: 0;
    border-left: solid 1px;
    mix-blend-mode: multiply;
    color: rgb(var(--zn-border-color));
  }
}

:host([data-zn-button-group__button--first]:not([data-zn-button-group__button--last])) .button {
  border-radius: 5px 0 0 5px !important;
  border-right: 0 !important;
}

:host([data-zn-button-group__button--last]:not([data-zn-button-group__button--first])) .button {
  border-radius: 0 5px 5px 0 !important;
  border-left: 0 !important;
}
