@import "./fab-button.vars";

// Floating Action Buttons
// --------------------------------------------------

:host {
  /**
   * @prop --background: Background of the button
   * @prop --background-activated: Background of the button when pressed
   * @prop --background-focused: Background of the button when focused with the tab key
   * @prop --background-hover: Background of the button on hover
   *
   * @prop --color: Text color of the button
   * @prop --color-activated: Text color of the button when pressed
   * @prop --color-focused: Text color of the button when focused with the tab key
   * @prop --color-hover: Text color of the button on hover
   *
   * @prop --transition: Transition of the button
   *
   * @prop --border-radius: Border radius of the button
   * @prop --border-width: Border width of the button
   * @prop --border-style: Border style of the button
   * @prop --border-color: Border color of the button
   *
   * @prop --ripple-color: Color of the button ripple effect
   *
   * @prop --box-shadow: Box shadow of the button
   *
   * @prop --padding-top: Top padding of the button
   * @prop --padding-end: Right padding if direction is left-to-right, and left padding if direction is right-to-left of the button
   * @prop --padding-bottom: Bottom padding of the button
   * @prop --padding-start: Left padding if direction is left-to-right, and right padding if direction is right-to-left of the button
   */
  --color-hover: #{var(--color)};
  --background-hover: #{ion-color(primary, tint)};
  --transition: background-color, opacity 100ms linear;
  --ripple-color: currentColor;
  --border-radius: #{$fab-border-radius};
  --border-width: 0;
  --border-style: none;
  --border-color: initial;
  --padding-top: 0;
  --padding-end: 0;
  --padding-bottom: 0;
  --padding-start: 0;

  @include margin(0);
  display: block;

  width: #{$fab-size};
  height: #{$fab-size};

  font-size: 14px;

  text-align: center;
  text-overflow: ellipsis;
  text-transform: none;

  white-space: nowrap;
  font-kerning: none;
}


.button-native {
  @include border-radius(var(--border-radius));
  @include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
  @include text-inherit();

  display: block;
  position: relative;

  width: 100%;
  height: 100%;

  transform: var(--transform);

  transition: var(--transition);

  border-width: var(--border-width);
  border-style: var(--border-style);
  border-color: var(--border-color);

  outline: none;

  background: var(--background);

  background-clip: padding-box;
  color: var(--color);

  box-shadow: var(--box-shadow);
  contain: strict;
  cursor: pointer;
  overflow: hidden;
  z-index: 0;
  appearance: none;

  box-sizing: border-box;
}

::slotted(ion-icon) {
  line-height: 1;
}

.button-inner {
  @include position(0, 0, null, 0);

  display: flex;
  position: absolute;

  flex-flow: row nowrap;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;

  height: 100%;

  transition: all ease-in-out 300ms;
  transition-property: transform, opacity;
}


// FAB Button: Color
// --------------------------------------------------

:host(.ion-color) .button-native {
  background: #{current-color(base)};
  color: #{current-color(contrast)};
}


// FAB Button: Disabled
// --------------------------------------------------

:host(.fab-button-disabled) {
  opacity: .5;

  pointer-events: none;
}

:host(.fab-button-disabled) .button-native {
  cursor: default;
  pointer-events: none;
}


// FAB Button: Hover
// --------------------------------------------------

@media (any-hover: hover) {
  :host(:hover) .button-native {
    background: var(--background-hover);
    color: var(--color-hover);
  }

  :host(.ion-color:hover) .button-native {
    background: #{current-color(tint)};
    color: #{current-color(contrast)};
  }
}

// FAB Button: Focused
// --------------------------------------------------

:host(.ion-focused) .button-native {
  background: var(--background-focused);
  color: var(--color-focused);
}

:host(.ion-color.ion-focused) .button-native {
  background: #{current-color(shade)};
}

// FAB Button: Activated
// --------------------------------------------------

:host(.activated) .button-native {
  background: var(--background-activated);
  color: var(--color-activated);
}

// Focused/Activated Button with Color
:host(.ion-color.ion-focused) .button-native,
:host(.ion-color.activated) .button-native {
  background: #{current-color(shade)};
  color: #{current-color(contrast)};
}


// FAB Content
// --------------------------------------------------

::slotted(ion-icon) {
  line-height: 1;
}


// FAB small (mini
// --------------------------------------------------

:host(.fab-button-small) {
  @include margin(($fab-size - $fab-small-size) / 2);

  width: #{$fab-small-size};
  height: #{$fab-small-size};
}

// FAB Close Icon
// --------------------------------------------------

.close-icon {
  @include position(0, 0, null, 0);

  display: flex;
  position: absolute;

  align-items: center;
  justify-content: center;

  height: 100%;

  transform: scale(.4) rotateZ(-45deg);

  transition: all ease-in-out 300ms;
  transition-property: transform, opacity;

  opacity: 0;
}

// FAB Animation
// --------------------------------------------------

:host(.fab-button-close-active) .close-icon {
  transform: scale(1) rotateZ(0deg);

  opacity: 1;
}

:host(.fab-button-close-active) .button-inner {
  transform: scale(.4) rotateZ(45deg);

  opacity: 0;
}

ion-ripple-effect {
  color: var(--ripple-color);
}

// Translucent FAB button
// --------------------------------------------------

@supports (backdrop-filter: blur(0)) {
  :host(.fab-button-translucent) .button-native {
    backdrop-filter: var(--backdrop-filter);
  }
}