@import "../../themes/mixins";

// Segment Button: Common
// --------------------------------------------------

:host {
  /**
   * @prop --background: Background of the segment button
   * @prop --background-checked: Background of the checked segment button
   *
   * @prop --color: Color of the segment button
   * @prop --color-checked: Color of the checked segment button
   *
   * @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
   */

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

  display: flex;

  position: relative;

  flex-direction: column;

  height: auto;

  background: var(--background);

  color: var(--color);

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

  white-space: nowrap;

  cursor: pointer;

  grid-row: 1;

  font-kerning: none;
}

.button-native {
  @include border-radius(0);
  @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-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 Icon
// --------------------------------------------------

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

  order: -1;

  pointer-events: none;
}

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

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

  align-self: center;

  max-width: 100%;

  text-overflow: ellipsis;

  white-space: nowrap;

  overflow: hidden;

  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: 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);

  background: var(--indicator-color);

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