import PrintElement from './print.js';

var generate = {};

/* const initialModel = {
  customKeys: [],
  equationEditor: 'geometry',
  responseType: 'Advanced Multi',
  expression: '{{response}}',
  responses: [
    {
      answer: 'r=\\sqrt{\\frac{V}{7\\pi}}',
      id: '1',
      alternates: {},
      validation: 'literal',
    },
  ],
  note: 'The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct.',
  rationale:
    '<p>The correct answer is:</p><ul><li><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi><mo>=</mo><msqrt><mfrac><mi>V</mi><mrow><mn>7</mn><mi>&#960;</mi></mrow></mfrac></msqrt></math></li></ul>',
}; */

const E262456 = {
  equationEditor: 3,
  toolbarEditorPosition: 'bottom',
  prompt:
    '<p><strong>B.</strong> Find the value of the expression that you wrote in part A to find how much money the band members made.</p>\n\n<p>Use the on-screen keyboard to type your answer in the box below.</p>\n',
  expression: '${{response}}',
  responses: [
    {
      allowSpaces: true,
      // 'validation': 'symbolic',
      answer: '$410',
      id: '1',
    },
  ],
  responseType: 'Advanced Multi',
};

generate.model = (id, element) => ({
  id,
  element,
  ...E262456,
  rubricEnabled: false,
});

const { model } = generate;

var config = {
  elements: {
    'math-inline': '../..',
  },
  models: [model('1', 'math-inline')],
};

// new init - just shows off print!

const init = async () => {
  console.log('define the element...');
  await Promise.all(
    config.models.map(async (m) => {
      try {
        const printTag = `${m.element}-print`;
        if (customElements.get(printTag)) {
          return true;
        } else {
          customElements.define(printTag, PrintElement);
          await customElements.whenDefined(printTag);
          return true;
        }
      } catch (e) {
        return false;
      }
    })
  );

  console.log('now apply the model...');
  config.models.forEach((m) => {
    const printTag = `${m.element}-print`;
    const h3s = document.createElement('h3');
    h3s.textContent = 'student mode';
    document.body.appendChild(h3s);
    const de = document.createElement(printTag);
    document.body.appendChild(de);
    de.options = {};
    de.model = m;

    const h3 = document.createElement('h3');
    h3.textContent = 'instructor mode';
    document.body.appendChild(h3);
    const instr = document.createElement(printTag);
    document.body.appendChild(instr);
    instr.options = { mode: 'instructor' };
    instr.model = JSON.parse(JSON.stringify(m));
  });
};

init()
  .then(() => {
    console.log('ready');
  })
  .catch((e) => {
    console.error(e);
  });
