@import "../../../themes/ionic.globals.ios";

// iOS Segment
// --------------------------------------------------

/// @prop - Background of the segment button
$segment-button-ios-background-color: transparent !default;

/// @prop - Background of the activated segment button
$segment-button-ios-background-color-activated: $toolbar-ios-active-color !default;

/// @prop - Text color of the segment button
$segment-button-ios-text-color: color-contrast($colors-ios, $segment-button-ios-background-color-activated) !default;

/// @prop - Transition of the activated segment button
$segment-button-ios-transition-activated: 100ms all linear !default;

/// @prop - Transition of the segment button on hover
$segment-button-ios-transition-hover: 100ms all linear !default;

/// @prop - Transition of the segment button when pressed
$segment-button-ios-transition-active: 100ms all linear !default;

/// @prop - Opacity of the segment button on hover
$segment-button-ios-opacity-hover: 0.1 !default;

/// @prop - Opacity of the segment button when pressed
$segment-button-ios-opacity-active: 0.16 !default;

/// @prop - Opacity of the activated segment button
$segment-button-ios-opacity-activated: 1 !default;

/// @prop - Opacity of the disabled segment button
$segment-button-ios-opacity-disabled: 0.3 !default;

/// @prop - Border width of the segment button
$segment-button-ios-border-width: 1px !default;

/// @prop - Height of the segment button
$segment-button-ios-height: 32px !default;

/// @prop - Line height of the segment button
$segment-button-ios-line-height: 30px !default;

/// @prop - Font size of the segment button
$segment-button-ios-font-size: 13px !default;

/// @prop - Border radius of the segment button
$segment-button-ios-border-radius: 4px !default;

/// @prop - Size of an icon in the segment button
$segment-button-ios-icon-size: 26px !default;

/// @prop - Line height of an icon in the segment button
$segment-button-ios-icon-line-height: 28px !default;

/// @prop - Max width of the segment button in a toolbar
$segment-button-ios-toolbar-button-max-width: 100px !default;

/// @prop - Height of the segment button in a toolbar
$segment-button-ios-toolbar-button-height: 26px !default;

/// @prop - Line height of the segment button in a toolbar
$segment-button-ios-toolbar-line-height: 25px !default;

/// @prop - Font size of the segment button in a toolbar
$segment-button-ios-toolbar-font-size: 12px !default;

/// @prop - Size of an icon in the segment button in a toolbar
$segment-button-ios-toolbar-icon-size: 22px !default;

/// @prop - Line height of an icon in the segment button in a toolbar
$segment-button-ios-toolbar-icon-line-height: 24px !default;

.segment-ios .segment-button {
  width: 0;
  height: $segment-button-ios-height;
  font-size: $segment-button-ios-font-size;
  line-height: $segment-button-ios-line-height;
  color: $segment-button-ios-background-color-activated;
  background-color: $segment-button-ios-background-color;
  border-color: $segment-button-ios-background-color-activated;
  border-style: solid;
  border-width: $segment-button-ios-border-width;
  flex: 1;
  
  .ion-icon {
    font-size: $segment-button-ios-icon-size;
    line-height: $segment-button-ios-icon-line-height;
  }
  
  &.segment-activated {
    color: $segment-button-ios-text-color;
    background-color: $segment-button-ios-background-color-activated;
    opacity: $segment-button-ios-opacity-activated;
    transition: $segment-button-ios-transition-activated;
  }
  
  &:hover:not(.segment-activated) {
    background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-hover);
    transition: $segment-button-ios-transition-hover;
  }
  
  &:active:not(.segment-activated) {
    background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-active);
    transition: $segment-button-ios-transition-active;
  }
  
  &:first-of-type {
    @include border-radius($segment-button-ios-border-radius, 0, 0, $segment-button-ios-border-radius);
    @include margin-horizontal(null, 0);
  }
  
  &:not(:first-of-type) {
    border-left-width: 0;
  }
  
  &:last-of-type {
    border-left-width: 0;
    
    @include border-radius(0, $segment-button-ios-border-radius, $segment-button-ios-border-radius, 0);
    @include margin-horizontal(0, null);
  }
}

[dir="rtl"] .segment-ios .segment-button {
  &:first-of-type {
    border-left-width: 0;
  }
  
  &:last-of-type {
    border-left-width: $segment-button-ios-border-width;
  }
}

.segment-ios.segment-disabled {
  pointer-events: none;
  opacity: 0.4;
}

.segment-ios .segment-button-disabled {
  color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-disabled);
  pointer-events: none;
}

// iOS Segment in Toolbar
// --------------------------------------------------

.toolbar-ios .segment-ios {
  position: absolute;
  
  @include position(0, 0, 0, 0);
}

.toolbar-ios .segment-button {
  max-width: $segment-button-ios-toolbar-button-max-width;
  height: $segment-button-ios-toolbar-button-height;
  font-size: $segment-button-ios-toolbar-font-size;
  line-height: $segment-button-ios-toolbar-line-height;
  
  .ion-icon {
    font-size: $segment-button-ios-toolbar-icon-size;
    line-height: $segment-button-ios-toolbar-icon-line-height;
  }
}

// iOS Segment Button Mixin
// --------------------------------------------------

@mixin ios-segment-button($color-name, $color-base, $color-contrast) {
  .segment-ios-#{$color-name} {
    .segment-button {
      color: $color-base;
      border-color: $color-base;
      
      &:hover:not(.segment-activated) {
        background-color: rgba($color-base, $segment-button-ios-opacity-hover);
      }
      
      &:active:not(.segment-activated) {
        background-color: rgba($color-base, $segment-button-ios-opacity-active);
      }
      
      &.segment-activated {
        color: $color-contrast;
        background-color: $color-base;
      }
    }
    
    .segment-button-disabled {
      color: rgba($color-base, $segment-button-ios-opacity-disabled);
    }
    
  }
  
}

// iOS Segment Color Generation
// --------------------------------------------------

@each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
  @include ios-segment-button($color-name, $color-base, $color-contrast);
  
  .toolbar-ios-#{$color-name} .segment-ios .segment-button.segment-activated {
    color: $color-base;
  }
}
