/**
 *
 * @ai-apps/angular v2.152.0 | _copy-button.scss
 *
 * Copyright 2014, 2023 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../../config' as *;
@use '../../spacing' as *;
@use '../../motion' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/convert' as *;
@use '../../utilities/box-shadow' as *;
@use '../../utilities/focus-outline' as *;
@use '../../utilities/keyframes' as *;
@use '../../utilities/tooltip' as *;
@use '../../utilities/visually-hidden' as *;

@mixin copy-button {
  .#{$prefix}--btn--copy {
    position: relative;
    overflow: visible;

    .#{$prefix}--btn__icon {
      margin-left: rem(5px);
    }
  }

  .#{$prefix}--btn--copy__feedback {
    position: absolute;
    top: 1.2rem;
    left: 50%;
    display: none;

    &::before {
      @include box-shadow;
      @include type-style('body-short-01');

      z-index: 2;
      top: 1.1rem;
      padding: $spacing-02;
      border-radius: 4px;
      color: $text-inverse;
      content: attr(data-feedback);
      font-weight: 400;
      pointer-events: none;
      transform: translateX(-50%);
      white-space: nowrap;
    }

    &::after {
      z-index: 1;
      top: 0.85rem;
      left: -0.3rem;
      width: 0.6rem;
      height: 0.6rem;
      border-right: 1px solid $background-inverse;
      border-bottom: 1px solid $background-inverse;
      content: '';
      transform: rotate(-135deg);
    }

    &::before,
    &::after {
      position: absolute;
      display: block;
      background: $background-inverse;
    }

    &--displayed {
      display: inline-flex;
    }
  }

  // TODO: deprecate above styles

  .#{$prefix}--copy-btn {
    @include reset;

    position: relative;
    display: flex;
    width: $spacing-08;
    height: $spacing-08;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background-color: $layer;
    cursor: pointer;

    &:hover {
      background-color: $layer-hover;
    }

    &:active {
      background-color: $layer-active;
    }

    &::before {
      @include tooltip--caret;

      display: none;
    }

    .#{$prefix}--copy-btn__feedback {
      @include tooltip--content('icon');

      display: none;
      overflow: visible;
      box-sizing: content-box;
      margin: auto;
      clip: auto;
    }

    @include tooltip--placement('icon', 'bottom', 'center');

    &:focus {
      @include focus-outline('outline');

      outline-color: $focus;
    }

    &.#{$prefix}--copy-btn--animating::before,
    &.#{$prefix}--copy-btn--animating .#{$prefix}--copy-btn__feedback {
      display: block;
    }

    &.#{$prefix}--copy-btn--animating.#{$prefix}--copy-btn--fade-out::before,
    &.#{$prefix}--copy-btn--animating.#{$prefix}--copy-btn--fade-out
      .#{$prefix}--copy-btn__feedback {
      // https://github.com/stylelint/stylelint/issues/2363
      animation: $duration-fast-02 motion(standard, productive) hide-feedback;
    }

    &.#{$prefix}--copy-btn--animating.#{$prefix}--copy-btn--fade-in::before,
    &.#{$prefix}--copy-btn--animating.#{$prefix}--copy-btn--fade-in
      .#{$prefix}--copy-btn__feedback {
      animation: $duration-fast-02 motion(standard, productive) show-feedback;
    }
  }

  // Needs to come after reset so hidden text is not set to font-size: 100%
  .#{$prefix}--copy {
    font-size: 0;
  }
}
