/*
Bootstrap (5) integration for btn-deluxe by hnldesign - https://www.hnldesign.nl
v 3.1.0
fixes: improved BS integration
 */

@import "btn-deluxe-v3";
@import "../css/bootstrap/5.1.3/scss/functions";
@import "../css/bootstrap/5.1.3/scss/variables";
$gradient-shade-sat-factor: 1;
$gradient-shade-bri-factor: 1.15;

// map bootstrap theme colors to btn-deluxe variables
@each $color, $value in $theme-colors {
  .btn-#{$color}.btn-deluxe, .btn-outline-#{$color}.btn-deluxe {
    --but-deluxe-txt: #{color-contrast($value)};
    --but-deluxe-hue: #{hue($value)};
    --but-deluxe-sat: #{saturation($value)};
    --but-deluxe-bri: #{lightness($value)};

    --but-deluxe-alt-hue: #{hue($value)};
    --but-deluxe-alt-sat: #{(saturation($value) * $gradient-shade-sat-factor)};
    --but-deluxe-alt-bri: #{(lightness($value) * $gradient-shade-bri-factor)};

    &:not([class*="btn-outline-"]):active,
    &:not([class*="btn-outline-"]).active,
    &:not([class*="btn-outline-"]):focus,
    &:not([class*="btn-outline-"]):hover {
      $active-background: if(color-contrast($value) == $color-contrast-light, shade-color($value, $btn-active-bg-shade-amount), tint-color($value, $btn-active-bg-tint-amount));

      --but-deluxe-txt: #{color-contrast($active-background)};
      --but-deluxe-hue: #{hue($active-background)};
      --but-deluxe-sat: #{saturation($active-background)};
      --but-deluxe-bri: #{lightness($active-background)};

      --but-deluxe-alt-hue: #{hue($active-background)};
      --but-deluxe-alt-sat: #{(saturation($active-background) * $gradient-shade-sat-factor)};
      --but-deluxe-alt-bri: #{(lightness($active-background) * $gradient-shade-bri-factor)};
    }

  }
}

.btn.btn-deluxe {
  color: $body-color;
  --btn-deluxe-round: #{$btn-border-radius};
  --but-deluxe-shade-angle: 5deg;
  > span {
    /* restore span visibility */
    display: inline-block;
  }
  & > .btn-deluxe-front {
    padding : $btn-padding-y $btn-padding-x;
  }
  &.btn-lg > .btn-deluxe-front {
    padding : $btn-padding-y-lg $btn-padding-x-lg;
  }
  &.btn-sm > .btn-deluxe-front {
    padding : $btn-padding-y-sm $btn-padding-x-sm;
  }
}

.btn-group {
  > .btn-deluxe:not(:last-child):not(.dropdown-toggle) > .btn-deluxe-front,
  > .btn-deluxe:not(:last-child):not(.dropdown-toggle) > .btn-deluxe-edge,
  > .btn-group:not(:last-child) > .btn-deluxe > .btn-deluxe-front,
  > .btn-group:not(:last-child) > .btn-deluxe > .btn-deluxe-edge {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  > .btn-deluxe:nth-child(n + 3) > .btn-deluxe-front,
  > .btn-deluxe:nth-child(n + 3) > .btn-deluxe-edge,
  > :not(.btn-check) + .btn-deluxe > .btn-deluxe-front,
  > :not(.btn-check) + .btn-deluxe > .btn-deluxe-edge,
  > .btn-group:not(:first-child) > .btn-deluxe > .btn-deluxe-front,
  > .btn-group:not(:first-child) > .btn-deluxe > .btn-deluxe-edge {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  > .btn-deluxe:not(:last-child):not(.dropdown-toggle) > .btn-deluxe-edge,
  > .btn-group:not(:last-child) > .btn-deluxe > .btn-deluxe-edge {
    background: linear-gradient(
                    to left,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 1.5)) 0%,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 1.5)) 92%,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 2)) 100%
    );
  }

  > .btn-deluxe:not(:first-child):not(:last-child) > .btn-deluxe-edge {
    background: hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 1.5));
  }

  > .btn-deluxe:nth-child(n+3) > .btn-deluxe-edge,
  > :not(.btn-check) + .btn-deluxe > .btn-deluxe-edge,
  > .btn-group:not(:first-child) > .btn-deluxe > .btn-deluxe-edge {
    background: linear-gradient(
                    to left,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 2)) 0%,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 1.5)) 8%,
                    hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) calc(var(--but-deluxe-bri, 47%) / 1.5)) 100%
    );
  }

}

.btn-group-vertical {
  // Reset rounded corners
  > .btn-deluxe:not(:last-child):not(.dropdown-toggle) > .btn-deluxe-front,
  > .btn-deluxe:not(:last-child):not(.dropdown-toggle) > .btn-deluxe-edge,
  > .btn-group:not(:last-child) > .btn-deluxe > .btn-deluxe-front,
  > .btn-group:not(:last-child) > .btn-deluxe > .btn-deluxe-edge {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
  }

  > .btn-deluxe ~ .btn-deluxe > .btn-deluxe-front,
  > .btn-deluxe ~ .btn-deluxe > .btn-deluxe-edge,
  > .btn-group:not(:first-child) > .btn-deluxe > .btn-deluxe-front,
  > .btn-group:not(:first-child) > .btn-deluxe > .btn-deluxe-edge {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  > .btn-deluxe {
    margin-bottom: 0;
    z-index: 1;
  }
  > .btn-deluxe ~ .btn-deluxe {
    margin-top: calc(0px - (#{$btn-deluxe-hover} + var(--btn-deluxe-up)));
  }
}


.btn.btn-deluxe {
  //outlined buttons
  &[class*="btn-outline-"] > .btn-deluxe-front {
    background: transparent;
    background-image: none;
    transition: transform var(--btn-deluxe-trans-duration), background-color .15s ease-in-out, color .15s ease-in-out;
    border: 1px solid hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) var(--but-deluxe-bri, 47%));
    color: hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) var(--but-deluxe-bri, 47%));
  }
  &[class*="btn-outline-"] > .btn-deluxe-edge {
    background: hsl(var(--but-deluxe-hue, 216deg) 0% 100% / 0%) !important;
    border: 1px solid hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) var(--but-deluxe-bri, 47%));
    border-top: 0 none;
    margin-top: 0;
    max-height: 50%;
    position: absolute;
    top: 50%;
    //border-radius: var(--btn-deluxe-round, 10px);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
  &[class*="btn-outline-"]:hover > .btn-deluxe-front,
  &[class*="btn-outline-"].active > .btn-deluxe-front {
    color: var(--but-deluxe-txt, white);
    transition: transform var(--btn-deluxe-trans-duration), background-color .15s ease-in-out, color .15s ease-in-out;
    background-color: hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) var(--but-deluxe-bri, 47%));
  }
  /* states */
  @media all and (hover: hover) {
    &[class*="btn-outline-"]:hover > .btn-deluxe-front {
      transition: transform var(--btn-deluxe-trans-duration), background-color .15s ease-in-out, color .15s ease-in-out;
    }
  }
  @media not all and (hover:hover) {
    &[class*="btn-outline-"]:hover > .btn-deluxe-front {
      color: var(--but-deluxe-txt, white);
      background: hsl(var(--but-deluxe-hue, 216deg) var(--but-deluxe-sat, 100%) var(--but-deluxe-bri, 47%));
    }
  }
}
