'use strict';

const typeGuard = require('./type-guard-3ec852d7.js');
const breakpoints = require('./breakpoints-ebde4837.js');
const globalSlimmerRegistry = require('./global-slimmer-registry-b3bce7e0.js');
const responsiveFormatFacade = require('./responsive-format-facade-2cab7344.js');
const typography = require('./typography-4560e7f1.js');
const stateBorderFormatter = require('./state-border-formatter-4e5e4ed0.js');
const ui = require('./ui-32120990.js');

/**
 * The `StateFormatFacade` class in TypeScript provides a method to format different types of
 * state variants based on a specified flag.
 */
class StateFormatFacade {
  /**
   * The function `format` takes in an input and a flag, then formats the input based on the flag
   * provided.
   *
   * @param {StateVariantType} input - The `input` parameter in the `format` function is of type
   * `StateVariantType<ManagedStateScopeInput[Flag], State>`. This means that it expects an input value
   * that corresponds to the specified flag and state. The `Flag` type is a key of
   * `ManagedStateScopeInput
   * @param {keyof ManagedStateScopeInput} flag - The `flag` parameter in the `format` function is a key of the
   * `ManagedStateScopeInput` type. It is used to determine which formatting logic to apply based on the
   * specific flag provided. The function then switches on the flag value to select the appropriate
   * formatting logic for that particular flag.
   * @returns {string} The `format` function takes in an input of type
   * `StateVariantType<ManagedStateScopeInput[Flag], State>` and a flag of type `Flag`. It then switches
   * on the flag value and returns a formatted string based on the flag value. The return value depends
   * on the flag value:
   */
  format(input, flag) {
    switch (flag) {
      case 'backgroundColor':
        return typeGuard.StateBackgroundColorFormatter.format(input);
      case 'borderColor':
        return stateBorderFormatter.StateBorderColorFormatter.format(input);
      case 'shadow':
        return stateBorderFormatter.StateShadowFormatter.format(input);
      case 'border':
        return stateBorderFormatter.StateBorderFormatter.format(input);
      default:
        throw new Error(`Invalid flag ${flag} passed into StateFormatFacade`);
    }
  }
}
const StateFormatFacade$1 = new StateFormatFacade();

/**
 * It logs a warning message to the console.
 *
 * @param {string} tokenType - The name of the token type.
 * @param {unknown} value - The value that was passed into the token.
 * @param {unknown} availableOptions - The available options for the token type.
 */
function logInvalidValueMessage(tokenType, value, availableOptions) {
  globalSlimmerRegistry.LogUtility.warn(`The ${tokenType} value ${value} is invalid, it must be a value of: `, availableOptions);
}
/**
 * Given a token and an array of modes, return a string with the token formatted with the appropriate mode
 *
 * @param {string} token - The name of the token.
 * @param {TokenMode[]} modes - TokenMode[]
 * @returns {string} The formatted token.
 */
function formatTokenWithModes(token, modes) {
  let formattedToken = '';
  if (modes.includes('dark')) {
    formattedToken += ` dark:v-dark-${token}`;
  }
  return formattedToken;
}
/**
 * If the token is a valid spacing token, return the CSS class string. Otherwise, log an error message
 *
 * @param {unknown} token - The value that was passed into the function.
 * @returns {Nullable<string>} The the CSS class string of the padding token.
 */
function formatAndValidPadding(token) {
  if (typeGuard.isSpacingTokenType(token)) {
    return `v-p-${token}`;
  }
  else {
    logInvalidValueMessage('padding', token, Object.keys(typeGuard.Spacing));
  }
}
/**
 * The function `formatAndValidBorderStyle` formats a border style token and returns a string if it is
 * a valid border style type, otherwise it logs an invalid value message.
 *
 * @param {unknown} token - The `token` parameter is a value that represents a border style type.
 * @returns {Nullable<string>} The function `formatAndValidBorderStyle` returns a string that is formatted as
 * `v-border-` if the `token` parameter is of a valid border style type. If the `token` is not
 * a valid border style type, it logs an invalid value message and does not return anything (implicitly
 * returns `undefined`).
 */
function formatAndValidBorderStyle(token) {
  if (typeGuard.isBorderStyleType(token)) {
    return `v-border-${token}`;
  }
  else {
    logInvalidValueMessage('border-style', token, ui.BorderStyle);
  }
}
/**
 * If the token is a valid border radius, return a string with the token prefixed with `v-rounded-`. Otherwise, log an
 * error message
 *
 * @param {unknown} token - The value passed in by the user.
 * @returns {Nullable<string>} The the CSS class string of the border radius token.
 */
function formatAndValidBorderRadius(token) {
  if (typeGuard.isBorderRadiusTokenType(token)) {
    return `v-${token}`;
  }
  else {
    logInvalidValueMessage('border-radius', token, Object.keys(typeGuard.BorderRadius));
  }
}
/**
 * If the token is a valid border color, return CSS class string of the border color. Otherwise, log an error message
 *
 * @param {unknown} token - The value passed in by the user.
 * @returns {Nullable<string>}  return the CSS class string of the border color
 */
function formatAndValidBorderColor(token) {
  if (typeGuard.isBorderColorTokenType(token)) {
    return `v-${token}`;
  }
  else {
    logInvalidValueMessage('border-color', token, typeGuard.Colors.filter(() => /^border-color-.+$/.test));
  }
}
/**
 * If the token is a valid background color, return it with the v- prefix. Otherwise, log an error
 *
 * @param {unknown} token - The value of the token.
 * @param {TokenMode[]} withModes - TokenMode[] = []
 * @returns {Nullable<string>} CSS class string for the background color token with modes supported.
 */
function formatAndValidBackgroundColor(token, withModes = []) {
  if (typeGuard.isBackgroundColorTokenType(token)) {
    return `v-${token}` + formatTokenWithModes(token, withModes);
  }
  else {
    logInvalidValueMessage('background-color', token, typeGuard.Colors.filter(() => /^bg-.+$/.test));
  }
}
/**
 * If the token is a valid text color, return the token prefixed with `v-` and formatted with the given modes. Otherwise,
 * log an error
 *
 * @param {unknown} token - The token to format.
 * @param {TokenMode[]} withModes - TokenMode[] = []
 * @returns {Nullable<string>} A CSS class string that is either a valid color or a valid color with modes.
 */
function formatAndValidTextColor(token, withModes = []) {
  if (typeGuard.isTextColorTokenType(token)) {
    return `v-${token}` + formatTokenWithModes(token, withModes);
  }
  else {
    logInvalidValueMessage('text-color', token, typeGuard.Colors.filter(() => /^text-.+$/.test));
  }
}
/**
 * If the token is a valid breakpoint, return CSS class string for the flex breakpoint. Otherwise, log an error
 *
 * @param {unknown} token - The value of the breakpoint.
 * @returns {Nullable<string>} CSS class string for the flex breakpoint.
 */
function formatAndValidFlexBreakpoint(token) {
  if (typeGuard.isBreakpointsTokenType(token)) {
    return `vega-flex-${token}`;
  }
  else {
    logInvalidValueMessage('breakpoint', token, Object.keys(breakpoints.Breakpoints));
  }
}
/**
 * If the token is a breakpoint, return the breakpoint value. Otherwise, log an error and return 0
 *
 * @param {unknown} token - The value passed in by the user.
 * @returns {Nullable<number>} value of the breakpoint.
 */
function formatAndValidBreakpointSize(token) {
  if (typeGuard.isBreakpointsTokenType(token)) {
    return breakpoints.Breakpoints[token];
  }
  else {
    logInvalidValueMessage('breakpoint', token, Object.keys(breakpoints.Breakpoints));
  }
}
/**
 * If the token is a valid spacing token, return a string with the token name prefixed with `v-gap-`. Otherwise, log an
 * error message
 *
 * @param {unknown} token - The value passed in by the user.
 * @returns {Nullable<string>} CSS class string for the given gap token.
 */
function formatAndValidGap(token) {
  if (typeGuard.isSpacingTokenType(token)) {
    return `v-gap-${token}`;
  }
  else {
    logInvalidValueMessage('gap', token, Object.keys(typeGuard.Spacing));
  }
}
/**
 * If the token is a valid shadows token type, return the token with the prefix "v-". Otherwise, log an error message
 *
 * @param {string} token - The token to format.
 * @param {TokenMode[]} withModes - TokenMode[] = []
 * @returns {Nullable<string>} CSS class string of the shadow token with modes supported
 */
function formatAndValidShadow(token, withModes = []) {
  if (typeGuard.isShadowsTokenType(token)) {
    return `v-${token}` + formatTokenWithModes(token, withModes);
  }
  else {
    logInvalidValueMessage('shadows', token, typeGuard.Shadows);
  }
}
/**
 * It takes a token and a flag, and returns a string
 *
 * @typedef Flag key of ManagedResponsiveScopeInput
 * @param {ResponsiveType<ManagedResponsiveScopeInput[Flag]>} token - The token to format.
 * @param {Flag} flag - The flag that the token is being formatted for.
 * @returns {Nullable<ManagedResponsiveScopeOutput[Flag]>} A nullable string
 */
function formatAndValidResponsiveToken(token, flag) {
  if (token !== null && token !== undefined) {
    return responsiveFormatFacade.ResponsiveFormatFacade.format(token, flag);
  }
}
/**
 * The function `formatAndValidTypographyToken` formats a typography token by adding a prefix and checks if it is a valid typography token.
 *
 * @param {string} token - The `token` parameter is a string that represents a typography token.
 * @returns {Nullable<string>} a string value.
 */
function formatAndValidTypographyToken(token) {
  if (typeGuard.isTypographyTokenType(token)) {
    return `v-${token}`;
  }
  else {
    logInvalidValueMessage('font', token, typography.TypographyKeys);
  }
}
/**
 * The function `formatAndValidStateToken` formats and validates a state token based on a specified flag.
 *
 * @param {StateVariantType} token - The `token` parameter is a value that represents a state variant for a specific flag
 * in a managed state scope input.
 * @param {Flag} flag - The `flag` parameter is a key of the `ManagedStateScopeInput` type.
 * @returns {Nullable<string>} a formatted and validated state token as a string, or `null` if the input token is `null`
 * or `undefined`.
 */
function formatAndValidStateToken(token, flag) {
  if (token !== null && token !== undefined) {
    return StateFormatFacade$1.format(token, flag);
  }
}

exports.formatAndValidBackgroundColor = formatAndValidBackgroundColor;
exports.formatAndValidBorderColor = formatAndValidBorderColor;
exports.formatAndValidBorderRadius = formatAndValidBorderRadius;
exports.formatAndValidBorderStyle = formatAndValidBorderStyle;
exports.formatAndValidBreakpointSize = formatAndValidBreakpointSize;
exports.formatAndValidFlexBreakpoint = formatAndValidFlexBreakpoint;
exports.formatAndValidGap = formatAndValidGap;
exports.formatAndValidPadding = formatAndValidPadding;
exports.formatAndValidResponsiveToken = formatAndValidResponsiveToken;
exports.formatAndValidShadow = formatAndValidShadow;
exports.formatAndValidStateToken = formatAndValidStateToken;
exports.formatAndValidTextColor = formatAndValidTextColor;
exports.formatAndValidTypographyToken = formatAndValidTypographyToken;
