@import '~prismjs/themes/prism.css';

$snippet-background-color: $light-gray-3;
$snippet-border-color: $light-gray-2;

@mixin snippet {
  // @include type-style('code-01');
  background: $snippet-background-color;
  border: 1px solid $snippet-border-color;
  position: relative;
  max-width: 600px;
  width: 100%;
}

.snippet {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font-family: inherit;
  vertical-align: baseline;
}

// Inline Code Snippet
.snippet--inline {
  box-sizing: border-box;
  margin: 0;
  border: 0;
  background: none;
  font-size: 100%;
  font-family: inherit;
  vertical-align: baseline;
  -webkit-appearance: none;
  -moz-appearance: none;
  // Note: originally this inline snippet inherited font-size, we might need
  // a more flexible strategy than explicitly setting font-size with this
  // type style
  position: relative;
  display: inline;
  padding: 0;
  border-radius: $border-radius-sm;
  background: $light-gray-2;
  color: $dark;
  cursor: pointer;

  &:hover {
    background-color: $light-gray-1;
  }

  &:active {
    background-color: $dark-gray-3;
    color: $light;
  }

  &:focus {
    outline: none;
    // border: 2px solid $interactive-01;
  }
}

.snippet--inline code {
  padding: 0 $spacing-xs;
}

// Single Line Snippet
.snippet--single {
  @include snippet;
  overflow-y: hidden;
  border: 1px solid $snippet-border-color;
  max-width: 760px;
  min-width: 320px;
  height: $spacing-2xl;
  padding: 0 40px 0 $spacing-md;
  border-radius: $border-radius;
}

.snippet--single .snippet-container {
  display: flex;
  align-items: center;
  overflow-x: auto;
  position: relative;
  padding: 0 0 $spacing-md 0;
  height: 56px;
}

.snippet--single pre {
  white-space: nowrap;
  padding-right: $spacing-xs;
}

.snippet--single::after {
  width: 16px;
  height: 100%;
  content: '';
  position: absolute;
  top: 0;
  right: 40px;
  background-image: linear-gradient(to right, transparent, $snippet-background-color);
}

// Multi Line Snippet
.snippet--multi {
  @include snippet;
  border: none;
  padding: $spacing-md;
  min-width: 320px;
  max-width: 100%;
  border-radius: $border-radius;
  border: 1px solid $snippet-border-color;
  overflow: hidden;

  code {
    line-height: 1.2;
  }

  //closed snippet container
  .snippet-container {
    overflow: hidden;
    position: relative;
    max-height: 238px;
    min-height: 56px;
    transition: max-height .3s ease;
  }

  // expanded snippet container
  &.snippet--expand
    .snippet-container {
    max-height: 1500px;
    transition: max-height .3s ease;
  }

  // closed pre
  .snippet-container pre {
    overflow: hidden;
  }

  // expanded pre
  &.snippet--expand
    .snippet-container
    pre {
    overflow-x: scroll;
  }
}


.snippet--multi .snippet-container pre::after {
  width: 16px;
  height: 100%;
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  background-image: linear-gradient(to right, transparent, $snippet-background-color);
}

.snippet--multi .snippet-container pre code {
  overflow: hidden;
}

//Copy Button
.snippet__icon {
  fill: $dark;
  height: 16px;
  width: 16px;
  transition: all .2s ease;
}

.snippet-button {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font-family: inherit;
  vertical-align: baseline;
  cursor: pointer;
  position: absolute;
  top: 0;
  right: 0;
  border-left: 1px solid $snippet-border-color;
  background-color: $white;
  outline: none;
  padding: 0;
  height: $spacing-2xl;
  width: $spacing-2xl;
  overflow: visible;
  transition: background-color .3s ease;

  .suka-icon {
    vertical-align: middle;
    top: -2px;
    position: relative;
  }

  &.snippet-button--copied {
    background-color: $success !important;
  }
}

.snippet--multi .snippet-button {
  height: $spacing-xl;
  width: $spacing-xl;
  top: 0;
  right: 0;
  border-bottom-left-radius: $border-radius;
  border-left: 1px solid $snippet-border-color;
  border-bottom: 1px solid $snippet-border-color;
}

.snippet-button:hover {
  background-color: $light-gray-2;
}

.snippet-button:active {
  background-color: $light-gray-1;
}

.btn--copy__feedback {
  // @include type-style('body-short-01');
  z-index: 1003;
  font-weight: 400;
  left: inherit;
  top: 0.75rem;
  right: 1.25rem;
}

// Show more / less button
button.btn.snippet-btn--expand {
  display: inline-flex;
  align-items: center;
  position: absolute;
  border: none;
  font-weight: 500;
  right: 0;
  bottom: 0;
  padding: $spacing-xs $spacing-md;
  border-top-left-radius: $border-radius;
  border-left: 1px solid $snippet-border-color;
  border-top: 1px solid $snippet-border-color;
  color: $dark;
  background-color: $white;
}

button.btn.snippet-btn--expand
  .snippet-btn--text {
  position: relative;
  top: -1px;
}

.snippet-btn--expand--hide.snippet-btn--expand {
  display: none;
}

.snippet-btn--expand .suka-icon {
  fill: $dark;
  margin-left: $spacing-xs;
  margin-bottom: 1px;
  transition: .3s transform ease;
}

button.btn.snippet-btn--expand {
  &:hover {
    background: $light-gray-2;
  }

  &:active {
    background-color: $light-gray-1;
  }

  &:focus {
    // border-color: $primary;
    outline: 0;
    // box-shadow: 0 0 0 0.2rem rgba($primary,.25);
  }
}

.snippet--expand
  .snippet-btn--expand
  .suka-icon {
  transform: rotate(180deg);
  transition: transform .3s;
}

// Skeleton State
.snippet--code.skeleton {
  height: 98px;
}

.snippet--terminal.skeleton {
  height: 56px;
}

.snippet.skeleton .snippet-container {
  height: 100%;
}

.snippet.skeleton code {
  @include skeleton;
  width: 100%;
  height: 1rem;
  display: block;
}

.snippet--multi.skeleton {
  height: 98px;
}

.snippet--single.skeleton {
  height: 56px;
}

.snippet.skeleton .snippet-container {
  height: 100%;
}

.snippet.skeleton span {
  @include skeleton;
  width: 100%;
  height: 1rem;
  display: block;
  margin-top: $spacing-xs;

  &:first-child {
    margin: 0;
  }

  &:nth-child(2) {
    width: 85%;
  }

  &:nth-child(3) {
    width: 95%;
  }
}

.snippet--single.skeleton
  .snippet-container {
  padding-bottom: 0;
}

// Skeleton State
.snippet--code.skeleton {
  height: 98px;
}

.snippet--terminal.skeleton {
  height: 56px;
}

.snippet.skeleton .snippet-container {
  height: 100%;
}

.snippet.skeleton code {
  @include skeleton;
  width: 100%;
  height: 1rem;
  display: block;
}
