// Typography System
// Font families, sizes, weights, and line heights

export interface TypographyScale {
  fontFamily: string;
  fontSize: string;
  fontWeight: number | string;
  lineHeight: string | number;
  letterSpacing?: string;
}

export interface TypographyConfig {
  fontFamilies: {
    sans: string[];
    mono: string[];
    serif: string[];
  };
  scales: {
    xs: TypographyScale;
    sm: TypographyScale;
    base: TypographyScale;
    lg: TypographyScale;
    xl: TypographyScale;
    '2xl': TypographyScale;
    '3xl': TypographyScale;
    '4xl': TypographyScale;
    '5xl': TypographyScale;
    '6xl': TypographyScale;
  };
  weights: {
    light: number;
    normal: number;
    medium: number;
    semibold: number;
    bold: number;
    extrabold: number;
  };
}

export const typographyConfig: TypographyConfig = {
  fontFamilies: {
    sans: ['Inter', 'system-ui', '-apple-system', 'sans-serif'],
    mono: ['Fira Code', 'Consolas', 'Monaco', 'monospace'],
    serif: ['Georgia', 'Times New Roman', 'serif'],
  },
  scales: {
    xs: {
      fontFamily: 'var(--font-sans)',
      fontSize: '0.75rem',
      fontWeight: 400,
      lineHeight: 1.5,
      letterSpacing: '0.025em',
    },
    sm: {
      fontFamily: 'var(--font-sans)',
      fontSize: '0.875rem',
      fontWeight: 400,
      lineHeight: 1.5,
      letterSpacing: '0.025em',
    },
    base: {
      fontFamily: 'var(--font-sans)',
      fontSize: '1rem',
      fontWeight: 400,
      lineHeight: 1.5,
      letterSpacing: '0',
    },
    lg: {
      fontFamily: 'var(--font-sans)',
      fontSize: '1.125rem',
      fontWeight: 400,
      lineHeight: 1.5,
      letterSpacing: '0',
    },
    xl: {
      fontFamily: 'var(--font-sans)',
      fontSize: '1.25rem',
      fontWeight: 500,
      lineHeight: 1.4,
      letterSpacing: '-0.025em',
    },
    '2xl': {
      fontFamily: 'var(--font-sans)',
      fontSize: '1.5rem',
      fontWeight: 500,
      lineHeight: 1.3,
      letterSpacing: '-0.025em',
    },
    '3xl': {
      fontFamily: 'var(--font-sans)',
      fontSize: '1.875rem',
      fontWeight: 600,
      lineHeight: 1.2,
      letterSpacing: '-0.025em',
    },
    '4xl': {
      fontFamily: 'var(--font-sans)',
      fontSize: '2.25rem',
      fontWeight: 600,
      lineHeight: 1.2,
      letterSpacing: '-0.05em',
    },
    '5xl': {
      fontFamily: 'var(--font-sans)',
      fontSize: '3rem',
      fontWeight: 700,
      lineHeight: 1.1,
      letterSpacing: '-0.05em',
    },
    '6xl': {
      fontFamily: 'var(--font-sans)',
      fontSize: '3.75rem',
      fontWeight: 700,
      lineHeight: 1,
      letterSpacing: '-0.05em',
    },
  },
  weights: {
    light: 300,
    normal: 400,
    medium: 500,
    semibold: 600,
    bold: 700,
    extrabold: 800,
  },
};

export type TypographySize = keyof typeof typographyConfig.scales;
export type TypographyWeight = keyof typeof typographyConfig.weights;

export class TypographyService {
  /**
   * Get typography scale
   */
  static getScale(size: TypographySize): TypographyScale {
    return typographyConfig.scales[size];
  }

  /**
   * Get font weight value
   */
  static getWeight(weight: TypographyWeight): number {
    return typographyConfig.weights[weight];
  }

  /**
   * Get CSS properties for typography
   */
  static getTypographyCSS(
    size: TypographySize,
    weight?: TypographyWeight,
    family: 'sans' | 'mono' | 'serif' = 'sans'
  ): Record<string, string> {
    const scale = this.getScale(size);
    const fontWeight = weight ? this.getWeight(weight) : scale.fontWeight;

    return {
      fontFamily: typographyConfig.fontFamilies[family].join(', '),
      fontSize: scale.fontSize,
      fontWeight: String(fontWeight),
      lineHeight: String(scale.lineHeight),
      letterSpacing: scale.letterSpacing || '0',
    };
  }
}

