const start = `<script  setup>`;
const end = `</script>`;
let variablesData = ``;
let functionData = ``;
const scriptCombined = () => {
  return `
${start}
${getVariablesData()}
${functionData}
${end}
`;
};

let variablesStructure = {};


const addVariables = (tier, key, type) => {
  let obj = variablesStructure;
  if (tier.length > 0) {
    tier.forEach((t) => {
      obj = obj[t];
    });
    obj[key] = type;
  } else {
    obj[key] = type;
  }
};
const getVariablesData = () => {
  return `const pageForm = ref(${JSON.stringify(variablesStructure)})`;
};

const addFunction = (code) => {
  functionData += code;
};
const resetScript = (data) => {
  variablesData = ``;
  variablesStructure = {};
  functionData = ``;
};

export {
  addVariables, addFunction, scriptCombined, resetScript
};
