// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

@include keyframes(fade-in-chart) {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

// New stuff

.#{$grommet-namespace}chart {
  position: relative;
  display: flex;

  .#{$grommet-namespace}chart {
    min-width: 0; // looks odd but needed for flexbox to work right
    max-width: 100%;
  }
}

.#{$grommet-namespace}chart--full {
  width: 100%;
}

.#{$grommet-namespace}chart--vertical {
  flex-direction: column;
}

.#{$grommet-namespace}chart:not(.#{$grommet-namespace}chart--vertical) {
  flex-direction: row;
}

// Base

.#{$grommet-namespace}chart-base {
  display: flex;
}

.#{$grommet-namespace}chart-base--vertical {
  flex-direction: column;
}

.#{$grommet-namespace}chart-base:not(.#{$grommet-namespace}chart-base--vertical) {
  flex-direction: row;

  > * {
    flex: 0 0 auto;
  }
}

.#{$grommet-namespace}chart-base--width-small {
  width: $size-small;
}

.#{$grommet-namespace}chart-base--width-medium {
  width: $size-medium;
}

.#{$grommet-namespace}chart-base--width-large {
  width: $size-large;

  @include media-query(palm) {
    max-width: 100%;
  }
}

.#{$grommet-namespace}chart-base--width-full {
  width: 100%;
}

.#{$grommet-namespace}chart-base--height-xxsmall {
  height: $size-xxsmall;
}

.#{$grommet-namespace}chart-base--height-xsmall {
  height: $size-xsmall;
}

.#{$grommet-namespace}chart-base--height-small {
  height: $size-small;
}

.#{$grommet-namespace}chart-base--height-medium {
  height: $size-medium;

  @include media-query(palm) {
    height: $size-small;
  }
}

.#{$grommet-namespace}chart-base--height-large {
  height: $size-large;

  @include media-query(palm) {
    height: $size-medium;
  }
}

.#{$grommet-namespace}chart-base--height-sparkline {
  height: $sparkline-height;
  width: $sparkline-height * 4;
}

// Axis

.#{$grommet-namespace}chart-axis {
  flex: 0 0 auto; // when in Chart
  display: flex;
  flex-direction: row;
}

.#{$grommet-namespace}chart-axis__slot {
  flex: 0 0;
  display: flex;
  flex-direction: column;
  // to work around Safari repaint issues
  -webkit-transform: translateZ(0);
}

.#{$grommet-namespace}chart-axis--ticks {
  .#{$grommet-namespace}chart-axis__slot {
    &::before,
    &::after {
      background-color: $border-color;
    }

    #{$dark-background-context} {
      &::before,
      &::after {
        background-color: $colored-border-color;
      }
    }

    #{$light-background-context} {
      &::before,
      &::after {
        background-color: $border-color;
      }
    }
  }
}

.#{$grommet-namespace}chart-axis--vertical {
  flex-direction: column-reverse;
  margin-left: halve($inuit-base-spacing-unit);
  margin-right: halve($inuit-base-spacing-unit);

  .#{$grommet-namespace}chart-axis__slot {
    min-width: 1em;
    justify-content: flex-start;

    &:first-child {
      flex-direction: column-reverse;
    }
  }

  &.#{$grommet-namespace}chart-axis--align-start {
    align-items: flex-start;

    .#{$grommet-namespace}chart-axis__slot {
      align-items: flex-start;
    }
  }

  &.#{$grommet-namespace}chart-axis--align-end {
    align-items: flex-end;

    .#{$grommet-namespace}chart-axis__slot {
      align-items: flex-end;
    }
  }

  &.#{$grommet-namespace}chart-axis--ticks {
    .#{$grommet-namespace}chart-axis__slot:not(.#{$grommet-namespace}chart-axis__slot--placeholder) {
      &::before {
        display: block;
        content: "";
        height: 1px;
        width: halve(halve($inuit-base-spacing-unit));
      }
    }

    &.#{$grommet-namespace}chart-axis--ticks--start {
      .#{$grommet-namespace}chart-axis__slot {
        align-items: flex-start;
      }
    }

    &.#{$grommet-namespace}chart-axis--ticks--end {
      .#{$grommet-namespace}chart-axis__slot {
        align-items: flex-end;
      }
    }
  }

  &.#{$grommet-namespace}chart-axis--reverse {
    flex-direction: column;

    .#{$grommet-namespace}chart-axis__slot {
      justify-content: flex-start;
      flex-direction: column-reverse;

      &:first-child {
        flex-direction: column;
        justify-content: flex-start;
      }

      &:last-child {
        justify-content: flex-start;
      }
    }

    &.#{$grommet-namespace}chart-axis--ticks--start {
      .#{$grommet-namespace}chart-axis__slot {
        align-items: flex-start;
      }
    }

    &.#{$grommet-namespace}chart-axis--ticks--end {
      .#{$grommet-namespace}chart-axis__slot {
        align-items: flex-end;
      }
    }
  }
}

.#{$grommet-namespace}chart-axis:not(.#{$grommet-namespace}chart-axis--vertical) {
  flex-direction: row;
  margin-top: halve($inuit-base-spacing-unit);
  margin-bottom: halve($inuit-base-spacing-unit);

  .#{$grommet-namespace}chart-axis__slot {
    min-height: $inuit-base-spacing-unit;
    align-items: flex-start;
    justify-content: flex-end;
    flex-direction: row;

    &:first-child {
      align-items: flex-start;
      flex-direction: row-reverse;
      padding-left: 0;
    }
  }

  &.#{$grommet-namespace}chart-axis--align-start {
    align-items: flex-start;
  }

  &.#{$grommet-namespace}chart-axis--align-end {
    align-items: flex-end;

    .#{$grommet-namespace}chart-axis__slot {
      justify-content: flex-end;
    }
  }

  &.#{$grommet-namespace}chart-axis--ticks {
    .#{$grommet-namespace}chart-axis__slot::after {
      display: block;
      content: "";
      height: halve(halve($inuit-base-spacing-unit));
      width: 1px;
    }

    &.#{$grommet-namespace}chart-axis--ticks--end {
      .#{$grommet-namespace}chart-axis__slot:not(.#{$grommet-namespace}chart-axis__slot--placeholder) {
        align-items: flex-end;
      }
    }

    &.#{$grommet-namespace}chart-axis--ticks--start {
      .#{$grommet-namespace}chart-axis__slot:not(.#{$grommet-namespace}chart-axis__slot--placeholder) {
        align-items: flex-start;
      }
    }

    .#{$grommet-namespace}chart-axis__slot:not(.#{$grommet-namespace}chart-axis__slot--placeholder) {
      > span {
        padding: 0 quarter($inuit-base-spacing-unit);
      }
    }
  }

  &.#{$grommet-namespace}chart-axis--reverse {
    flex-direction: row-reverse;

    .#{$grommet-namespace}chart-axis__slot {
      align-items: flex-start;
    }

    &.#{$grommet-namespace}chart-axis--ticks {
      .#{$grommet-namespace}chart-axis__slot {
        align-items: flex-start;
        justify-content: flex-end;
        flex-direction: row-reverse;

        &:first-child {
          flex-direction: row;
        }
      }
    }
  }
}

// MarkerLabel

.#{$grommet-namespace}chart-marker-label {
  flex: 0 0 auto; // when in Chart
  display: flex;
  flex-direction: row;
}

.#{$grommet-namespace}chart-marker-label__slot {
  flex: 0 0;
  display: flex;
  flex-direction: column;
  // to work around Safari repaint issues
  -webkit-transform: translateZ(0);
}

.#{$grommet-namespace}chart-marker-label--vertical {
  flex-direction: column-reverse;
  // padding-top: round($inuit-base-spacing-unit / 3);
  // padding-bottom: round($inuit-base-spacing-unit / 3);
  margin-left: halve($inuit-base-spacing-unit);
  margin-right: halve($inuit-base-spacing-unit);

  .#{$grommet-namespace}chart-marker-label__slot {
    min-width: 1em;
    justify-content: flex-start;

    &.#{$grommet-namespace}chart-marker-label__slot--flip {
      justify-content: flex-end;
    }
  }

  &.#{$grommet-namespace}chart-marker-label--align-start {
    align-items: flex-start;

    .#{$grommet-namespace}chart-marker-label__slot {
      align-items: flex-start;
    }
  }

  &.#{$grommet-namespace}chart-marker-label--align-end {
    align-items: flex-end;

    .#{$grommet-namespace}chart-marker-label__slot {
      align-items: flex-end;
    }
  }

  &.#{$grommet-namespace}chart-marker-label--reverse {
    flex-direction: column;

    .#{$grommet-namespace}chart-marker-label__slot {
      justify-content: flex-end;

      &.#{$grommet-namespace}chart-marker-label__slot--flip {
        justify-content: flex-start;
      }
    }
  }
}

.#{$grommet-namespace}chart-marker-label:not(.#{$grommet-namespace}chart-marker-label--vertical) {
  flex-direction: row;
  // padding-left: round($inuit-base-spacing-unit / 3);
  // padding-right: round($inuit-base-spacing-unit / 3);
  margin-top: halve($inuit-base-spacing-unit);
  margin-bottom: halve($inuit-base-spacing-unit);

  .#{$grommet-namespace}chart-marker-label__slot {
    min-height: $inuit-base-spacing-unit;
    align-items: flex-end;

    &.#{$grommet-namespace}chart-marker-label__slot--flip {
      align-items: flex-start;
    }
  }

  &.#{$grommet-namespace}chart-marker-label--align-start {
    align-items: flex-start;

    .#{$grommet-namespace}chart-marker-label__slot {
      justify-content: flex-start;
    }
  }

  &.#{$grommet-namespace}chart-marker-label--align-end {
    align-items: flex-end;

    .#{$grommet-namespace}chart-marker-label__slot {
      justify-content: flex-end;
    }
  }
}

// Layers

.#{$grommet-namespace}chart-layers {
  position: absolute;
  @include animation('fade-in-chart 0.5s');
}

@include keyframes(stretch-up-chart) {
  0% {
    max-height: 0;
  }

  100% {
    max-height: 100%;
  }
}

@include keyframes(stretch-right-chart) {
  0% {
    max-width: 0;
  }

  100% {
    max-width: 100%;
  }
}

.#{$grommet-namespace}chart-marker,
.#{$grommet-namespace}chart-grid,
.#{$grommet-namespace}chart-graph--line,
.#{$grommet-namespace}chart-graph--area,
.#{$grommet-namespace}chart-graph--bar,
.#{$grommet-namespace}chart-hot-spots,
.#{$grommet-namespace}chart-range,
.#{$grommet-namespace}chart-loading {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
}

// Loading

.#{$grommet-namespace}chart-loading {
  top: 0;
  stroke-width: $inuit-base-spacing-unit;
  stroke: $unset-color;
  stroke-dasharray: 1 $inuit-base-spacing-unit;
  stroke-dashoffset: 0;
}

// HotSpots

.#{$grommet-namespace}chart-hot-spots {
  display: flex;
  width: 100%;

  > * {
    flex: 0 0;
  }
}

.#{$grommet-namespace}chart-hot-spots--vertical {
  flex-direction: column;
}

.#{$grommet-namespace}chart-hot-spots:not(.#{$grommet-namespace}chart-hot-spots--vertical) {
  flex-direction: row;
}

.#{$grommet-namespace}chart-hot-spots--clickable {
  cursor: pointer;
}

// Range

$range-inactive-background-color: rgba(#fff, 0.5);
$range-inactive-colored-background-color: rgba(#000, 0.4);
$range-control-background-color: rgba(#fff, 0.7);
$range-control-colored-background-color: rgba(#000, 0.5);

.#{$grommet-namespace}chart-range {
  display: flex;
  flex-direction: row;
  cursor: pointer;
}

.#{$grommet-namespace}chart-range__active {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.#{$grommet-namespace}chart-range__inactive {
  background-color: $range-inactive-background-color;

  #{$dark-background-context} {
    background-color: $range-inactive-colored-background-color;
  }

  #{$light-background-context} {
    background-color: $range-inactive-background-color;
  }
}

.#{$grommet-namespace}chart-range__active-start,
.#{$grommet-namespace}chart-range__active-end {
  flex: 0 0 $inuit-base-spacing-unit;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background-color: $range-control-background-color;
  border: 1px solid $border-color;

  #{$dark-background-context} {
    background-color: $range-control-colored-background-color;
    border-color: $colored-border-color;
  }

  #{$light-background-context} {
    background-color: $range-control-background-color;
    border-color: $border-color;
  }

  &:hover {
    background-color: $background-color;
    border-color: $strong-border-color;

    #{$dark-background-context} {
      background-color: $range-control-colored-background-color;
      border-color: $colored-strong-border-color;
    }

    #{$light-background-context} {
      background-color: $background-color;
      border-color: $strong-border-color;
    }
  }

  svg {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
}

.#{$grommet-namespace}chart-range--vertical {
  flex-direction: column;

  .#{$grommet-namespace}chart-range__active {
    flex-direction: column;
  }

  .#{$grommet-namespace}chart-range__active-start,
  .#{$grommet-namespace}chart-range__active-end {
    flex-direction: row;
  }

  svg {
    transform: rotate(90deg);
  }
}

// Grid

.#{$grommet-namespace}chart-grid {
  path {
    stroke: $border-color;

    #{$dark-background-context} {
      stroke: $colored-border-color;
    }

    #{$light-background-context} {
      stroke: $border-color;
    }
  }
}

// Marker

.#{$grommet-namespace}chart-marker {
  stroke: $border-color;
  @include graph-stroke-color-translucent(0.7);
  @include animation('fade-in-chart 1s');

  #{$dark-background-context} {
    @include graph-stroke-color();
  }

  #{$light-background-context} {
    @include graph-stroke-color-translucent(0.7);
  }
}

// Graph

.#{$grommet-namespace}chart-graph--line {
  stroke-width: 3px;
  @include graph-stroke-color-translucent(0.7);
}

.#{$grommet-namespace}chart-graph--bar {
  stroke-width: 4px;
  @include graph-stroke-color-translucent(0.7);

  &.#{$grommet-namespace}chart-graph--vertical {
    @include animation('stretch-right-chart 1.5s');
  }

  &:not(.#{$grommet-namespace}chart-graph--vertical) {
    bottom: 0;
    @include animation('stretch-up-chart 1.5s');
  }
}

.#{$grommet-namespace}chart-graph--area {
  stroke-width: 3px;
  @include graph-fill-color-translucent(0.7);

  &.#{$grommet-namespace}chart-graph--vertical {
    @include animation('stretch-right-chart 1.5s');
  }

  &:not(.#{$grommet-namespace}chart-graph--vertical) {
    bottom: 0;
    @include animation('stretch-up-chart 1.5s');
  }

  .#{$grommet-namespace}chart-graph__point {
    stroke: $background-color;
  }
}

.#{$grommet-namespace}chart-graph__point {
  stroke: none;
  @include graph-fill-color-translucent(0.9);
  // fill: $background-color;
  transition: r $base-animation-duration;
  @include animation('fade-in-chart 0.3s');
}

.#{$grommet-namespace}chart-graph__point--active {
  stroke: $background-color;
  @include graph-fill-color();

  #{$dark-background-context} {
    stroke: $colored-active-background-color;
  }

  #{$light-background-context} {
    stroke: $background-color;
  }
}
