import { Ctx as n } from "./accelbyte-widgets33.mjs";
import a from "react";
import { ReadyPlayerMeDialogComponent as p } from "./accelbyte-widgets560.mjs";
import { IamUserClient as l } from "@accelbyte/sdk-iam";
class f extends a.Component {
  constructor(e) {
    super(e), this.receiveAvatar = async (o) => {
      typeof o.data == "string" && (this.props.setLoadingDialogOpen(), await this.renderImage(o.data, "halfbody-portrait-v1"), this.props.onCloseDialog());
    }, this.renderImage = async (o, i) => {
      try {
        const t = n.getAppState().getSdk(), s = await new l(t).renderImageFromGlbModel({ model: o, scene: i }).then((r) => {
          if (r.error)
            throw r.error;
          return r.response.data.renders;
        });
        this.props.updateAvatar(s[0]);
      } catch (t) {
        console.error(t), this.props.onCloseDialog();
      }
    }, this.state = {
      isDialogConfirmationOpen: !1
    };
  }
  componentDidMount() {
    window.addEventListener("message", this.receiveAvatar, !1);
  }
  render() {
    const { isDialogConfirmationOpen: e } = this.state;
    return /* @__PURE__ */ a.createElement(
      p,
      {
        onCloseDialog: this.props.onCloseDialog,
        isDialogConfirmationOpen: e,
        toggleDialogConfirmation: () => {
          this.setState({ isDialogConfirmationOpen: !e });
        }
      }
    );
  }
}
export {
  f as ReadyPlayerMeDialog
};
