/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */

import {ITheme} from './interfaces/ITheme';
import {IColorSystem} from './interfaces/IColorSystem';
import {IExtendedSpacingSystem} from './interfaces/ISpacingSystem';
import {ITypographySystem} from './interfaces/ITypographySystem';
import {IScreenSystem} from './interfaces/IScreenSystem';
import {IBackgroundSystem} from './interfaces/IBackgroundSystem';
import {ColorSystem} from './defaultTheme/ColorSystem';
import {SpacingSystem} from './defaultTheme/SpacingSystem';
import {TypographySystem} from './defaultTheme/TypographySystem';
import {ScreenSystem} from './defaultTheme/ScreenSystem';
import {BackgroundSystem} from './defaultTheme/BackgroundSystem';

export class ThemeFactory {
  /**
   * Creates a default theme instance
   * @returns A complete theme object
   */
  static createDefaultTheme(): ITheme {
    const colors = new ColorSystem();
    const spacing = new SpacingSystem();
    const typography = new TypographySystem();
    const screenSizes = new ScreenSystem();
    const backgrounds = new BackgroundSystem();

    return new DefaultTheme(colors, spacing, typography, screenSizes, backgrounds);
  }

  /**
   * Creates a custom theme with provided systems
   * @param colorSystem - Custom color system
   * @param spacingSystem - Custom spacing system
   * @param typographySystem - Custom typography system
   * @param screenSystem - Custom screen system
   * @returns A complete theme object
   */
  static createCustomTheme(
    colorSystem: IColorSystem,
    spacingSystem: IExtendedSpacingSystem,
    typographySystem: ITypographySystem,
    screenSystem: IScreenSystem,
    backgroundSystem?: IBackgroundSystem
  ): ITheme {
    const backgrounds = backgroundSystem || new BackgroundSystem();
    return new DefaultTheme(colorSystem, spacingSystem, typographySystem, screenSystem, backgrounds);
  }
}

class DefaultTheme implements ITheme {
  constructor(
    public readonly colors: IColorSystem,
    public readonly spacing: IExtendedSpacingSystem,
    public readonly typography: ITypographySystem,
    public readonly screenSizes: IScreenSystem,
    public readonly backgrounds: IBackgroundSystem
  ) {}

  readonly footerHeight = '51px';
  readonly headerAllowance = 200;
  readonly formFieldWidth = 350;
  readonly formFieldMaxWidth = 500;
  readonly formFieldMaxHeight = 250;
  readonly inputIconWidth = 16;

  get primaryColor(): string {
    return this.colors.blue;
  }

  get secondaryColor(): string {
    return this.colors.gray700;
  }

  get successColor(): string {
    return this.colors.green;
  }

  get infoColor(): string {
    return this.colors.cyan;
  }

  get warningColor(): string {
    return this.colors.yellow;
  }

  get dangerColor(): string {
    return this.colors.red;
  }

  get secondaryLight(): string {
    return this.colors.gray800;
  }

  get secondaryDark(): string {
    return this.colors.gray500;
  }

  get primaryThemeColor(): string {
    return this.colors.lightBlue;
  }

  get primaryBackground(): string {
    return this.colors.gray900;
  }

  get linkColor(): string {
    return this.colors.green;
  }

  get blackWithOpacity(): string {
    return this.colors.blackWithOpacity;
  }

  get primaryInputHeight(): string {
    return '2.2rem';
  }

  get primaryBorderColor(): string {
    return this.colors.gray400;
  }

  get primaryBorderWidth(): string {
    return '1px';
  }

  get primaryBorderRadius(): string {
    return '1.2rem';
  }

  get loaderSize() {
    return {
      small: 12,
      medium: 20,
      large: 50
    };
  }
}
