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

// Segment Button
// --------------------------------------------------

:host {
  /**
   * @prop --background: Background of the segment button
   * @prop --background-checked: Background of the checked segment button
   *
   * @prop --background-hover: Background of the segment button on hover
   * @prop --background-focused: Background of the segment button when focused with the tab key
   *
   * @prop --background-hover-opacity: Opacity of the segment button background on hover
   * @prop --background-focused-opacity: Opacity of the segment button background when focused with the tab key
   *
   * @prop --color: Color of the segment button
   * @prop --color-checked: Color of the checked segment button
   * @prop --color-hover: Color of the segment button on hover
   * @prop --color-focused: Color of the segment button when focused with the tab key
   *
   * @prop --border-radius: Radius of the segment button border
   * @prop --border-color: Color of the segment button border
   * @prop --border-style: Style of the segment button border
   * @prop --border-width: Width of the segment button border
   *
   * @prop --margin-top: Top margin of the segment button
   * @prop --margin-end: Right margin if direction is left-to-right, and left margin if direction is right-to-left of the segment button
   * @prop --margin-bottom: Bottom margin of the segment button
   * @prop --margin-start: Left margin if direction is left-to-right, and right margin if direction is right-to-left of the segment button
   *
   * @prop --padding-top: Top padding of the segment button
   * @prop --padding-end: Right padding if direction is left-to-right, and left padding if direction is right-to-left of the segment button
   * @prop --padding-bottom: Bottom padding of the segment button
   * @prop --padding-start: Left padding if direction is left-to-right, and right padding if direction is right-to-left of the segment button
   *
   * @prop --transition: Transition of the segment button
   *
   * @prop --indicator-height: Height of the indicator for the checked segment button
   * @prop --indicator-box-shadow: Box shadow on the indicator for the checked segment button
   * @prop --indicator-color: Color of the indicator for the checked segment button
   * @prop --indicator-transition: Transition of the indicator for the checked segment button
   * @prop --indicator-transform: Transform of the indicator for the checked segment button
   */
  --color: initial;
  --color-hover: var(--color);
  --color-checked: var(--color);
  --color-disabled: var(--color);
  --padding-start: 0;
  --padding-end: 0;
  --padding-top: 0;
  --padding-bottom: 0;

  @include border-radius(var(--border-radius));

  display: flex;

  position: relative;

  flex: 1 1 auto;
  flex-direction: column;

  height: auto;

  background: var(--background);

  color: var(--color);

  text-decoration: none;
  text-overflow: ellipsis;

  white-space: nowrap;

  font-kerning: none;

  cursor: pointer;
}

.button-native {
  @include border-radius(0);
  @include text-inherit();
  @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 transform(translate3d(0,0,0));

  display: flex;
  position: relative;

  flex-direction: inherit;

  flex-grow: 1;
  align-items: center;
  justify-content: center;

  width: 100%;
  min-width: inherit;
  max-width: inherit;

  height: auto;
  min-height: inherit;
  max-height: inherit;

  transition: var(--transition);

  border: none;

  outline: none;

  background: transparent;

  contain: content;
  pointer-events: none;

  overflow: hidden;

  z-index: 2;
}

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

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

  flex-flow: inherit;
  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;

  z-index: 1;
}


// Segment Button: Checked
// --------------------------------------------------

:host(.segment-button-checked) {
  background: var(--background-checked);
  color: var(--color-checked);
}


// Segment Button: Disabled
// --------------------------------------------------

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


// Segment Button: Focused
// --------------------------------------------------

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

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

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

// Segment Button: Hover
// --------------------------------------------------

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

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

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

  :host(.segment-button-checked:hover) .button-native {
    color: var(--color-checked);
  }
}


// Segment Button Icon
// --------------------------------------------------

::slotted(ion-icon) {
  flex-shrink: 0;

  order: -1;

  pointer-events: none;
}


// Segment Button Label
// --------------------------------------------------

::slotted(ion-label) {
  display: block;

  align-self: center;

  line-height: 22px;

  text-overflow: ellipsis;

  white-space: nowrap;

  box-sizing: border-box;

  pointer-events: none;
}


// Segment Button Layout
// --------------------------------------------------

// Layout: icon top
:host(.segment-button-layout-icon-top) .button-native {
  flex-direction: column;
}

// Layout: icon start
:host(.segment-button-layout-icon-start) .button-native {
  flex-direction: row;
}

// Layout: icon end
:host(.segment-button-layout-icon-end) .button-native {
  flex-direction: row-reverse;
}

// Layout: icon bottom
:host(.segment-button-layout-icon-bottom) .button-native {
  flex-direction: column-reverse;
}

// Layout: icon hide
:host(.segment-button-layout-icon-hide) ::slotted(ion-icon) {
  display: none;
}

// Layout: label hide
:host(.segment-button-layout-label-hide) ::slotted(ion-label) {
  display: none;
}

// Segment Button Ripple
// --------------------------------------------------

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

// Segment Button: Indicator
// --------------------------------------------------

.segment-button-indicator {
  @include transform-origin(left);

  position: absolute;

  opacity: 0;

  box-sizing: border-box;

  will-change: transform, opacity;

  pointer-events: none;
}

.segment-button-indicator-background {
  width: 100%;
  height: var(--indicator-height);

  transform: var(--indicator-transform);

  box-shadow: var(--indicator-box-shadow);

  pointer-events: none;
}

.segment-button-indicator-animated {
  transition: var(--indicator-transition);
}

:host(.segment-button-checked) .segment-button-indicator {
  opacity: 1;
}


// Segment: Reduced Motion
// --------------------------------------------------

@media (prefers-reduced-motion: reduce) {
  .segment-button-indicator-background {
    transform: none;
  }

  .segment-button-indicator-animated {
    transition: none;
  }
}