import gql from 'graphql-tag';
import { create, error, ReferenceMap } from '@hatiolab/things-scene';
import { client, gqlContext } from '@operato/graphql';
export function createProcessProvider() {
    var _provider = new ReferenceMap(async (processId, resolve, reject) => {
        try {
            const response = await client.query({
                query: gql `
            query FetchProcessById($id: String!) {
              process(id: $id) {
                model
              }
            }
          `,
                variables: { id: processId },
                context: gqlContext()
            });
            const process = response.data.process;
            var model = JSON.parse(process.model);
            var scene;
            try {
                scene = await provider.get(processId);
                console.warn('Process fetched more than twice.', processId);
            }
            catch (e) {
                scene = create({
                    model,
                    mode: 0,
                    refProvider: provider
                });
                // s.app.baseUrl = undefined;
            }
            resolve(scene);
            // resolve(scene, {
            //   ...process,
            //   model
            // })
        }
        catch (e) {
            error(e);
            reject(e);
        }
    }, async (id, ref) => {
        ref.dispose();
    });
    return _provider;
}
export const provider = createProcessProvider();
//# sourceMappingURL=process-provider.js.map