// Copyright 2025 (c) MatteuSan and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

@use 'validators';

/// Prefixing errors/warns.
/// @access private
@function _identify($source, $context) {
  @return if(validators.is-empty($source) == false, '#{$context} [#{$source}]:', '#{$context}:');
}

/// Throws an error.
/// @param {string} $message
/// @param {string} $source
/// @param {boolean} $output-string
/// @return {error|string} The error.
@function error($message, $source: (), $output-string: false) {
  @if not $output-string {
    @error '#{_identify($source, 'ERROR')} #{$message}';
  }
  @return '#{_identify($source, 'ERROR')} #{$message}';
}

/// The error() function mixin counterpart.
/// @param {string} $message
/// @param {string} $source
/// @param {boolean} $output-string
/// @return {error|string} The error.
@mixin error($message, $source: (), $output-string: false) {
  --sentro-error: '#{error($message, $source, $output-string)}';
}

/// Throws a warning.
/// @param {string} $message
/// @param {string} $source
/// @param {boolean} $output-string
/// @return {warn|string} The warning.
@function warn($message, $source: (), $output-string: false) {
  @if not $output-string {
    @warn '#{_identify($source, 'WARN')} #{$message}';
  }
  @return '#{_identify($source, 'WARN')} #{$message}';
}

/// The warn() function mixin counterpart.
/// @param {string} $message
/// @param {string} $source
/// @param {boolean} $output-string
/// @return {warn|string} The warning.
@mixin warn($message, $source: (), $output-string: false) {
  --sentro-warning: '#{warn($message, $source, $output-string)}';
}