import { defaultVirtualService as y, VirtualService as J } from "../services/VirtualService.js";
import { useState as n, useEffect as l } from "react";
const w = ({
  virtualId: r,
  userName: s,
  virtualName: o,
  initAccessToken: u,
  onPromptError: S,
  metadata: t,
  onInitCompleted: g
}) => {
  const [U, i] = n(""), [V, c] = n(""), [m, f] = n([]), [e, p] = n(y);
  return l(() => {
    r === e.configs.virtualId && s === e.configs.userName && o === e.configs.virtualName && JSON.stringify(e.configs.metadata ?? {}) === JSON.stringify(t ?? {}) || p(
      new J({
        virtualId: r,
        userName: s,
        virtualName: o,
        initAccessToken: u,
        onPromptError: S,
        metadata: t,
        onInitCompleted: g
      })
    );
  }, [r, s, o, t, e]), l(() => {
    r && e && (i(""), c(""), f([]), e.initSession(r).then(() => {
      i(e.runnerUrl), c(e.modelUrl), f(e.cores);
    }));
  }, [r, e]), {
    runnerUrl: U,
    modelUrl: V,
    virtualService: e,
    cores: m
  };
};
export {
  w as useVirtual
};
