@import "../../globals.wp";
@import "./toolbar";
@import "./toolbar-button";

// Windows Toolbar
// --------------------------------------------------

$toolbar-order-wp: (
  back-button: 0,
  menu-toggle-start: 1,
  buttons-left: 2,
  content: 3,
  buttons-start: 4,
  buttons-end: 5,
  buttons-right: 6,
  menu-toggle-end: 7,
);

$toolbar-wp-padding:                     4px !default;
$toolbar-wp-height:                      4.6rem !default;
$toolbar-wp-title-padding:               0 6px !default;
$toolbar-wp-title-font-size:             1.5rem !default;
$toolbar-wp-title-font-weight:           bold !default;
$toolbar-wp-title-text-transform:        uppercase !default;
$toolbar-wp-title-text-color:            color-contrast($colors-wp, $toolbar-wp-background, wp) !default;

$toolbar-wp-button-font-size:            1.4rem !default;
$toolbar-wp-button-color:                color-contrast($colors-wp, $toolbar-wp-background, wp) !default;
$toolbar-wp-button-border-radius:        2px !default;

$navbar-wp-height:                       $toolbar-wp-height !default;


.toolbar {
  padding: $toolbar-wp-padding;

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

ion-navbar-section {
  min-height: $navbar-wp-height;
}


// Windows Toolbar Background
// --------------------------------------------------

.toolbar-background {
  border-color: $toolbar-wp-border-color;
  background: $toolbar-wp-background;
}


// Windows Toolbar Content
// --------------------------------------------------

.toolbar-content {
  flex: 1;
  order: map-get($toolbar-order-wp, content);

  min-width: 0;
  max-width: 100%;
}

.toolbar-title {
  padding: $toolbar-wp-title-padding;

  font-size: $toolbar-wp-title-font-size;
  font-weight: $toolbar-wp-title-font-weight;
  text-transform: $toolbar-wp-title-text-transform;
  color: $toolbar-wp-title-text-color;
}

@mixin wp-toolbar-theme($color-name, $color-base, $color-contrast) {
  .toolbar[#{$color-name}] {
    $fg-color: $color-contrast;

    .toolbar-background {
      background: $color-base;
    }

    .bar-button-default,
    .bar-button-outline,
    .toolbar-title {
      color: $fg-color;
    }

    .bar-button-default,
    .bar-button-outline {
      ion-button-effect {
        background-color: $fg-color;
      }
    }

    .bar-button-outline {
      border-color: $fg-color;
    }

    @each $color-name, $color-base, $color-contrast in get-colors($colors-wp) {
      @include wp-bar-button-default($color-name, $color-base, $color-contrast);
      @include wp-bar-button-outline($color-name, $color-base, $color-contrast);
      @include wp-bar-button-solid($color-name, $color-base, $color-contrast);
    }
  }
}


// Windows Toolbar Button Placement
// --------------------------------------------------

ion-buttons {
  order: map-get($toolbar-order-wp, buttons-start);

  transform: translateZ(0);
}

ion-buttons[left] {
  order: map-get($toolbar-order-wp, buttons-left);
}

ion-buttons[left] .bar-button:first-child {
  margin-left: 0;
}

ion-buttons[end] {
  order: map-get($toolbar-order-wp, buttons-end);

  text-align: right;
}

ion-buttons[right] {
  order: map-get($toolbar-order-wp, buttons-right);

  text-align: right;
}


// Windows Toolbar Button Default
// --------------------------------------------------

.bar-button {
  margin-top: 0;
  margin-right: .2rem;
  margin-bottom: 0;
  margin-left: .2rem;
  padding: 0 5px;

  height: 32px;

  border: 0;
  border-radius: $toolbar-wp-button-border-radius;
  font-size: $toolbar-wp-button-font-size;
  font-weight: 500;
  text-transform: uppercase;
}

.bar-button-solid,
.bar-button-outline {
  // restrict the ripple to button size
  overflow: hidden;
}

@mixin wp-bar-button-default($color-name, $color-base, $color-contrast) {

  .bar-button-#{$color-name} {
    color: $color-base;
    background-color: transparent;

    &:hover:not(.disable-hover) {
      color: $color-base;
    }
  }

}


// Windows Toolbar Button Outline
// --------------------------------------------------

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

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

  &.activated {
    color: color-contrast($colors-wp, $toolbar-wp-button-color, wp);
    background-color: $toolbar-wp-button-color;
  }
}

@mixin wp-bar-button-outline($color-name, $color-base, $color-contrast) {

  .bar-button-outline-#{$color-name} {
    $fg-color: color-shade($color-base);
    border-color: $fg-color;
    color: $fg-color;
    background-color: transparent;

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

}


// Windows Toolbar Button Solid
// --------------------------------------------------

.bar-button-solid {
  color: color-contrast($colors-wp, $toolbar-wp-button-color, wp);
  background-color: $toolbar-wp-button-color;

  &:hover:not(.disable-hover) {
    color: color-contrast($colors-wp, $toolbar-wp-button-color, wp);
  }

  &.activated {
    color: color-contrast($colors-wp, $toolbar-wp-button-color, wp);
    background-color: color-shade($toolbar-wp-button-color);
  }
}

@mixin wp-bar-button-solid($color-name, $color-base, $color-contrast) {

  .bar-button-solid-#{$color-name} {
    color: $color-contrast;
    background-color: $color-base;

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

}


// Windows Toolbar Button Icon
// --------------------------------------------------

.bar-button-icon-left ion-icon {
  padding-right: .3em;

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

  pointer-events: none;
}

.bar-button-icon-right ion-icon {
  padding-left: .4em;

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

  pointer-events: none;
}

.bar-button-icon-only {
  padding: 0;

  ion-icon {
    padding: 0 .1em;

    min-width: 28px;

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

    pointer-events: none;
  }
}


// Windows Toolbar Back Button
// --------------------------------------------------

.back-button {
  margin: 0 6px;

  min-width: 44px;

  box-shadow: none;
}

.back-button-icon {
  margin: 0;
  padding: 0 6px;

  font-size: 2.4rem;
  font-weight: normal;
  text-align: left;
}


// Windows Toolbar Menu Toggle
// --------------------------------------------------

.bar-button-menutoggle {
  order: map-get($toolbar-order-wp, menu-toggle-start);

  margin: 0 6px;
  padding: 0 2px;

  min-width: 44px;

  ion-icon {
    padding: 0 6px;

    font-size: 2.4rem;
  }
}

.bar-button-menutoggle[end],
.bar-button-menutoggle[right] {
  order: map-get($toolbar-order-wp, menu-toggle-end);

  margin: 0 2px;

  min-width: 28px;
}


// Windows Toolbar Color Generation
// --------------------------------------------------

@include wp-bar-button-default(default, $toolbar-wp-button-color, color-contrast($colors-wp, $toolbar-wp-button-color, wp));

@each $color-name, $color-base, $color-contrast in get-colors($colors-wp) {
  @include wp-toolbar-theme($color-name, $color-base, $color-contrast);
  @include wp-bar-button-default($color-name, $color-base, $color-contrast);
  @include wp-bar-button-outline($color-name, $color-base, $color-contrast);
  @include wp-bar-button-solid($color-name, $color-base, $color-contrast);
}
