/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict
 */

import type { InjectableStyle, StyleXOptions } from '../common-types';

export type ClassesToOriginalPaths = {
  +[className: string]: $ReadOnlyArray<string>,
};

export type ComputedStyle = null | $ReadOnly<
  [string, InjectableStyle, ClassesToOriginalPaths],
>;

// The classes in this file are used to represent objects that
// can be compiled into one or CSS rules.
//
// These are thin wrappers around the "values" in Raw Style Objects
// with all the metadata needed to compile them into CSS.
export interface IPreRule {
  compiled(options: StyleXOptions): $ReadOnlyArray<ComputedStyle>;
  equals(other: IPreRule): boolean;
}

export type AnyPreRule = NullPreRule | PreRule | PreRuleSet;

declare export class NullPreRule implements IPreRule {
  compiled(_options: StyleXOptions): [null];
  equals(other: IPreRule): boolean;
}

declare export class PreRule implements IPreRule {
  +property: string;
  +value: string | number | $ReadOnlyArray<string | number>;
  +keyPath: $ReadOnlyArray<string>;
  constructor(
    property: string,
    value: string | number | $ReadOnlyArray<string | number>,
    keyPath?: $ReadOnlyArray<string>,
  ): void;
  get pseudos(): $ReadOnlyArray<string>;
  get atRules(): $ReadOnlyArray<string>;
  get constRules(): $ReadOnlyArray<string>;
  compiled(
    options: StyleXOptions,
  ): $ReadOnlyArray<[string, InjectableStyle, ClassesToOriginalPaths]>;
  equals(other: IPreRule): boolean;
}

declare export class PreRuleSet implements IPreRule {
  +rules: $ReadOnlyArray<PreRule | NullPreRule>;
  constructor(rules: $ReadOnlyArray<PreRule | NullPreRule>): void;
  static create(
    rules: $ReadOnlyArray<PreRule | NullPreRule | PreRuleSet>,
  ): AnyPreRule;
  compiled(options: StyleXOptions): $ReadOnlyArray<ComputedStyle>;
  equals(other: IPreRule): boolean;
}
