import { makeScene2D } from "@motion-canvas/2d";
import {
  Direction,
  beginSlide,
  createRef,
  slideTransition,
} from "@motion-canvas/core";
import { CodeBlock, insert } from "@motion-canvas/2d/lib/components/CodeBlock";
import { theme } from "../theme";

const conversation = `
I am the psychotherapist.  Please, describe your problems.  Each time you are finished talking, type RET twice.
> i need a valentine
Why do you say you might want to have this valentine?
> im lonely
Are you lonely often?
> sometimes
Can you elaborate on that?
> i need someone or something i can trust
What makes you believe you need someone or something you can trust?
> i want something that when i ask one question i'll get the same answer no matter what.
Is it because when you ask one question you will get the same answerno matter what that you came to me?
> yes
I see...  Well, are you sure that this is so?
> yes
Yes, hmmm... so, do you really think this is so?
> yes`
  .split("\n")
  .filter((x) => x.trim());

export default makeScene2D(function* (view) {
  const block = createRef<CodeBlock>();
  let currentConversation = conversation[0] + "\n";

  view.add(
    <CodeBlock
      fontFamily={theme.font}
      language="markdown"
      ref={block}
      fontSize={20}
      code={currentConversation}
    ></CodeBlock>,
  );

  yield* slideTransition(Direction.Right);

  let id = 0;
  for (const line of conversation.slice(1)) {
    yield* block().edit(1.2, false)`${currentConversation}${insert(
      "\n" + line + "\n",
    )}`;
    currentConversation += "\n" + line + "\n";
    yield* beginSlide(line.split(" ").slice(0, 3).join(" ") + id.toString());
  }
});
