@import "../../themes/ionic.globals";

// Back Button
// --------------------------------------------------

:host {
 /**
   * @prop --background: Background of the button
   * @prop --background-focused: Background of the button when focused with the tab key
   * @prop --background-focused-opacity: Opacity of the button background when focused with the tab key
   * @prop --background-hover: Background of the button on hover
   * @prop --background-hover-opacity: Opacity of the background on hover
   *
   * @prop --color: Text color of the button
   * @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 --min-width: Minimum width of the button
   * @prop --min-height: Minimum height of the button
   *
   * @prop --transition: Transition of the button
   *
   * @prop --border-radius: Border radius of the button
   *
   * @prop --ripple-color: Color of the button ripple effect
   *
   * @prop --opacity: Opacity of the button
   *
   * @prop --margin-top: Top margin of the button
   * @prop --margin-end: Right margin if direction is left-to-right, and left margin if direction is right-to-left of the button
   * @prop --margin-bottom: Bottom margin of the button
   * @prop --margin-start: Left margin if direction is left-to-right, and right margin if direction is right-to-left 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
   *
   * @prop --icon-margin-top: Top margin of the button icon
   * @prop --icon-margin-end: Right margin if direction is left-to-right, and left margin if direction is right-to-left of the button icon
   * @prop --icon-margin-bottom: Bottom margin of the button icon
   * @prop --icon-margin-start: Left margin if direction is left-to-right, and right margin if direction is right-to-left of the button icon
   *
   * @prop --icon-padding-top: Top padding of the button icon
   * @prop --icon-padding-end: Right padding if direction is left-to-right, and left padding if direction is right-to-left of the button icon
   * @prop --icon-padding-bottom: Bottom padding of the button icon
   * @prop --icon-padding-start: Left padding if direction is left-to-right, and right padding if direction is right-to-left of the button icon
   *
   * @prop --icon-font-size: Font size of the button icon
   * @prop --icon-font-weight: Font weight of the button icon
   */
  --background: transparent;
  --color-focused: currentColor;
  --color-hover: currentColor;
  --icon-margin-top: 0;
  --icon-margin-bottom: 0;
  --icon-padding-top: 0;
  --icon-padding-end: 0;
  --icon-padding-bottom: 0;
  --icon-padding-start: 0;
  --margin-top: 0;
  --margin-end: 0;
  --margin-bottom: 0;
  --margin-start: 0;
  --min-width: auto;
  --min-height: auto;
  --padding-top: 0;
  --padding-end: 0;
  --padding-bottom: 0;
  --padding-start: 0;
  --opacity: 1;
  --ripple-color: currentColor;
  --transition: background-color, opacity 100ms linear;

  display: none;

  min-width: var(--min-width);
  min-height: var(--min-height);

  color: var(--color);

  font-family: $font-family-base;

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

  white-space: nowrap;

  user-select: none;
  font-kerning: none;
}


// Back Button with Color
// --------------------------------------------------

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


// Back Button States
// --------------------------------------------------

:host(.show-back-button) {
  display: block;
}

:host(.back-button-disabled) {
  cursor: default;
  opacity: .5;
  pointer-events: none;
}

// Native Back Button
// --------------------------------------------------

.button-native {
  @include border-radius(var(--border-radius));
  @include font-smoothing();
  @include margin(var(--margin-top), var(--margin-end), var(--margin-bottom), var(--margin-start));
  @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%;

  min-height: inherit;

  transition: var(--transition);

  border: 0;

  outline: none;

  background: var(--background);

  line-height: 1;

  cursor: pointer;

  opacity: var(--opacity);

  overflow: hidden;
  user-select: none;
  z-index: 0;
  appearance: none;
}

.button-inner {
  display: flex;
  position: relative;

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

  width: 100%;
  height: 100%;

  z-index: 1;
}


// Back Button Icon
// --------------------------------------------------

ion-icon {
  @include padding(var(--icon-padding-top), var(--icon-padding-end), var(--icon-padding-bottom), var(--icon-padding-start));
  @include margin(var(--icon-margin-top), var(--icon-margin-end), var(--icon-margin-bottom), var(--icon-margin-start));

  display: inherit;

  font-size: var(--icon-font-size);
  font-weight: var(--icon-font-weight);

  pointer-events: none;
}


// Back Button: Focused
// --------------------------------------------------

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

  &::after {
    background: var(--background-focused);

    opacity: var(--background-focused-opacity);
  }
}


// Back Button: Hover
// --------------------------------------------------

.button-native::after {
  @include button-state();
}

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

    &::after {
      background: var(--background-hover);

      opacity: var(--background-hover-opacity);
    }
  }
}


// Back Button Color: Focused
// --------------------------------------------------

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


// Back Button Color: Hover
// --------------------------------------------------

@media (any-hover: hover) {
  :host(.ion-color:hover) .button-native {
    color: #{current-color(base)};
  }
}


// Back Button in Toolbar: Global Theming
// --------------------------------------------------

:host(.in-toolbar:not(.in-toolbar-color)) {
  color: #{var(--ion-toolbar-color, var(--color))};
}