import { addCode, templateCombined, resetTemplate } from './template.js';
import { getInputCode } from './input.js';
import { getFormCode } from './form.js';
import { getTableCode } from './table.js';
import { scriptCombined, resetScript } from './script.js';
import Download from '@/plugins/download';

const reset = () => {
  resetScript();
  resetTemplate();
};

const elementEnum = {
  'hw-input': getInputCode, 'hw-form': getFormCode, 'hw-table': getTableCode
};

const exportConfig = (e) => {
  reset();
  const noFun = () => {
  };
  e.map(v => {
    (elementEnum[v.type] || noFun)({
      isForm: false, elementData: v, formData: {}
    });
  });
  let template = templateCombined();
  let script = scriptCombined();
  let codeStr = template + script;
  console.log(codeStr);
  const blob = new Blob([codeStr], { type: 'text/plain;charset=utf-8' });
  Download.saveAs(blob, Date.now() + '.vue');
};


export {
  exportConfig
};
