import { makeScene2D } from "@motion-canvas/2d";
import {
  Direction,
  beginSlide,
  createRef,
  slideTransition,
  all,
  waitFor,
} from "@motion-canvas/core";

import { FunctionBox } from "../components/function_box";

const add = `(a: number, b: number) => {
  return a + b;
}`;

export default makeScene2D(function* (view) {
  const functionBox = createRef<FunctionBox>();

  view.add(<FunctionBox arity={2} source={add} ref={functionBox} />);

  yield* slideTransition(Direction.Left);

  yield* beginSlide("Black Box");

  for (const [a, b] of [
    [-1, 2],
    [3, 4],
    [5, 6],
  ] as [number, number][]) {
    const inputId = "(" + [a, b].join(",") + ")";

    yield* all(functionBox().reset(0.25));
    yield* functionBox().setInputs([{ val: a }, { val: b }], 0.5);

    yield* beginSlide("Add Inputs " + inputId);

    yield* functionBox().propogateInput(0.5);
    yield* waitFor(0.3);
    yield* functionBox().propogateOutput(0.5);

    yield* beginSlide("Propogate Outputs of " + inputId);
    yield* beginSlide("Propogate Outputs of 1" + inputId);
  }
});
