/**
 * This code was generated by "react-native codegen-lib-harmony"
 */

import {
  Descriptor as ComponentDescriptor,
  ViewBaseProps,
  ViewRawProps,
  ViewDescriptorWrapperBase,
  ColorValue,
  Color,
  RNInstance,
  Tag,
  RNComponentCommandReceiver,
  ViewPropsSelector,
} from '@rnoh/react-native-openharmony/ts';


export namespace RNCGLCanvas {
  export const NAME = "RNCGLCanvas" as const

  export interface DirectRawProps {
    pixelRatio?: number;
    backgroundColor?: number;
    autoRedraw?: boolean;
    overlay?: boolean;
    setZOrderOnTop?: boolean;
    nbContentTextures?: string;
    renderId?: string;
    data?: string;
    imagesToPreload?: string;
    children?: string;
    uri?: string;
  }
  
  export interface Props extends ViewBaseProps {}
  
  export interface State {}
  
  export interface RawProps extends ViewRawProps, DirectRawProps {}
  
  export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
    get pixelRatio() {
      return this.rawProps.pixelRatio ?? 0;
    }
    
    get backgroundColor() {
      return this.rawProps.backgroundColor ?? 0;
    }
    
    get autoRedraw() {
      return this.rawProps.autoRedraw ?? false;
    }
    
    get overlay() {
      return this.rawProps.overlay ?? false;
    }
    
    get setZOrderOnTop() {
      return this.rawProps.setZOrderOnTop ?? false;
    }
    
    get nbContentTextures() {
      return this.rawProps.nbContentTextures;
    }
    
    get renderId() {
      return this.rawProps.renderId;
    }
    
    get data() {
      return this.rawProps.data;
    }
    
    get imagesToPreload() {
      return this.rawProps.imagesToPreload;
    }
    
    get children() {
      return this.rawProps.children;
    }
    
    get uri() {
      return this.rawProps.uri;
    }
    
  
  }

  export type Descriptor = ComponentDescriptor<
    typeof NAME,
    Props,
    State,
    RawProps
  >;
  
  export class DescriptorWrapper extends ViewDescriptorWrapperBase<
    typeof NAME,
    Props,
    State,
    RawProps,
    PropsSelector
  > {
    protected createPropsSelector() {
      return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
    }
  }
  
  export interface EventPayloadByName {
  }
  
  export class EventEmitter {
    constructor(private rnInstance: RNInstance, private tag: Tag) {}
    
    emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
      this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
    }
  }
  
  export interface CommandArgvByName {
  }
  
  export class CommandReceiver {
    private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
    private cleanUp: (() => void) | undefined = undefined
  
    constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
    }
  
    subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
      if (!this.listenersByCommandName.has(commandName)) {
        this.listenersByCommandName.set(commandName, new Set())
      }
      this.listenersByCommandName.get(commandName)!.add(listener)
      const hasRegisteredCommandReceiver = !!this.cleanUp
      if (!hasRegisteredCommandReceiver) {
        this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
          if (this.listenersByCommandName.has(commandName)) {
            const listeners = this.listenersByCommandName.get(commandName)!
            listeners.forEach(listener => {
              listener(argv)
            })
          }
        })
      }
  
      return () => {
        this.listenersByCommandName.get(commandName)?.delete(listener)
        if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
          this.listenersByCommandName.delete(commandName)
        }
        if (this.listenersByCommandName.size === 0) {
          this.cleanUp?.()
        }
      }
    }
  }

}
