/**
 *
 * @ai-apps/angular v2.152.0 | _aspect-ratio.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. 2018, 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 'sass:list';
@use 'sass:math';
@use 'sass:meta';
@use '../../config' as *;

/// The aspect ratios that are used to generate corresponding aspect ratio
/// classes in code
/// @type List
/// @access public
/// @group @carbon/grid
$carbon--aspect-ratios: (
  (16, 9),
  (9, 16),
  (2, 1),
  (1, 2),
  (4, 3),
  (3, 4),
  (3, 2),
  (2, 3),
  (1, 1)
);

/// Generates the CSS classname utilities for the aspect ratios
///
/// CSS Tricks article on aspect ratios and all the different ways it can be done.
/// https://css-tricks.com/aspect-ratio-boxes/#article-header-id-6
///
/// That article references an earlier article on the topic.
/// https://keithjgrant.com/posts/2017/03/aspect-ratios/
///
/// @param {Number} $width width from an aspect ratio
/// @param {Number} $height height from an aspect ratio
/// @access private
/// @group @carbon/grid
@mixin aspect-ratio($aspect-ratios: $carbon--aspect-ratios) {
  .#{$prefix}--aspect-ratio {
    position: relative;
  }

  .#{$prefix}--aspect-ratio::before {
    width: 1px;
    height: 0;
    margin-left: -1px;
    content: '';
    float: left;
  }

  .#{$prefix}--aspect-ratio::after {
    display: table;
    clear: both;
    content: '';
  }

  @each $aspect-ratio in $aspect-ratios {
    $width: list.nth($aspect-ratio, 1);
    $height: list.nth($aspect-ratio, 2);

    .#{$prefix}--aspect-ratio--#{$width}x#{$height}::before {
      @if meta.function-exists('div', 'math') {
        padding-top: math.percentage(math.div($height, $width));
      } @else {
        padding-top: math.percentage(($height / $width));
      }
    }
  }
}
