// studio - views - course outline
// ====================

// view-specific utilities
// --------------------
%outline-item-header {
  @include clearfix();
  line-height: 0;

  // CASE: is-editable
  // TODO: abstract out
  .is-editable {

    .incontext-editor-value, .incontext-editor-action-wrapper {
      vertical-align: top;
    }

    .incontext-editor-open-action {
      @include transition(opacity $tmg-f1 ease-in-out 0);
      opacity: 0.0;
    }

    .incontext-editor-form {
      width: 100%;
      position: relative;
      top: -($baseline/4);
    }

    // TOOD: abstract this out into a Sass placeholder
    .incontext-editor-input {
      @include transition(box-shadow $tmg-f1 ease-in-out 0, color $tmg-f1 ease-in-out 0);
      width: 100%;
      background: none repeat scroll 0 0 $white;
      border: 0;
      box-shadow: 0 0 2px 2px $shadow inset;

      // STATE: focus
      &:focus {
        box-shadow: 0 0 2px 2px rgba($ui-action-primary-color-focus, 0.50) inset;
        color: $ui-action-primary-color-focus;
      }
    }

    // STATE: hover/focus
    &:hover, &:focus {

      .incontext-editor-open-action {
        opacity: 1.0;
      }
    }
  }
}

%outline-item-content-hidden {
  display: none;
}

%outline-item-content-shown {
  display: block;
}

.view-outline {

  // page structure
  // --------------------
  .content-primary,
  .content-supplementary {
    @include box-sizing(border-box);
    float: left;
  }

  .content-primary {
    width: flex-grid(9, 12);
    margin-right: flex-gutter();

    .no-content {
      @extend %no-content;
    }
  }

  .content-supplementary {
    width: flex-grid(3, 12);
  }


  // page header
  // --------------------
  .button-toggle-expand-collapse {

    // STATE: action will collapse all
    &.collapse-all {

      .expand-all {
        display: none;
      }

      .collapse-all {
        display: block;
      }
    }

    // STATE: action will expand all
    &.expand-all {

      .collapse-all {
        display: none;
      }

      .expand-all {
        display: block;
      }
    }
  }

  // adding outline elements
  // --------------------

  // forms
  .new-section-name,
  .new-subsection-name-input {
    @extend %t-copy-base;
    display: inline-block;
    width: 515px;
    padding: ($baseline/4);
    vertical-align: top;
  }

  .new-subsection-name-input {
    @extend %t-copy-sub1;
  }
  .new-section-name-save,
  .new-subsection-name-save {
    @include blue-button();
    margin: 0 5px;
    padding: 4px 20px 7px;
    color: $white;
  }

  .new-section-name-cancel,
  .new-subsection-name-cancel {
    @include white-button();
    padding: 4px 20px 7px;
    color: $gray-l1;
  }

  // buttons
  .new-subsection-item,
  .new-unit-item {
    @extend %ui-btn-flat-outline;
    width: 100%;
    margin: 0 0 ($baseline/2) 0;
    border: 1px solid $gray-l3;
    padding: ($baseline/2) 0;
    color: $gray-l2;


    &:hover {
      box-shadow: none;
      background-image: none;
    }
  }

  .courseware-unit-new {
    margin-right: ($baseline*1.5);
  }


  // UI: general action list styles (section and subsection)
  // --------------------
  .expand-collapse {
    @extend %expand-collapse;
  }

  // outline
  // --------------------
  .outline {

    .outline-content {
      margin-top: 0;
    }

    // add/new items
    .add-item {
      margin-top: ($baseline*0.75);

      .button-new {
        @extend %ui-btn-flat-outline;
        padding: ($baseline/2) $baseline;
        display: block;

        .icon {
          display: inline-block;
          vertical-align: middle;
          margin-right: ($baseline/2);
        }
      }
    }

    .add-section {
      margin-bottom: $baseline;
    }

    .add-subsection {

    }

    .add-unit {
      margin-left: $outline-indent-width;
    }
  }

  // outline: items
  .outline-item {

    // CASE: expand/collapse-able
    &.is-collapsible {

      // only select the current item's toggle expansion controls
      &:nth-child(1) .ui-toggle-expansion, &:nth-child(1) .item-title {

        // STATE: hover/active
        &:hover, &:active {
          color: $blue;
        }
      }

      &.is-dragging {
        @include transition-property(none);
      }
    }

    // item: title
    .item-title {

      // STATE: is-editable
      &.is-editable {

        // editor
        + .editor {
          display: block;

          .item-edit-title {
            width: 100%;
          }
        }
      }
    }

    // STATE: drag and drop
    .drop-target-prepend .draggable-drop-indicator-initial {
      opacity: 1.0;
    }

    // STATE: was dropped
    &.was-dropped {
      border-color: $blue;
    }
  }

  // outline: sections
  // --------------------
  .outline-section {
    padding: ($baseline*0.75) $baseline ($baseline*0.75) ($baseline + 4);

    // header
    .section-header {
      @extend %outline-item-header;

      .incontext-editor-input {
        @extend %t-strong;
        @extend %t-title5;
      }
    }

    .section-header-details {
      float: left;
      width: flex-grid(6, 9);

      .icon, .wrapper-section-title {
        display: inline-block;
        vertical-align: top;
      }

      .icon {
        margin-right: ($baseline/4);
      }

      .wrapper-section-title {
        width: flex-grid(5, 6);
        line-height: 0;
      }
    }

    .section-header-actions {
      float: right;
      width: flex-grid(3, 9);
      margin-top: -($baseline/4);
      text-align: right;

      .actions-list {
        @extend %actions-list;
        @extend %t-action2;
      }
    }

    // status
    .section-status {
      margin: 0 0 0 ($outline-indent-width*1.25);
    }

    // content
    .section-content {
      @extend %outline-item-content-shown;
    }

    // CASE: is-collapsible
    &.is-collapsible {
      @extend %ui-expand-collapse;

      .ui-toggle-expansion {
        @extend %t-icon3;
        color: $gray-l3;
      }
    }

    // STATE: is-collapsed
    &.is-collapsed {

      .section-content {
        @extend %outline-item-content-hidden;
      }
    }

    // STATE: drag and drop - was dropped
    &.was-dropped {
      border-left-color: $ui-action-primary-color-focus;
    }
  }

  // outline: subsections
  // --------------------
  .list-subsections {
    margin: $baseline 0 0 0;
  }

  .outline-subsection {
    padding: ($baseline*0.75);

    // header
    .subsection-header {
      @extend %outline-item-header;

      .incontext-editor-input {
        @extend %t-title6;
      }
    }

    .subsection-header-details {
      float: left;
      width: flex-grid(6, 9);

      .icon, .wrapper-subsection-title {
        display: inline-block;
        vertical-align: top;
      }

      .icon {
        margin-right: ($baseline/4);
      }

      .wrapper-subsection-title {
        width: flex-grid(5, 6);
        margin-top: -($baseline/10);
        line-height: 0;
      }
    }

    .subsection-header-actions {
      float: right;
      width: flex-grid(3, 9);
      margin-top: -($baseline/4);
      text-align: right;

      .actions-list {
        @extend %actions-list;
        @extend %t-action2;
        margin-right: ($baseline/2);
      }
    }

    // status
    .subsection-status {
      margin: 0 0 0 $outline-indent-width;
    }

    // content
    .subsection-content {
      @extend %outline-item-content-shown;
    }

    // CASE: is-collapsible
    &.is-collapsible {
      @extend %ui-expand-collapse;

      .ui-toggle-expansion {
        @extend %t-icon4;
        color: $gray-l3;
      }
    }

    // STATE: is-collapsed
    &.is-collapsed {

      .subsection-content {
        @extend %outline-item-content-hidden;
      }
    }
  }

  // outline: units
  // --------------------
  .list-units {
    margin: $baseline 0 0 0;
  }

  .outline-unit {
    @include transition(margin $tmg-f2 linear 0s); // needed for drag and drop transitions
    margin-left: $outline-indent-width;

    // header
    .unit-header {
      @extend %outline-item-header;
    }

    .unit-header-details {
      float: left;
      width: flex-grid(6, 9);
      margin-top: ($baseline/4);
    }

    .unit-header-actions {
      float: right;
      width: flex-grid(3, 9);
      margin-top: -($baseline/10);
      text-align: right;

      .actions-list {
        @extend %actions-list;
        @extend %t-action2;
      }
    }
  }


  // UI: drag and drop: section
  // --------------------
  .outline-section {

    .ui-splint-indicator {
      height: ($baseline/10);
      margin-left: ($baseline/4);
    }

    .draggable-drop-indicator-before {
      top: -($baseline*0.75);
      left: 0;
    }

    .draggable-drop-indicator-after {
      bottom: -($baseline*0.75);
      left: 0;
    }
  }

  // UI: drag and drop: subsection
  .outline-subsection {

    .ui-splint-indicator {
      height: ($baseline/10);
      margin-left: ($baseline*1.25);
    }

    .draggable-drop-indicator-before {
      top: -($baseline*0.75);
    }

    .draggable-drop-indicator-after {
      bottom: -($baseline*0.75);
    }
  }

  // // UI: drag and drop: unit
  .outline-unit {

    .draggable-drop-indicator-before {
      top: -($baseline*0.75);
    }

    .draggable-drop-indicator-after {
      bottom: -($baseline*0.75);
    }
  }

  // UI: drag and drop: splints
  .ui-splint-indicator {
    position: relative;

    .draggable-drop-indicator {
      @extend %ui-depth3;
      @include transition(opacity $tmg-f2 linear 0s);
      @include size(100%, auto);
      position: absolute;
      border-top: 1px solid $blue-l1;
      opacity: 0.0;

      *[class^="icon-caret"] {
        @extend %t-icon5;
        position: absolute;
        top: -12px;
        left: -($baseline/4);
        color: $blue-s1;
      }
    }

    .draggable-drop-indicator-before {
      top: -($baseline/2);
    }

    .draggable-drop-indicator-after {
      bottom: -($baseline/2);
    }
  }
}
