import * as React from "react";
import { Text } from "react-native";
import { useContext } from "react";

type LiveEditProps = {
  children?: any;
  id?: any;
  Wrapper?: any;
  attributes?: any;
};
import { BuilderContext } from "../context/index";
import { findBlockById } from "../helpers/find-block";

function LiveEdit(props: LiveEditProps) {
  function block() {
    return findBlockById(context.content!, props.id);
  }

  function options() {
    return block?.()?.component?.options || {};
  }

  const context = useContext(BuilderContext);

  return (
    <props.Wrapper {...options()} attributes={props.attributes}>
      {props.children}
    </props.Wrapper>
  );
}

export default LiveEdit;
