@use "lib/viewport";
/* stylelint-disable scss/no-global-function-names */
.subscription-campaign-sidebar {
  #main-outlet
    .container.list-container
    .row:nth-of-type(2)
    .full-width
    #list-area
    .contents {
    display: grid;
    grid-template-columns: 78% calc(22% - 2em);
    grid-template-areas: "content sidebar";
    grid-column-gap: 2em;

    span:first-of-type {
      grid-area: sidebar;
    }
  }
}

// Sidebar Version
.subscriptions-campaign-sidebar .campaign-banner {
  width: 100%;
  flex-direction: column;
  position: relative;

  .btn.close {
    position: absolute;
    top: 1em;
    right: 1em;
    font-size: 10px;
    z-index: 1;
  }

  .campaign-banner-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc(100% - 2em);
    padding: 1em 1em 2em 1em;
    position: relative;

    &-header {
      font-size: $font-up-5;
      margin: 0 !important;
      text-align: center;
    }

    &-description {
      width: 100%;
      font-size: $font-down-1;
      text-align: center;
      margin-bottom: 1em;
    }
  }

  .campaign-banner-progress {
    width: calc(100% - 2em);
    margin: 1em 0;
    padding: 1em;

    &-users {
      align-items: stretch;
      display: flex;
      flex-direction: column;
      margin: 0;

      &-title {
        font-size: $font-down-1;

        strong {
          font-weight: bold;
        }
      }
    }
  }

  .campaign-banner-info-button {
    height: 2em;
  }

  progress[value] {
    height: 1.5em;
  }

  .campaign-banner-progress-description {
    font-size: $font-down-1;
  }
}

// Hide from showing above main container outlet
// on topic list
body.archetype-regular {
  .above-main-container-outlet.subscriptions-campaign {
    display: none;
  }
}

// Above Topic List version
.campaign-banner {
  display: flex;
  width: 100%;
  margin: 1em 0 2em 0;
  border: 1px solid var(--primary-low);
  position: relative;
  align-items: stretch;
  box-shadow: 5px 5px
    var(--discourse_subscriptions_campaign_banner_shadow_color);

  @include viewport.until(md) {
    width: 98%;
    flex-direction: column;
  }

  .btn.close {
    position: absolute;
    top: 1em;
    right: 1em;
    font-size: 10px;
    background-color: transparent;
    padding: 0;

    &:hover {
      .d-icon {
        color: var(--primary);
      }
    }
  }

  &-info {
    width: 30%;
    padding: 2em;
    background-color: var(--primary-very-low);

    @include viewport.until(md) {
      width: calc(100% - 4em);
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-bottom: 1em;
    }

    &-header {
      font-size: $font-up-4;
      margin: 0;

      @include viewport.until(md) {
        font-size: $font-up-3;
      }
    }

    &-success {
      width: 100%;
      margin: 0;
    }

    &-description {
      width: 100%;
      margin: 0.25em 0 1em 0;

      @include viewport.until(md) {
        font-size: $font-down-1;
        text-align: center;
      }
    }

    &-button {
      grid-area: right;
      height: 2.5em;
      padding: 0.75em 1.5em 0.75em 2.75em;
      position: relative;

      .d-icon {
        position: absolute;
        left: 1em;

        &.hover-heart {
          opacity: 0;
          transition: opacity 0.2s ease-in-out;
        }
      }

      &:hover {
        .d-icon.hover-heart {
          opacity: 1;
        }
      }
    }
  }

  &-progress {
    width: 60%;
    padding: 1.5em 2em 1.5em;
    display: flex;
    flex-flow: column;
    justify-content: center;

    @include viewport.until(md) {
      width: calc(100% - 4em);
    }

    &-success {
      height: 32px;
      background: linear-gradient(
        -45deg,
        var(--tertiary-hover),
        var(--tertiary-medium),
        var(--tertiary-hover),
        var(--tertiary-medium)
      );
      border-radius: 2em;
      margin: 0;
      background-size: 400% 100%;
      animation: gradient 15s ease infinite;
    }

    &-description {
      margin: 0.5em 0 0;
      font-weight: 300;

      strong {
        font-weight: bold;
      }
    }

    &-users {
      align-items: center;
      display: inline-flex;
      margin: 0 0 -2em 0;

      &-title {
        strong {
          font-weight: bold;
        }
      }

      &-avatars {
        margin: 0 0 0 0.5em;
      }
    }

    progress[value] {
      appearance: none;
      height: 2.5em;
      width: 100%;
      border: 1px solid #e5e5e5;
      border-radius: 2em;
      background-color: var(--primary-very-low);
      overflow: hidden;
    }

    progress[value]::-webkit-progress-bar {
      background-color: var(--primary-very-low);
    }

    progress[value]::-webkit-progress-value {
      background-color: var(--tertiary);
      border-top-right-radius: 2em;
      border-bottom-right-radius: 2em;
    }

    progress[value]::-moz-progress-bar {
      background-color: var(--tertiary);
      border-top-right-radius: 2em;
      border-bottom-right-radius: 2em;
    }
  }
}

html:not(.mobile-view) {
  .subscriptions-campaign,
  .subscriptions-campaign-sidebar,
  .subscriptions-campaign-topic-footer {
    .goal-met .campaign-banner {
      .campaign-banner-info {
        &-description {
          margin: 1em auto !important;
        }
      }
    }
  }
}

// Stack buttons and container on mobile
html.mobile-view #topic-footer-buttons {
  display: flex;
  flex-direction: column;
}

// Topic Footer Version
html:not(.mobile-view) .subscriptions-campaign-topic-footer .campaign-banner {
  margin-top: 2em;
  width: calc(var(--d-max-width) * 0.87);

  @include viewport.until(lg) {
    width: auto;
  }

  .btn.close {
    top: 1em;
    right: 1em;
  }
}

// Topic Footer Version + Sidebar visible
@media screen and (width <= 1285px) {
  html:not(.mobile-view)
    body.has-sidebar-page
    .subscriptions-campaign-topic-footer
    .campaign-banner {
    width: auto;
  }
}

// CSS Animations for campaign Success
@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

/* Fireworks (modified to fit modern SASS standards)
  Copyright (c) 2020 by Eddie Lin (https://codepen.io/yshlin/pen/ylDEk)
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

$particles: 50;
$width: 500;
$halfwidth: calc($width / 2);
$height: 250;
$heightpartial: calc($height / 1.2);

// Create the explosion...
$box-shadow: ();

@for $i from 0 through $particles {
  $box-shadow:
    $box-shadow,
    random($width) -
      $halfwidth +
      px
      random($height) -
      $heightpartial +
      px
      hsl(random(360), 100%, 50%);
}

@mixin keyframes($animationName) {
  @keyframes #{$animationName} {
    @content;
  }

  @keyframes #{$animationName} {
    @content;
  }

  @keyframes #{$animationName} {
    @content;
  }

  @keyframes #{$animationName} {
    @content;
  }

  @keyframes #{$animationName} {
    @content;
  }
}

@mixin animation-delay($settings) {
  animation-delay: $settings;
}

@mixin animation-duration($settings) {
  animation-duration: $settings;
}

@mixin animation($settings) {
  animation: $settings;
}

@mixin transform($settings) {
  transform: $settings;
}

body:not(.archetype-regular, .success-animation-off) {
  .fireworks > .before,
  .fireworks > .after {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;

    @include animation(
      (
        1s bang ease-out 1s 2 backwards,
        1s gravity ease-in 1s 2 backwards,
        5s position ease-in-out 1s 1 backwards
      )
    );
  }
}

.fireworks > .after {
  @include animation-delay((1.25s, 1.25s, 1.25s));
  @include animation-duration((1.25s, 1.25s, 1.25s));
}

@include keyframes(bang) {
  to {
    box-shadow: $box-shadow;
  }
}

@include keyframes(gravity) {
  to {
    @include transform(translateY(200px));
    opacity: 0;
  }
}

@include keyframes(position) {
  0%,
  19.9% {
    margin-top: -2%;
    margin-left: -43%;
  }

  20%,
  39.9% {
    margin-top: 2%;
    margin-left: -18%;
  }

  40%,
  59.9% {
    margin-top: 0%;
    margin-left: 0%;
  }

  60%,
  79.9% {
    margin-top: 4%;
    margin-left: 18%;
  }

  80%,
  99.9% {
    margin-top: 6%;
    margin-left: 56%;
  }
}
