import { unpackProxyObject as c } from "@scalar/workspace-store/helpers/unpack-proxy";
const m = ({
  workspaceStore: r,
  workspaceState: u,
  name: s
}) => {
  if (!r)
    return { ok: !1, error: "Workspace store is not available" };
  const t = c(r.workspace.documents[s]);
  if (!t)
    return { ok: !1, error: "Current document not found in workspace store" };
  const n = u.documents[s];
  if (!n)
    return { ok: !1, error: "Importing document not found in workspace state" };
  const o = {
    selectedServer: t["x-scalar-selected-server"],
    securitySchemes: t.components?.securitySchemes,
    servers: t.servers
  };
  r.loadWorkspace({
    meta: {},
    documents: {
      [s]: n
    },
    intermediateDocuments: {},
    originalDocuments: {},
    overrides: {},
    history: {},
    auth: {}
  });
  const e = c(r.workspace.documents[s]);
  return e ? (e["x-scalar-selected-server"] = o.selectedServer, e.servers = o.servers, e.components ??= {}, e.components.securitySchemes = o.securitySchemes, { ok: !0 }) : { ok: !1, error: "New document not found in workspace store" };
};
export {
  m as restoreWorkspaceState
};
