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

// Material Design Toolbar
// --------------------------------------------------

$toolbar-order-md: (
  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-md-padding:                     4px !default;
$toolbar-md-height:                      5.6rem !default;
$toolbar-md-title-font-size:             2rem !default;
$toolbar-md-title-text-color:            color-contrast($colors-md, $toolbar-md-background, md) !default;

$toolbar-md-button-font-size:            1.4rem !default;

$toolbar-md-button-color:                $toolbar-md-title-text-color !default;
$toolbar-md-button-border-radius:        2px !default;

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


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

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

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


// Material Design Toolbar Background
// --------------------------------------------------

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


// Material Design Toolbar Content
// --------------------------------------------------

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

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

.toolbar-title {
  padding: 0 12px;

  font-size: $toolbar-md-title-font-size;
  font-weight: 500;
  color: $toolbar-md-title-text-color;
}

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

    .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-md) {
      @include md-bar-button-default($color-name, $color-base, $color-contrast);
      @include md-bar-button-outline($color-name, $color-base, $color-contrast);
      @include md-bar-button-solid($color-name, $color-base, $color-contrast);
    }
  }
}


// Material Design Toolbar Button Placement
// --------------------------------------------------

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

  transform: translateZ(0);
}

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

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

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

  text-align: right;
}

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

  text-align: right;
}


// Material Design 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-md-button-border-radius;
  font-size: $toolbar-md-button-font-size;
  font-weight: 500;
  text-transform: uppercase;
}

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

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

}


// Material Design Toolbar Button Outline
// --------------------------------------------------

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

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

  &.activated {
    background-color: transparent;
  }

  ion-button-effect {
    background-color: $toolbar-md-button-color;
  }
}

@mixin md-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 {
      background-color: transparent;
    }

    ion-button-effect {
      background-color: $fg-color;
    }
  }

}


// Material Design Toolbar Button Solid
// --------------------------------------------------

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

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

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

@mixin md-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);
    }
  }

}


// Material Design 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;
  }
}


// Material Design 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;
}


// Material Design Toolbar Menu Toggle
// --------------------------------------------------

.bar-button-menutoggle {
  order: map-get($toolbar-order-md, 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-md, menu-toggle-end);

  margin: 0 2px;

  min-width: 28px;
}


// Material Design Toolbar Color Generation
// --------------------------------------------------

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

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