//
// @file
// Stable paragraphs widget CSS.
//

@use "sass:map";
@use "variables" as *;
@use "summary";

.paragraphs {
  // Paragraphs state information icons.
  &-icon {
    display: inline-block;
    width: $info-size;
    height: $info-size;
    vertical-align: middle;
    background: no-repeat center;
    background-size: $info-icon-size $info-icon-size;
    @each $icon in (view edit-info edit-disabled delete delete-disabled lock changed collapse warning error) {
      &-#{$icon} {
        background-image: url('../icons/icon-#{$icon}.svg');
      }
    }
  }
}

// Paragraphs button icon support for small screens.
@media (max-width: map.get($grid-breakpoints, 'md')) {
  .button.paragraphs-icon-button {
    width: $action-size-big !important;
    height: $action-size-big;
    padding: 0;
    text-indent: -9999em;
    border-radius: $action-border-radius;
    background-repeat: no-repeat !important;
    // We need important flag here to easily override many specific rules from
    // seven buttons.css.
    background-position: center !important;
    background-size: $action-icon-size $action-icon-size;
    @each $icon in (collapse edit) {
      &-#{$icon},
      &-#{$icon}:active,
      &-#{$icon}:hover,
      &-#{$icon}:focus {
        background-image: url('../icons/icon-#{$icon}.svg');
      }

      &-#{$icon}:disabled,
      &-#{$icon}:disabled:active {
        background-image: url('../icons/icon-#{$icon}-disabled.svg');
      }
    }
  }
}


.paragraphs-tabs-wrapper {
  .paragraphs-tabs-hide {
    display: none;
  }
}

.paragraph-bullet {
  text-align: center;
  &::after {
    padding: 0 10px;
    content: "\25cf";
    color: #777;
    font-size: 0.75em;
    line-height: 3.5em;
  }
}

@media (min-width: map.get($grid-breakpoints, 'md')) {
  .paragraph-bullet {
    &::after {
      line-height: 2.5em;
    }
  }
}

// We are using .js prefix here mainly because we want to apply this style rules
// only for JS version of a widget.
.js {
  .field--widget-paragraphs {
    .paragraphs-nested .tabledrag-toggle-weight-wrapper {
      display: none;
    }
    th .paragraphs-actions {
      float: right;
      // Table th padding is 12px but for some weird reason here we need to do
      // -11px to return it back.
      margin-right: -11px;
    }

    // Fix alignment of field-actions / form-actions.
    .form-actions,
    .field-actions {
      align-items: center;

      // Fix alignment to content.
      .dropbutton-multiple {
        margin-right: .5rem;
      }

      // Add spacing to "to" keyword
      .placeholder {
        margin-left: .25em;
      }
    }

    .paragraphs-dropbutton-wrapper {
      // We are using inline-flex here so 'Add type' dropdown button is inline
      // and aligned 'to type' text.
      display: inline-flex;
      // Remove margins and paddings that come from Claro theme.
      margin: 0;
      padding: 0;

      .dropbutton-multiple {
        margin: 0 .5rem 0 0;
      }
    }

    .dropbutton-wrapper {
      // Override 600px breakpoint from core, needed again so 'to type' is in
      // the same line with add dropdown button.
      width: auto;

      // Reset some CSS that are coming from core.
      margin-right: 0;
      padding-right: 0;
    }

    .field-multiple-table {
      margin-bottom: 10px;
    }

    td { // stylelint-disable-line selector-no-type
      padding: 10px 0;
    }

    .field-multiple-drag {
      min-width: 40px;
      vertical-align: middle;
    }

    .draggable .tabledrag-handle {
      width: 23px;
      margin-top: 3px;
      margin-left: 0;
      padding-right: .25em;
      vertical-align: baseline;

      // Fix active focus.
      &:focus {
        &::before {
          margin-right: .1em;
          margin-left: .1em;
        }
      }

      // Claro theme fix for the handle icon position.
      &::after {
        margin-top: 0.9375rem;
        margin-left: 0;
        padding: .5rem;
      }

      // Scale the icon on hover.
      &:hover .handle {
        transform: scale(1.25);
      }
    }

    .tabledrag-changed {
      text-decoration: none;
    }

    .tabledrag-handle .handle {
      height: 22px;
      margin-right: 0;
      margin-left: 0;
    }

    .delta-order {
      padding-right: 10px;
      text-align: right;
    }
  }

  .paragraph-top {
    display: grid;
    grid-template-rows: auto auto;
    grid-template-columns: 100px auto 1fr auto;
    grid-gap: 0 $gutter-top;
    align-items: baseline;

    .paragraph-type {
      grid-row: 1 / span 1;
      grid-column: 1 / 2;
    }

    .paragraph-info {
      grid-row: 1 / span 1;
      grid-column: 2 / 3;
    }

    .paragraph-summary {
      overflow: hidden;
      grid-row: 2 / span 1;
      grid-column: 1 / 5;
      white-space: nowrap;

      @media (min-width: map.get($grid-breakpoints, 'sm')) {
        grid-row: 1 / span 2;
        grid-column: 3 / 4;
      }
    }

    .paragraphs-actions {
      grid-row: 1 / span 1;
      grid-column: 3 / 5;
      justify-self: end;

      @media (min-width: map.get($grid-breakpoints, 'sm')) {
        grid-column: 4 / 5;
      }
    }

    @media (min-width: map.get($grid-breakpoints, 'lg')) {
      grid-template-columns: 150px auto 1fr auto;
    }
  }

  .paragraphs-subform {
    margin-top: 5px;
  }

  .paragraphs-description {
    @at-root .draggable:hover .paragraphs-description {
      &::after {
        background: linear-gradient(to right, rgba(247, 252, 255, 0) 0%, #f7fcff 100%);
      }
    }

    @at-root .drag-previous .paragraphs-description {
      &::after {
        background: linear-gradient(to right, rgba(255, 255, 221, 0) 0%, #ffd 100%);
      }
    }

    @at-root tr:hover .paragraphs-description {
      &::after {
        background: linear-gradient(to right, rgba(255, 255, 221, 0) 0%, #f7fcff 100%);
      }
    }
  }

  .paragraph-type {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    &-title {
      display: flex;
      flex-basis: 100px;
      min-width: 100px;
    }

    &-icon {
      width: $info-icon-size;
      height: $info-icon-size;
      padding-right: $gutter-top;
      vertical-align: middle;
    }

    &-label {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }

  .paragraph-type-add-modal-button {
    display: inline-block;
  }

  .paragraph-type-add-modal-button:hover {
    color: #fff;
    background: #057ec7 none;
  }

  .paragraphs-convert-button {
    margin-left: 0;
  }

  @media (min-width: map.get($grid-breakpoints, 'sm')) {
    .paragraph-type-add-modal {
      display: inline-block;
    }
  }
}

.paragraphs-dragdrop__item {
  .paragraphs-summary-wrapper {
    .paragraphs-description {
      .paragraphs-content-wrapper,
      .paragraphs-plugin-wrapper {
        font-size: 81.3%;
      }
    }
  }
}

.paragraph--view-mode--preview {
  padding-right: 1em;
}

.is-horizontal .paragraphs-tabs .tabs__tab {
  border-bottom: 0;
}

// Requires JavaScript to avoid flickering on pageload.
.paragraphs-behavior {
  display: none;
}

.first-paragraph {
  transition: background-color .3s linear;
}

.paragraph-hover {
  background-color: $paragraph-hover-bg;
}

@media (min-width: map.get($grid-breakpoints, 'md')) {
  // Basic node form sticky paragraph tabs implementation.
  .is-horizontal .paragraphs-tabs:first-of-type {
    position: sticky;
    // Toolbar bar minimum z-index is 501 so we need to be lower, other way
    // our sticky tabs will be on top of toolbar menu.
    z-index: 500;
    top: 0;
    margin-top: 0;
    padding-top: 5px !important;
    background-color: rgba(255, 255, 255, 0.9);
  }

  .toolbar-fixed .is-horizontal .paragraphs-tabs:first-of-type {
    top: 39px;
  }

  .toolbar-fixed.toolbar-horizontal.toolbar-tray-open .is-horizontal .paragraphs-tabs:first-of-type {
    top: 79px;
  }
}
