import { isStateVariantTokenType } from '../../../types/type-guard';
/**
 * StateVariantFormatter: Format state token to CSS styles
 */
export class StateVariantFormatter {
  /**
   * The function `format` takes an input state variant type and returns formatted CSS styles based on
   * the input.
   *
   * @param {StateVariantType} input - The `format` function takes an `input` parameter of type
   * `StateVariantType<ManagedStateScopeInput[Flag], State>`. This means that the `input` parameter
   * should be an object that contains styles for different states, where the keys are state names and
   * the values are the corresponding styles
   * @returns {string} The `format` function returns a string that contains CSS styles based on the input
   * provided. If the input is determined to be a state variant token type, the function generates CSS
   * styles for each state in the input and returns them joined by newlines. If the input is not a state
   * variant token type, the function generates CSS styles for the default state and returns them.
   */
  format(input) {
    if (isStateVariantTokenType(input)) {
      const stateStyles = [];
      this.getStates().forEach((state) => {
        const style = this.formatToken(input[state]);
        if (style) {
          stateStyles.push(`:host${state === 'default' ? '' : `(:${state})`}{\n\t${style}\n}`);
        }
      });
      return stateStyles.join('\n');
    }
    else {
      const style = this.formatToken(input);
      return `:host{\n\t${style}\n}`;
    }
  }
}
