import { TurboModule } from '@rnoh/react-native-openharmony/ts';
import { TM } from "./generated/ts"
import { emitter } from '@kit.BasicServicesKit';
import { JSON } from '@kit.ArkTS';

export type GlObj = { frag: string, name: string }

export class RNGLContextModule extends TurboModule implements TM.RNGLContext.Spec {
  private logger = this.ctx.logger.clone("GLCanvasManagerModule")

  addShader(id: number, shader: GlObj, callback: (err: string, res: string) => void): void {
    this.logger.info('#abc addShader is been invoked', id, JSON.stringify(shader))
    let glArr = []
    glArr.push({ id, ...shader })
    if (id) {
      AppStorage.setOrCreate(id.toString(), { data: glArr })
      emitter.emit('addShader', { data: glArr })
    }
  }

  removeShader(id: number): void {
    this.logger.info('removeShader is been invoked')
  }

  capture(): void {
    this.logger.info('drawLine is been invoked')
  }
}