import PrintElement from './print.js';

var generate = {};

generate.model = (id, element) => ({
  id,
  element,
  points: ['nothing right', 'a teeny bit right', 'mostly right', 'bingo'],
  sampleAnswers: [null, 'just right', 'not left', null],
  maxPoints: 3,
  excludeZero: false,
});

const { model } = generate;

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

// 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);
  });
