@charset "UTF-8";

// @description
// * flex-shrink mixin.
// * This mixin provides a convenient way to set the `flex-shrink`
// * property with vendor prefixes for better cross-browser compatibility.

// @access public

// @version 1.2.1

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @reference: https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink

// @namespace main-props

// @module main-props/flex-shrink

// @dependencies:
// * - meta.type-of (SASS function).
// * - LibFunc1.is-in-list (function).
// * - LibFunc2.cut-unit (function).
// * - Error.throw (function).

// @param {String|Number} $val
// * The value for the `flex-shrink` property.
// * Allowed values: initial, inherit, or a non-negative number.
// * Default: initial.

// @throws {Error}
// * Throws an error if the provided $val is not one of the
// * allowed values or if it's a negative number.

// @example
// * .example {
// *     @include flex-shrink(2);
// * }

// @output:
// * .example {
// *   -webkit-flex-shrink: 2;
// *   -ms-flex-negative: 2;
// *   -ms-flex-shrink: 2;
// *   -moz-box-flex: 2;
// *   -moz-flex-shrink: 2;
// *   flex-shrink: 2;
// * }

// @note
// * There are two mixins in this file.
// * The first is the (flex-shrink) mixin and second is (f-s) mixin.
// * The second one is for only simplicity when using (flex-shrink) mixin.
// * The core logic of (f-s) mixin is to call the first one.
// * You can use one of them as you want.

// stylelint-disable scss/dollar-variable-empty-line-before

@use "sass:meta";
@use "../../../functions/global" as LibFunc;
@use "../../../abstract/global-variables" as var;
@use "../../../development-utils/toggle-error-message" as Error;

@mixin flex-shrink($value) {
    $flex-shrink-props: (
        -webkit-flex-shrink,
        -ms-flex-negative,
        -ms-flex-shrink,
        -moz-box-flex,
        -moz-flex-shrink,
        flex-shrink
    ) !default;

    @if meta.type-of($value) == string {
        @if LibFunc.is-in-list(var.$flex-shrink-values, $value) {
            @each $prop in $flex-shrink-props {
                // stylelint-disable-next-line scss/no-global-function-names
                #{$prop}: if(meta.type-of($value) == string, $value, LibFunc.cut-unit($value));
            }
        } @else {
            content: Error.throw("The parameter of flex-shrink mixin must be one of: (#{var.$flex-shrink-values}).");
        }
    }

    @if meta.type-of($value) == number {
        @if $value < 0 {
            content: Error.throw("The parameter of flex-shrink mixin must be greater than or equal to zero.");
        } @else {
            @each $prop in $flex-shrink-props {
                // stylelint-disable-next-line scss/no-global-function-names
                #{$prop}: if(meta.type-of($value) == string, $value, LibFunc.cut-unit($value));
            }
        }
    }
}

@mixin f-s($value) {
    @include flex-shrink($value);
}
