import { MovingHeadState } from 'rust_native_module';
import { Pattern, PatternOutput, Time } from './proto';

export class ChaserPattern implements Pattern {
  render(time: Time): PatternOutput {

    if (time.beatRelative === null) {
      return null;
    }

    let head_number = Math.ceil(time.beatRelative) % 4;

    let template: MovingHeadState = {
      startAddress: 0,
      pan: 0,
      tilt: 0,
      brightness: {
        type: 'dimmer',
        value: 0.2,
      },
      rgbw: [255, 0, 0, 0],
      speed: 1,
      reset: false,
    }

    let result = [];

    for (let [i, startAddress] of [1, 15, 29, 43].entries()) {
      result[i] = { ...template};
      result[i].startAddress = startAddress;

      if (i === head_number) {
        result[i].brightness = { type: 'dimmer', value: 1 };
      }
    }

    return result;
  }
}
