////
///
/// Selection Controls Mixin Module
/// =========================================================================
///
/// Provides mixins for customizing text selection styles including
/// background colors, text colors, and themed selections. Supports
/// cross-browser compatibility with vendor prefixes.
///
/// @group Controls
/// @author Scape Agency
/// @link https://move.gl
/// @since 0.1.0 initial release
/// @access public
///
////


// ============================================================================
// Use
// ============================================================================

@use "sass:color";
@use "sass:map";
@use "../../variables" as *;
@use "../../maps" as *;


// ============================================================================
// Mixins
// ============================================================================


/// selection
/// ---------------------------------------------------------------------------
/// Base mixin for applying styles to text selection across browsers.
/// Uses @content to allow custom styles to be passed in.
///
/// @name selection
/// @group Controls
/// @access public
///
/// @content Styles to apply to selected text.
///
/// @example scss
///   @include selection {
///       background-color: #007bff;
///       color: #fff;
///   }
///
@mixin selection {
    ::selection { @content; }
    ::-moz-selection { @content; }
    ::-webkit-selection { @content; }
    ::-ms-selection { @content; }
}


/// custom-selection
/// ---------------------------------------------------------------------------
/// Mixin for defining custom text selection colors.
/// Applies background and text color to selected text.
///
/// @name custom-selection
/// @group Controls
/// @access public
///
/// @param {Color} $bg-color [#b3d4fc] - Selection background color.
/// @param {Color} $text-color [#fff] - Selection text color.
///
/// @example scss
///   .element {
///       @include custom-selection(#009688, #ffffff);
///   }
///
@mixin custom-selection($bg-color: #b3d4fc, $text-color: #fff) {
    &::selection {
        background-color: $bg-color;
        color: $text-color;
    }
    &::-moz-selection {
        background-color: $bg-color;
        color: $text-color;
    }
}


/// dynamic-selection
/// ---------------------------------------------------------------------------
/// Creates selection styles with dynamically adjusted colors based on a
/// base color. Lightens background and darkens text for good contrast.
///
/// @name dynamic-selection
/// @group Controls
/// @access public
///
/// @param {Color} $base-color - Base color for dynamic adjustment.
///
/// @example scss
///   .element {
///       @include dynamic-selection(#007bff);
///   }
///
@mixin dynamic-selection($base-color) {
    $adjusted-bg-color: color.adjust($base-color, $lightness: 20%);
    $adjusted-text-color: color.adjust($base-color, $lightness: -50%);

    &::selection {
        background-color: $adjusted-bg-color;
        color: $adjusted-text-color;
    }
    &::-moz-selection {
        background-color: $adjusted-bg-color;
        color: $adjusted-text-color;
    }
}


/// apply-selection-to-elements
/// ---------------------------------------------------------------------------
/// Applies selection styles to a list of elements. Useful for batch
/// application of consistent selection styles.
///
/// @name apply-selection-to-elements
/// @group Controls
/// @access public
///
/// @param {List} $elements - List of selectors to apply styles to.
/// @param {Color} $bg-color - Selection background color.
/// @param {Color} $text-color - Selection text color.
///
/// @example scss
///   @include apply-selection-to-elements(
///       ('p', 'h1', '.custom'),
///       #ffcc80,
///       #333
///   );
///
@mixin apply-selection-to-elements($elements, $bg-color, $text-color) {
    @each $element in $elements {
        #{$element}::selection {
            background-color: $bg-color;
            color: $text-color;
        }
        #{$element}::-moz-selection {
            background-color: $bg-color;
            color: $text-color;
        }
    }
}


/// gradient-selection
/// ---------------------------------------------------------------------------
/// Applies a gradient background to text selection. Note that gradient
/// support may vary across browsers.
///
/// @name gradient-selection
/// @group Controls
/// @access public
///
/// @param {Color} $color1 - First gradient color.
/// @param {Color} $color2 - Second gradient color.
///
/// @example scss
///   .element {
///       @include gradient-selection(#FFD54F, #D500F9);
///   }
///
@mixin gradient-selection($color1, $color2) {
    &::selection {
        background: linear-gradient(45deg, $color1, $color2);
        color: color.mix($color1, $color2, 50%);
    }
    &::-moz-selection {
        background: linear-gradient(45deg, $color1, $color2);
        color: color.mix($color1, $color2, 50%);
    }
}


/// scoped-selection
/// ---------------------------------------------------------------------------
/// Applies selection styles to a specific scope/selector. Useful for
/// theming different sections of a page.
///
/// @name scoped-selection
/// @group Controls
/// @access public
///
/// @param {String} $scope - CSS selector for the scope.
/// @param {Color} $bg-color - Selection background color.
/// @param {Color} $text-color - Selection text color.
///
/// @example scss
///   @include scoped-selection('.dark-theme', #333, #fff);
///   @include scoped-selection('.light-theme', #e0e0e0, #000);
///
@mixin scoped-selection($scope, $bg-color, $text-color) {
    #{$scope}::selection {
        background-color: $bg-color;
        color: $text-color;
    }
    #{$scope}::-moz-selection {
        background-color: $bg-color;
        color: $text-color;
    }
}
