@import "../../../themes/ionic.globals.ios";

// iOS Toolbar
// --------------------------------------------------

/// @prop - Order of the toolbar elements
$toolbar-order-ios: (
  back-button: 0,
  menu-toggle-start: 1,
  buttons-left: 2,
  buttons-start: 3,
  content: 4,
  buttons-end: 5,
  buttons-right: 6,
  menu-toggle-end: 7,
) !default;

/// @prop - Font size of the toolbar button
$toolbar-ios-button-font-size: 17px !default;

/// @prop - Font size of the toolbar title
$toolbar-ios-title-font-size: 17px !default;

/// @prop - Font weight of the toolbar title
$toolbar-ios-title-font-weight: 600 !default;

/// @prop - Text alignment of the toolbar title
$toolbar-ios-title-text-align: center !default;

/// @prop - Text color of the toolbar title
$toolbar-ios-title-text-color: color-contrast($colors-ios, $toolbar-ios-background) !default;

/// @prop - Text color of the toolbar button
$toolbar-ios-button-color: color-contrast($colors-ios, $toolbar-ios-background, ios) !default;

/// @prop - Border radius of the toolbar button
$toolbar-ios-button-border-radius: 4px !default;

/// @prop - Font weight of the strong toolbar button
$toolbar-ios-button-strong-font-weight: 600 !default;

/// @prop - Height of the navigation bar
$navbar-ios-height: $toolbar-ios-height !default;

$toolbar-button-ios-strong-font-weight: 600 !default;

.toolbar-ios {
  min-height: $toolbar-ios-height;
  
  @include padding($toolbar-ios-padding);
  @include safe-area-padding-horizontal($toolbar-ios-padding);
}

// iOS Toolbar Background
// --------------------------------------------------

.toolbar-background-ios {
  background: $toolbar-ios-background;
}

// iOS Header / Footer Borders
// --------------------------------------------------

.header-ios .toolbar-background-ios,
.footer-ios .toolbar-background-ios {
  border-color: $toolbar-ios-border-color;
  border-style: solid;
}

.header-ios .toolbar-ios:last-child .toolbar-background-ios {
  border-width: 0 0 $hairlines-width;
}

.footer-ios .toolbar-ios:first-child .toolbar-background-ios {
  border-width: $hairlines-width 0 0;
}

.header-ios[no-border] .toolbar-ios:last-child .toolbar-background-ios {
  border-bottom-width: 0;
}

.footer-ios[no-border] .toolbar-ios:first-child .toolbar-background-ios {
  border-top-width: 0;
}

// iOS Toolbar Content
// --------------------------------------------------

.toolbar-content-ios {
  min-width: 0;
  flex: 1;
  order: map-get($toolbar-order-ios, content);
}

.toolbar-title-ios {
  font-size: $toolbar-ios-title-font-size;
  font-weight: $toolbar-ios-title-font-weight;
  color: $toolbar-ios-title-text-color;
  pointer-events: auto;
  
  @include text-align($toolbar-ios-title-text-align);
}

.toolbar-ios .ion-title {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: translateZ(0);
  
  @include position(0, null, null, 0);
  @include padding(0, 90px, 1px);
}

@mixin ios-toolbar-theme($color-name, $color-base, $color-contrast) {
  .toolbar-ios-#{$color-name} {
    .toolbar-background-ios {
      background: $color-base;
    }
    
    .toolbar-title-ios,
    .bar-button-clear-ios,
    .bar-button-default-ios {
      color: $color-contrast;
    }
    
    .back-button .button-inner {
      @include arrow-back($color-contrast);
    }
    
    @each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
      @include ios-bar-button-default($color-name, $color-base, $color-contrast);
      @include ios-bar-button-outline($color-name, $color-base, $color-contrast);
      @include ios-bar-button-solid($color-name, $color-base, $color-contrast);
    }
  }
}

// iOS Toolbar Button Placement
// --------------------------------------------------

.bar-buttons-ios {
  transform: translateZ(0);
  order: map-get($toolbar-order-ios, buttons-start);
}

.bar-buttons-ios[left] {
  order: map-get($toolbar-order-ios, buttons-left);
}

.bar-buttons-ios[end] {
  order: map-get($toolbar-order-ios, buttons-end);
  
  @include text-align(end);
}

.bar-buttons-ios[right] {
  order: map-get($toolbar-order-ios, buttons-right);
  
  @include text-align(right);
}

// iOS Toolbar Button Default
// --------------------------------------------------

.bar-button-ios {
  height: 32px;
  font-size: $toolbar-ios-button-font-size;
  border: 0;
  
  @include padding(0, 4px);
  @include border-radius($toolbar-ios-button-border-radius);
}

@mixin ios-bar-button-default($color-name, $color-base, $color-contrast) {
  .bar-button-#{$color-name}-ios,
  .bar-button-default.bar-button-ios-#{$color-name},
  .bar-button-clear-ios-#{$color-name} {
    color: $color-base;
    background-color: transparent;
    
    &:hover:not(.disable-hover) {
      color: $color-base;
    }
    
    &:active {
      opacity: 0.4;
    }
    
    &.back-button {
      @include arrow-back($color-base);
    }
  }
}

// iOS Toolbar Button Outline
// --------------------------------------------------

.bar-button-outline-ios {
  color: $toolbar-ios-button-color;
  background-color: transparent;
  border-color: $toolbar-ios-button-color;
  border-style: solid;
  border-width: 1px;
  
  &:hover:not(.disable-hover) {
    opacity: 0.4;
  }
  
  &:active {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    background-color: $toolbar-ios-button-color;
  }
}

@mixin ios-bar-button-outline($color-name, $color-base, $color-contrast) {
  .bar-button-outline-ios-#{$color-name} {
    color: $color-base;
    background-color: transparent;
    border-color: $color-base;
    
    &:active {
      color: $color-contrast;
      background-color: $color-base;
    }
  }
  
}

// iOS Toolbar Button Solid
// --------------------------------------------------

.bar-button-solid-ios {
  color: color-contrast($colors-ios, $toolbar-ios-button-color);
  background-color: $toolbar-ios-button-color;
  
  &:hover:not(.disable-hover) {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    opacity: 0.4;
  }
  
  &:active {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    background-color: color-shade($toolbar-ios-button-color);
    opacity: 0.4;
  }
}

@mixin ios-bar-button-solid($color-name, $color-base, $color-contrast) {
  .bar-button-solid-ios-#{$color-name} {
    color: $color-contrast;
    background-color: $color-base;
    
    &:active {
      color: $color-contrast;
      background-color: color-shade($color-base);
    }
  }
  
}

// iOS Toolbar Button Icon
// --------------------------------------------------

.bar-button-ios.bar-button-icon-start .ion-icon {
  font-size: 1.4em;
  line-height: 0.67;
  pointer-events: none;
  
  @include padding-horizontal(null, 0.3em);
}

.bar-button-ios.bar-button-icon-end .ion-icon {
  font-size: 1.4em;
  line-height: 0.67;
  pointer-events: none;
  
  @include padding-horizontal(0.4em, null);
}

.bar-button-ios[icon-only] {
  min-width: 0.9em;
  
  @include padding(0);
}

.bar-button-ios[icon-only] .ion-icon {
  font-size: 1.8em;
  line-height: 0.67;
  pointer-events: none;
  
  @include padding(0, 0.1em);
}

// iOS Toolbar Back Button
// --------------------------------------------------

.back-button-ios {
  z-index: 99;
  min-height: 32px;
  overflow: visible;
  line-height: 1;
  transform: translateZ(0);
  order: map-get($toolbar-order-ios, back-button);
  
  @include margin(0);
}

.back-button-icon-ios {
  display: inherit;
  min-width: 18px;
  font-size: 17px;
  
  @include margin(-1px, 0, 0, 0);
}

.back-button-text-ios {
  letter-spacing: -0.01em;
}

// iOS Toolbar Menu Toggle
// --------------------------------------------------

.bar-button-menutoggle-ios {
  min-width: 36px;
  order: map-get($toolbar-order-ios, menu-toggle-start);
  
  @include margin(0, 6px);
  @include padding(0);
  
  .ion-icon {
    font-size: 28px;
    
    @include padding(0, 6px);
  }
}

.bar-button-menutoggle-ios[end],
.bar-button-menutoggle-ios[right] {
  order: map-get($toolbar-order-ios, menu-toggle-end);
}

// iOS Toolbar Color Generation
// --------------------------------------------------

@include ios-bar-button-default(default, $toolbar-ios-button-color, color-contrast($colors-ios, $toolbar-ios-button-color, ios));
@include ios-bar-button-default(clear, $toolbar-ios-button-color, color-contrast($colors-ios, $toolbar-ios-button-color, ios));

@each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
  @include ios-toolbar-theme($color-name, $color-base, $color-contrast);
  @include ios-bar-button-default($color-name, $color-base, $color-contrast);
  @include ios-bar-button-outline($color-name, $color-base, $color-contrast);
  @include ios-bar-button-solid($color-name, $color-base, $color-contrast);
}

// iOS strong Button
// --------------------------------------------------

.bar-button-strong-ios {
  font-weight: $toolbar-ios-button-strong-font-weight;
}
