//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

//-----------------------------
// Tiles
//-----------------------------

@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/css--reset';

/// Tile styles
/// @access private
/// @group tile
@mixin tile {
  .#{$prefix}--tile {
    position: relative;
    display: block;
    min-width: 8rem;
    min-height: 4rem;
    padding: $carbon--spacing-05;
    background-color: $ui-01;
    outline: 2px solid transparent;
    outline-offset: -2px;

    &:focus {
      @include focus-outline('outline');
    }
  }

  .#{$prefix}--tile--light {
    background-color: $ui-02;
  }

  .#{$prefix}--tile--clickable,
  .#{$prefix}--tile--selectable,
  .#{$prefix}--tile--expandable {
    cursor: pointer;
    transition: $duration--moderate-01 motion(standard, productive);

    &:hover {
      background: $hover-ui;
    }
  }

  .#{$prefix}--tile--clickable,
  .#{$prefix}--tile--expandable {
    &:focus {
      @include focus-outline('outline');
    }

    &:hover,
    &:focus {
      .#{$prefix}--tile__checkmark {
        opacity: 1;
      }
    }
  }

  // Removes Firefox automatic border on buttons
  .#{$prefix}--tile--expandable::-moz-focus-inner {
    border: 0;
  }

  .#{$prefix}--tile--clickable {
    @include reset;
    @include type-style('body-short-01');

    color: $text-01;
    text-decoration: none;
  }

  .#{$prefix}--tile--selectable {
    padding-right: $carbon--spacing-09;
  }

  .#{$prefix}--tile__checkmark,
  .#{$prefix}--tile__chevron {
    position: absolute;
    background: transparent;
    border: none;
    transition: $duration--fast-02 motion(standard, productive);
  }

  .#{$prefix}--tile__checkmark {
    top: 1rem;
    right: 1rem;
    height: 1rem;
    opacity: 0;

    svg {
      border-radius: 50%;
      fill: $icon-02;
    }

    &:focus {
      @include focus-outline('outline');
    }
  }

  .#{$prefix}--tile__chevron {
    position: absolute;
    right: 0.5rem;
    bottom: 0.5rem;
    height: 1rem;

    svg {
      transform-origin: center;
      transition: $duration--fast-02 motion(standard, productive);
      fill: $ui-05;
    }

    &:hover {
      cursor: pointer;
    }

    &:focus {
      outline: none;
    }
  }

  .#{$prefix}--tile--expandable {
    width: 100%;
    overflow: hidden;
    color: inherit;
    font-size: inherit;
    text-align: left;
    border: 0;
    transition: max-height $duration--moderate-01 motion(standard, productive);
  }

  .#{$prefix}--tile-content__above-the-fold {
    display: block;
  }

  .#{$prefix}--tile-content__below-the-fold {
    display: block;
    visibility: hidden;
    opacity: 0;
    transition: opacity $duration--fast-02 motion(standard, productive),
      visibility $duration--fast-02 motion(standard, productive);
  }

  .#{$prefix}--tile--is-expanded {
    overflow: visible;
    transition: max-height $duration--fast-02 motion(standard, productive);

    .#{$prefix}--tile__chevron svg {
      transform: rotate(-180deg);
    }

    .#{$prefix}--tile-content__below-the-fold {
      visibility: inherit;
      opacity: 1;
      transition: opacity $duration--fast-02 motion(standard, productive),
        visibility $duration--fast-02 motion(standard, productive);
    }
  }

  .#{$prefix}--tile--is-selected {
    outline: 1px solid $ui-05;
    outline-offset: -1px;
  }

  .#{$prefix}--tile--is-selected .#{$prefix}--tile__checkmark {
    opacity: 1;
  }

  .#{$prefix}--tile-input:checked
    + .#{$prefix}--tile
    > .#{$prefix}--tile__checkmark
    svg {
    fill: $ui-05;
  }

  .#{$prefix}--tile-content {
    width: 100%;
    height: 100%;
  }

  .#{$prefix}--tile-input {
    @include hidden;
  }

  .#{$prefix}--tile-input:focus + .#{$prefix}--tile {
    @include focus-outline('outline');
  }
}

@include exports('tile') {
  @include tile;
}
