@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:              1.7rem !default;

/// @prop - Font size of the toolbar title
$toolbar-ios-title-font-size:               1.7rem !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 {
  @include padding($toolbar-ios-padding);

  min-height: $toolbar-ios-height;
}


// 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-style: solid;
  border-color: $toolbar-ios-border-color;
}

.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 {
  flex: 1;
  order: map-get($toolbar-order-ios, content);

  min-width: 0;
}

.toolbar-title-ios {
  @include text-align($toolbar-ios-title-text-align);

  font-size: $toolbar-ios-title-font-size;
  font-weight: $toolbar-ios-title-font-weight;
  color: $toolbar-ios-title-text-color;

  pointer-events: auto;
}

.toolbar-ios ion-title {
  @include position(0, null, null, 0);
  @include padding(0, 90px, 1px);

  position: absolute;

  width: 100%;
  height: 100%;

  transform: translateZ(0);

  pointer-events: none;
}

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

    @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 {
  order: map-get($toolbar-order-ios, buttons-start);

  transform: translateZ(0);
}

.bar-buttons-ios[left] {
  order: map-get($toolbar-order-ios, buttons-left);
}

.bar-buttons-ios[end] {
  @include text-align(end);

  order: map-get($toolbar-order-ios, buttons-end);
}

.bar-buttons-ios[right] {
  @include text-align(right);

  order: map-get($toolbar-order-ios, buttons-right);
}


// iOS Toolbar Button Default
// --------------------------------------------------

.bar-button-ios {
  @include padding(0, 4px);
  @include border-radius($toolbar-ios-button-border-radius);

  height: 32px;

  border: 0;
  font-size: $toolbar-ios-button-font-size;
}

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

    &.activated {
      opacity: .4;
    }
  }

}


// iOS Toolbar Button Outline
// --------------------------------------------------

.bar-button-outline-ios {
  border-width: 1px;
  border-style: solid;
  border-color: $toolbar-ios-button-color;
  color: $toolbar-ios-button-color;
  background-color: transparent;

  &:hover:not(.disable-hover) {
    opacity: .4;
  }

  &.activated {
    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} {
    $fg-color: $color-base;
    border-color: $fg-color;
    color: $fg-color;
    background-color: transparent;

    &.activated {
      color: $color-contrast;
      background-color: $fg-color;
    }
  }

}


// 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: .4;
  }

  &.activated {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    background-color: color-shade($toolbar-ios-button-color);
    opacity: .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;

    &.activated {
      color: $color-contrast;
      background-color: color-shade($color-base);
    }
  }

}


// iOS Toolbar Button Icon
// --------------------------------------------------

.bar-button-ios.bar-button-icon-start ion-icon {
  @include padding-horizontal(null, .3em);

  font-size: 1.4em;
  line-height: .67;

  pointer-events: none;
}

.bar-button-ios.bar-button-icon-end ion-icon {
  @include padding-horizontal(.4em, null);

  font-size: 1.4em;
  line-height: .67;

  pointer-events: none;
}

.bar-button-ios[icon-only] {
  @include padding(0);

  min-width: .9em;
}

.bar-button-ios[icon-only] ion-icon {
  @include padding(0, .1em);

  font-size: 1.8em;
  line-height: .67;

  pointer-events: none;
}


// iOS Toolbar Back Button
// --------------------------------------------------

.back-button-ios {
  @include margin(0);

  z-index: 99;
  overflow: visible;

  order: map-get($toolbar-order-ios, back-button);

  min-height: 3.2rem;

  line-height: 1;
  transform: translateZ(0);
}

.back-button-icon-ios {
  @include margin(-1px, 0, 0, 0);

  display: inherit;

  min-width: 18px;

  font-size: 3.4rem;
}

.back-button-text-ios {
  letter-spacing: -.01em;
}


// iOS Toolbar Menu Toggle
// --------------------------------------------------

.bar-button-menutoggle-ios {
  @include margin(0, 6px);
  @include padding(0);

  order: map-get($toolbar-order-ios, menu-toggle-start);

  min-width: 36px;

  ion-icon {
    @include padding(0, 6px);

    font-size: 2.8rem;
  }
}

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