////
/// @group tools
////
@use "sass:list";

/// List of modules which have already been exported
///
/// @type List
/// @access private

$govuk-imported-modules: () !default;

/// Export module
///
/// Ensure that the modules of CSS that we define throughout Frontend are only
/// included in the generated CSS once, no matter how many times they are
/// imported across the individual components with `@import`.
///
/// If you include your stylesheets as Sass modules with `@use` or `@forward`
/// Sass already ensures the CSS for the module is only output once without having
/// to use `govuk-exports`.
///
/// `govuk-exports` can also prevent a mixin from outputting CSS multiple times.
///
/// @param {String} $name - Name of module - must be unique within the codebase
/// @content The passed content will only be outputted if a module of the same
///   $name has not already been outputted. Use only with `@import`, not `@use`.
/// @access public

@mixin govuk-exports($name) {
  // If the mixin is not in the list of modules already exported...
  @if not list.index($govuk-imported-modules, $name) {
    // ... then add it to the list
    $govuk-imported-modules: list.append($govuk-imported-modules, $name) !global;
    // ... and output the CSS for that module
    @content;
  }
  // The next time exports is called for the module of the same name, it will be
  // found in the list and so nothing will be outputted.
}

