/* ==========================================================================
   Uploader
   ========================================================================== */

/**
 * A single and multi file uploader
 */

@import "../../../../kodekit-ui/src/scss/admin/core/tools";
@import "koowa/progressbar";

/* Variables
   ========================================================================== */

$k-upload-height: 60px !default;
$k-upload-radius: 3px !default;
$k-upload-border-color: #ccc !default;
$k-upload-max-height: 200px !default;
$k-upload-progressbar-height: 3px !default;
$k-upload-transition-fast: all .2s ease-in-out !default;
$k-upload-transition-slow: all .4s ease-in-out !default;
$k-upload-querie: 600px !default;
$k-upload-list-button-mobile-size: 18px !default;
$k-upload-list-button-desktop-size: 23px !default;



/* The parent container
   ========================================================================== */

/**
 * 1. Content-box so we don't get weird 1pixel jump error on IE (IE10 as well)
 * 2. Hide overflowing content like messages and info
 */

.k-upload {
  box-sizing: content-box; /* 1 */
  overflow: hidden; /* 2 */
  background: white;
  color: #555;
  border: 1px solid $k-upload-border-color;
  border-radius: $k-upload-radius;
  margin-bottom: 20px;
  min-height: $k-upload-height;
  transition: $k-upload-transition-fast;
  max-width: 100%;
  flex: 0 0 auto;

  /* Loading message on top */
  &:after {
    @include coverall;
    display: block;
    content: "Loading...";
    background: white;
    z-index: 9;
    text-align: left;
    padding: 0 15px;
    line-height: $k-upload-height;
    transition: $k-upload-transition-slow;

    @include rtl {
      text-align: right;
    }
  }


  /* Hide loading message on initializing */
  &.is-initialized {
    &:after {
      z-index: -2;
      opacity: 0;
    }
  }


  /**
   * Inline styling - modals
   *
   * 1. Reset border-radius to fit in parent view
   * 2. High z-index to set upload on top of the rest
   */

  &.k-upload--boxed-top {
    border-top-color: transparent;
    border-right-color: transparent;
    border-left-color: transparent;
    border-radius: 0; /* 1 */
    z-index: 9; /* 2 */
    box-shadow: none;
    margin: 0;

    .k-upload__content-wrapper {
      border-radius: 0; /* 1 */
      border-top: none;
      box-shadow: none;
    }
  }


  /* Border box size everything inside */
  * {
    box-sizing: border-box;
  }
}


/**
 * Custom height uploader
 *
 * To use this you also need to set a height to the uploader like so:
 * `<div class="k-upload k-upload--custom" style="height:300px"></div>`
 *
 * To have a flexible / fluid uploader use `.k-upload--flex` in combination with a flexing parent
 *
 * 1. Set background since uploader always looks open
 * 2. Set the bottom border and radius since uploader always looks open
 * 3. Position item absolute with 60px from the top to cover entire parent except uploader area
 * 4. Remove the max-height from containers since we're fluid
 * 5. Set overflow so overflowing content will be visible
 */

.k-upload--custom {
  background: #f3f3f3; /* 1 */

  .k-upload__content-wrapper {
    border-radius: $k-upload-radius $k-upload-radius 0 0; /* 2 */
    border-bottom-color: #ccc; /* 2 */
  }

  &.has-open-info .k-upload__body-info {
    @include coverall($top: 60px); /* 3 */
    max-height: none; /* 4 */
    overflow: auto; /* 5 */
  }

  .k-upload__info__content {
    max-height: none; /* 4 */
  }
}


/**
 * Flexing uploader
 *
 * Uploader that grows and shrinks with it's parent
 *
 * warning: you do need to have set up flexbox parents properly
 */

.k-upload--flex {
  margin: 0;
  min-height: 244px;
  flex: 1 1 auto;
}



/* Uploader animations
   ========================================================================== */

/**
 * 1. Position relative for `top` to work properly
 * 2. By default hide overflowing content
 * 3. Smooth transitions
 */

.k-upload__body-default,
.k-upload__body-message,
.k-upload__body-info {
  position: relative; /* 1 */
  overflow: hidden; /* 2 */
  transition: $k-upload-transition-slow; /* 3 */
}


/**
 * Default content wrapper
 *
 * 1. Higher z-index than message and info
 * 2. Set opacity to 1, so we can transition to 0
 * 3. Height should always be the same as the uploader
 */

.k-upload__body-default {
  z-index: 2; /* 1 */
  opacity: 1; /* 2 */
  min-height: $k-upload-height; /* 3 */
  max-height: $k-upload-height; /* 3 */
}


/**
 * Default content wrapper when message or info is visible
 *
 * 1. Set opacity to 0 to hide the item visually
 * 2. Move item out of "screen"
 */

.has-error {
  .k-upload__body-default {
    opacity: 0; /* 1 */
    margin-top: -60px; /* 2 */
  }
}


/**
 * Message and info containers, "hide" by default
 *
 * 1. Lower z-index to put behind the default content wrapper
 * 2. Set opacity to 0 to hide the item visually
 * 3. Height should always be the same as uploader
 * 4. Position items above content wrapper to make them slide in from top
 */

.k-upload__body-message,
.k-upload__body-info {
  z-index: 0; /* 1 */
  opacity: 0; /* 2 */
  min-height: $k-upload-height; /* 3 */
  max-height: $k-upload-height; /* 3 */
  margin-top: -($k-upload-height); /* 4 */
  top: -($k-upload-height); /* 4 */
}


/**
 * Display error and info
 *
 * 1. Higher z-index than other container
 * 2. Set opacity to 1 to visually show item
 * 3. Minimum height should always be the same as the uploader
 * 4. Set the max-height
 * 5. Move into "screen"
 */

.has-error .k-upload__body-message,
.has-open-info .k-upload__body-info {
  z-index: 1; /* 1 */
  opacity: 1; /* 2 */
  min-height: $k-upload-height; /* 3 */
  max-height: $k-upload-max-height; /* 4 */
  top: 0; /* 5 */
  margin-top: 0; /* 5 */
}


/**
 * Has error
 *
 * Hide the info container on displaying error
 */

.has-error {
  .k-upload__body-info {
    z-index: 0; /* 1 */
    opacity: 0; /* 2 */
    min-height: $k-upload-height; /* 3 */
    max-height: $k-upload-height; /* 3 */
    margin-top: -($k-upload-height); /* 4 */
    top: -($k-upload-height); /* 4 */
  }
}



/**
 * When dragging file over area
 */

.has-drag-hover {
  border-color: #29abe2;

  .k-upload__content-wrapper,
  .k-upload__info__content {
    background: #e9f8ff;
  }

  &.has-open-info {
    .k-upload__content-wrapper {
      border-bottom-color: #29abe2; /* Also color the queue list border */
    }
  }

  &.k-upload--boxed-top {
    border-color: #29abe2;
  }
}



/* Content wrapper
   ========================================================================== */

/**
 * 1. Display table to align drop text and buttons next to each other with easy vertical centering
 * 2. 100% width to stretch table even if content is not enough
 * 3. Min-height same as uploader container for vertical centering
 * 4. Borders for the extra container
 */

.k-upload__content-wrapper {
  display: table; /* 1 */
  width: 100%; /* 2 */
  min-height: 60px; /* 3 */
  border-radius: $k-upload-radius;
  background: white;
  border-top: 1px solid rgba(0,0,0,0.075);
  border-bottom: 1px solid white;
  box-shadow: inset 0 0 1px rgba(0,0,0,0.075);
  transition: $k-upload-transition-fast;
}


/**
 * Content & Buttons
 *
 * 1. Align content in vertical middle
 */

.k-upload__buttons,
.k-upload__content {
  vertical-align: middle; /* 1 */
}


/**
 * Content
 *
 * 1. "Drop files here" in larger font
 * 2. Set max-width to 0 for text-overflow: ellipsis to work properly
 * 3. Display as table-cell
 */

.k-upload__content {
  font-size: 16px; /* 1 */
  max-width: 0; /* 2 */
  padding: 0 15px;
  display: table-cell; /* 3 */
  height: 58px;
  min-height: 58px;
  transition: all .8s ease-in-out;

  @media (min-width: $k-upload-querie) {
    font-size: 20px; /* 1 */
  }
}

/* Hide drop message by default */
.k-upload__drop-message {
  transition: $k-upload-transition-fast;
  display: none;
}


/**
 * Define which content should be visible based on if drag and drop is supported
 */

.has-dragdrop-support {
  .k-upload__drop-message {
    display: block;
  }
  .k-upload__select-message {
    display: none;
  }
}


/**
 * Details button
 *
 * Opens the queue
 *
 * 1. Smaller font-size
 * 2. Styling as link
 */

.k-upload__details-button {
  font-size: 16px; /* 1 */
  cursor: pointer; /* 2 */
  text-decoration: underline; /* 2 */
  color: #3071a9; /* 2 */

  &:hover,
  &:focus {
    color: #1f496e; /* 2 */
    text-decoration: none; /* 2 */
  }

  .k-upload__details-button__close {
    display: none;
  }
}


/**
 * Files message
 *
 * 1. Hide container when no files are uploaded yet
 * 2. Smaller font when both file and drop message are visible
 * 3. Display files when file is selected
 */

.k-upload__files {
  opacity: 0; /* 1 */
  z-index: -1; /* 1 */
  margin: 0;
  padding: 0;
  border: none;
  transition: $k-upload-transition-fast;
}

.k-upload.has-file {
  .k-upload__files,
  .k-upload__drop-message {
    font-size: 14px; /* 2 */
    line-height: 21px; /* 2 */
  }

  .k-upload__files {
    opacity: 1; /* 3 */
    z-index: 0; /* 3 */
  }
}

.k-upload__file-list {
  height: 21px;
  overflow: hidden;

  div {
    height: 21px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
}



/* Buttons
   ========================================================================== */

/**
 * 1. Display as table-cell to align items
 * 2. Make this cell as large as it's content
 * 3. Don't wrap content to always align buttons
 */

.k-upload__buttons {
  display: table-cell; /* 1 */
  width: 1%; /* 2 */
  white-space: nowrap; /* 3 */
  padding-left: 15px;
  text-align: right;

  @include rtl {
    padding-left: 0;
    padding-right: 15px;
  }

  &--right {
    padding-left: 0;
    padding-right: 15px;

    @include rtl {
      padding-left: 15px;
      padding-right: 0;
    }
  }
}


/**
 * Buttons styling
 */

.k-upload__button,
.k-upload__text-button {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
  border-radius: $k-upload-radius;
  text-decoration: none;
  color: #333;

  /* Add spacing to left from second button */
  & + .k-upload__button,
  & + .k-upload__text-button {
    margin-left: 8px;
  }

  @include rtl {
    & + .k-upload__button,
    & + .k-upload__text-button {
      margin-left: auto;
      margin-right: 8px;
    }
  }

  /* Disabled buttons should be invisible, but only after initializing */
  @at-root .is-initialized &.disabled {
    display: none !important;
  }
}


/**
 * Moxie shim button
 *
 * Always on top of the button container
 */

.moxie-shim {
  z-index: 3;
}


/* Default button styling */

.k-upload__button {
  border: 1px solid #ddd;
  background: white;
  padding: 4px 8px;

  @media (min-width: $k-upload-querie) {
    padding: 5px 10px;
  }

  &:focus,
  &:hover {
    background: #f5f5f5;
    text-decoration: none;
  }
}


/* Upload button styling */

.k-upload__button--upload {
  background: #3071a9;
  color: white;
  border: 1px solid #1f496e;

  &:focus,
  &:hover {
    background-color: #1f496e;
    color: white;
    text-decoration: none;
  }
}


/* Text button styling */

.k-upload__text-button {
  border: none;
  background: transparent;
  text-decoration: underline;
  padding: 0;

  &:focus,
  &:hover {
    text-decoration: none;
  }
}



/* The '/' divider */

.k-upload__divider {
  display: inline-block;
  padding-left: 15px;
  font-size: 20px;
  vertical-align: middle;

  @include rtl {
    padding-left: 0;
    padding-right: 15px;
  }
}



/* Progress bar
   ========================================================================== */

/**
  * 1. Double class to win over the plupload styling
  * 2. Absolute positioning so it's not in the way of anything
  * 3. Hide container visually
  */

.k-upload__progress.progress { /* 1 */
  position: absolute; /* 2 */
  top: 0; /* 2 */
  right: 0; /* 2 */
  left: 0; /* 2 */
  margin: 0;
  height: $k-upload-progressbar-height;
  z-index: -1;  /* 3 */
  opacity: 0; /* 3 */
  transition: $k-upload-transition-fast;

  /* Display container visually when files are uploading */
  &.is-uploading {
    z-index: 99;
    opacity: 1;
  }

  /* Remove the 45deg gradient from plupload, just use a solid color */
  .bar {
    background-image: none;
  }
}



/* Message container
   ========================================================================== */

/**
 * For displaying errors, warnings and info
 *
 * 1. Set font styling
 * 2. Border-radius to fit in nicely within parent container
 * 3. 1px margin to set background aside from parent container
 */

.k-upload__message {
  padding: 8px 10px;
  transition: $k-upload-transition-fast;
  font-size: 15px; /* 1 */
  line-height: 21px; /* 1 */
  border-radius: $k-upload-radius - 1px; /* 2 */
  margin: 1px; /* 3 */
}

.k-upload--boxed-top {
  .k-upload__message {
    margin-top: 0;
    margin-right: 0;
    margin-left: 0;
  }
}


/**
 * Message content
 *
 * 1. Display table to align text and buttons next to each other with easy vertical centering
 * 2. 100% width to stretch table even if content is not enough
 */

.k-upload__message__content  {
  display: table; /* 1 */
  width: 100%; /* 2 */
}


/**
 * Message body and button
 *
 * 1. Display as table-cell to align items
 */

.k-upload__message__body,
.k-upload__message__button {
  display: table-cell; /* 1 */
}


/**
 * Message body
 *
 * 1. Vertical align text to the middle
 */

.k-upload__message__body {
  vertical-align: middle;
}


/**
 * Message button
 *
 * 1. Align button right
 * 2. Align buttons to the top (for when there's a lot of content)
 * 3. Add default padding to optically vertical align middle
 * 4. Make cell small but always big enough for it's content
 */

.k-upload__message__button {
  text-align: right; /* 1 */
  vertical-align: top; /* 2 */
  padding: 6px 4px 6px 10px; /* 3 */
  white-space: nowrap; /* 4 */
  width: 1%; /* 4 */

  @include rtl {
    padding: 6px 10px 6px 4px;
  }

  .k-upload__button {
    color: #000;
  }
}


/**
 * Message styling
 */

.k-upload__message--error {
  background: #e74c3c;
  color: white;
}

.k-upload__message--info {
  background: #2980b9;
  color: white;
}



/* Info / queue container
   ========================================================================== */

/**
 * 1. Set font styling
 * 2. Border-radius to fit in nicely within parent container
 * 3. 1px margin to set background aside from parent container
 */

.k-upload__info {
  transition: $k-upload-transition-fast;
  font-size: 15px; /* 1 */
  line-height: 21px; /* 1 */
}

.k-upload__info__content {
  background: #f3f3f3;
  border-radius: 0 0 $k-upload-radius $k-upload-radius;
  max-height: $k-upload-max-height;
  overflow: auto;
  transition: $k-upload-transition-fast;
}


/**
 * Has open info
 */

.has-open-info {
  .k-upload__content-wrapper {
    border-radius: $k-upload-radius $k-upload-radius 0 0;
    border-bottom-color: #ccc;
  }

  .k-upload__details-button__view {
    display: none;
  }

  .k-upload__details-button__close {
    display: inline;
  }
}


/**
 * The file list
 *
 * 1. Add some spacing to move from the sides
 * 2. Make some room for the clear queue message on mobile
 * 3. Remove top margin on desktop screens
 * 4. Position "clear queue" button outside the table on mobile
 * 5. Set "clear queue" button inline in the table on desktop
 */

.k-upload__info__body {
  padding: 10px; /* 1 */

  table {
    width: 100%;
    margin: 21px 0 0; /* 2 */
    padding: 0;
    font-size: 14px;

    @media (min-width: $k-upload-querie) {
      margin-top: 0; /* 3 */
    }
  }

  th, td {
    position: relative;
    text-align: left;
    white-space: nowrap;
    padding: 2px 5px;
  }

  @include rtl {
    th, td {
      text-align: right;
    }
  }

  .k-uploader__clear-queue {
    position: absolute; /* 4 */
    top: -20px; /* 4 */
    left: 0; /* 4 */

    @include rtl {
      left: auto;
      right: 0;
    }

    @media (min-width: $k-upload-querie) {
      position: static; /* 5 */
      top: auto; /* 5 */
      left: auto; /* 5 */

      @include rtl {
        right: auto;
      }
    }
  }
}


/**
 * Overflowing td
 */

.k-upload__overflow {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 0; /* Needed for text ellipsis to work */
}


/**
 * Remove files from the queue button
 */

.k-upload__remove-button {
  background: white;
  border: 1px solid #ccc;
  border-radius: $k-upload-radius - 1px;
  font-size: 12px;
  color: #555;
  display: block;
  width: $k-upload-list-button-mobile-size;
  height: $k-upload-list-button-mobile-size;
  line-height: $k-upload-list-button-mobile-size - 2px;
  overflow: hidden;
  text-align: center;
  transition: $k-upload-transition-fast;
  text-decoration: none;
  cursor: pointer;
  font-weight: bold;

  &:focus,
  &:hover {
    background: #f1f1f1;
    text-decoration: none;
  }

  @media (min-width: $k-upload-querie) {
    width: 100%;
    overflow: auto;
    padding: 0 5px;
    height: $k-upload-list-button-desktop-size;
    line-height: $k-upload-list-button-desktop-size - 2px;
  }
}


/**
 * Clear queue button
 */

th.k-upload__clear-queue {
  padding-left: 0;

  @include rtl {
    padding-left: 5px;
    padding-right: 0;
  }

  a {
    font-weight: normal;
  }
}


/**
 * Upload status labels
 *
 * 1. No padding left on the label wrapper so labels align to the left of the table nicely
 */

td.k-upload__file-status-wrapper {
  padding-left: 0;

  @include rtl {
    padding-left: 5px;
    padding-right: 0;
  }
}

.k-upload__file-status {
  border-radius: $k-upload-radius - 1px;
  font-size: 12px;
  color: white;
  display: block;
  width: $k-upload-list-button-mobile-size;
  height: 0;
  overflow: hidden;
  padding-top: $k-upload-list-button-mobile-size;
  text-align: center;
  transition: $k-upload-transition-slow;

  @media (min-width: 600px) {
    width: 100%;
    overflow: auto;
    padding: 0 5px;
    height: $k-upload-list-button-desktop-size;
    line-height: $k-upload-list-button-desktop-size;
  }
}

.k-upload__file-status.is-in-queue {
  background: #95a5a6;
  min-width: $k-upload-list-button-mobile-size;

  @media (min-width: $k-upload-querie) {
    min-width: 80px;
  }
}

.k-upload__file-status.is-uploading {
  background: #e67e22;
}

.k-upload__file-status.is-failed {
  background: #c0392b;
}

.k-upload__file-status.is-done {
  background: #27ae60;
}


/**
 * Hide parts of strings on mobile to make everything fit nicely
 */

.k-hidden-mobile {
  display: none;

  @media (min-width: $k-upload-querie) {
    display: inline;
  }
}


/**
 * Fullscreen drop visual and area to make it easier to use
 *
 * 1. Border box so padding and withd: 100% can be used at the same time
 * 2. Fixed position to cover whole screen, even on scroll
 * 3. Hide element by default
 * 4. Display table for vertical align
 * 5. Full width and height table for vertical align
 * 6. Make room for dashed border
 * 7. Default font settings
 */

.k-uploader-drop-visual {
  box-sizing: border-box; /* 1 */
  position: fixed; /* 2 */
  top: 0; /* 2 */
  right: 0; /* 2 */
  bottom: 0; /* 2 */
  left: 0; /* 2 */
  z-index: -1; /* 3 */
  opacity: 0; /* 3 */
  background: rgba(#3498db,.75);
  color: white;
  display: table; /* 4 */
  width: 100%; /* 5 */
  height: 100% /* 5 */;
  padding: 5px; /* 6 */
  font-family: sans-serif; /* 7 */
  font-weight: 400; /* 7 */
  -webkit-font-smoothing: antialiased; /* 7 */
  -moz-osx-font-smoothing: grayscale; /* 7 */
  @include transition;


  /**
   * 1. Table cell for vertical alignment
   * 2. horizontal and vertical align
   */

  span {
    display: table-cell; /* 1 */
    text-align: center; /* 2 */
    vertical-align: middle; /* 2 */
    font-size: 40px;
    border: 3px dashed white;
    text-shadow: 1px 1px 1px rgba(0,0,0,.25);
  }


  /**
   * Display item when hovering with dragged file (added class with js)
   */

  &.is-active {
    opacity: 1;
    z-index: 99999999;
  }
}
