import sdk from '@stackblitz/sdk';

export const previewCode = async (code: string, options: any) => {
  const el = document.querySelector('.cm-editor') as HTMLElement;
  if (!el) {
    return;
  }
  const vm = await sdk.embedProject(el, {
    title: 'Preview Code',
    template: 'javascript',
    files: {
      'index.html': '<h1>Hello World</h1>',
      'a/index.js': code,
    },

    dependencies: {},
  });
  vm.editor.openFile('index.js');
  setTimeout(() => {
    vm.getFsSnapshot().then((snapshot) => {
      console.log('files', snapshot);
    });
  }, 1000);
  return vm;
};
