@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-disabled: Background of the disabled segment button
   * @prop --background-hover: Background of the segment button on hover
   *
   * @prop --color: Color of the segment button
   * @prop --color-checked: Color of the checked segment button
   * @prop --color-disabled: Color of the disabled segment button
   * @prop --color-hover: Color of the segment button on hover
   *
   * @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-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: initial;
  --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;
}

.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;
  cursor: pointer;

  z-index: 2;
}


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

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


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

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


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

@media (any-hover: hover) {
  :host(:hover) {
    background: var(--background-hover);
    color: var(--color-hover, var(--color));
  }

  :host(.segment-button-checked:hover) {
    color: var(--color-hover, 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;
}

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

  transform: var(--indicator-transform);

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

.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;
  }
}