// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.

// ---------------------------------------------------------------------
// Variables are defined by baseline Design Tokens

@import '../utilityVariables/spacing-options';
@import '../utilityFunctions/capitalize';
@import '../utilityFunctions/map-deep-get';
@import '../utilityVariables/important';
@import '../libSupport/manageScope';

$ds-spacing-types: inline, stack !default;
$ds-spacing-options: $ds-spacing-options !default;
$ds-spacing-properties: padding, padding, margin, margin !default;

/// This mixin is designed to return a series of pre-defined selectors based on the stack or inline spacing design specs
///
/// DO NOT execute mixin, this is already included with the import of the file dependency
///
/// **Dependency:** `$npm i @aurodesignsystem/design-tokens`
/// @group utility-layout
/// @param {string} $ds-spacing-types [inline, stack] inline - L/R, stack - top/bottom
/// @param {string} $ds-spacing-options [none, 25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] defines value applied.
/// @example css - Example output css
/// .util_inlinePadding25--left {
///   padding-left: 0.125rem;
/// }
/// .util_inlinePadding25--right {
///   padding-right: 0.125rem;
/// }
/// .util_inlineMargin25--left {
///   margin-left: 0.125rem;
/// }
/// .util_inlineMargin25--right {
///   margin-right: 0.125rem;
/// }
/// @example scss - import dependencies
///   @import "./node_modules/@aurodesignsystem/design-tokens/dist/auro-classic/SCSSVariableMap";
///   @import "./node_modules/@aurodesignsystem/webcorestylesheets/dist/utilityMixins/spacingUtility";
/// @example scss - import with custom over-rides
///   $ds-spacing-types: inline;
///   $ds-spacing-options: 200;
///   @import "./node_modules/@aurodesignsystem/design-tokens/dist/auro-classic/SCSSVariableMap";
///   @import "./node_modules/@aurodesignsystem/webcorestylesheets/dist/utilityMixins/spacingUtility";

@mixin auro_spacing($types: $ds-spacing-types, $options: $ds-spacing-options) {
  @each $type in $types {
    @each $value in $options {
      $map: map-keys($tokens);
      $var: auro_map-deep-get($tokens, #{$map}, #{$value});
      $directions: null;
      $properties: null;

      @if $type == stack {
        $directions: top, bottom, top, bottom;
      } @else if $type == inline {
        $directions: left, right, left, right;
      }

      @if $type == stack or $type == inline {
        $properties: $ds-spacing-properties;
      }

      @if not index($types, $type) {
        @error 'INVALID, \'#{$type}\' is not known, please choose from options, [#{$types}]';
      }

      @if auro_contains($options, $value) {
        @if not index($options, $value) {
          @error 'INVALID, \'#{$value}\' is not known, please choose from options, [#{$ds-inset-options}]';
        }

        @if $value == 'none' {
          @for $i from 1 through length($properties) {
            $direction: nth($directions, $i);
            $property: nth($properties, $i);
            #{$scope}.#{$prefix}util_#{$type}#{auro_capitalize($property)}#{auro_capitalize($value)}--#{$direction} {
              #{$property}-#{$direction}: 0 $important;
            }
          }
        } @else {
          @for $i from 1 through length($properties) {
            $direction: nth($directions, $i);
            $property: nth($properties, $i);
            #{$scope}.#{$prefix}util_#{$type}#{auro_capitalize($property)}#{auro_capitalize($value)}--#{$direction} {
              #{$property}-#{$direction}: $var $important;
            }
          }
        }
      }
    }
  }
}

@include auro_spacing()
