"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = writeHtmlRubric;

var _path = _interopRequireDefault(require("path"));

var _ = require(".");

var _utils = require("../../utils");

var _rubric = require("./rubric");

var _utils2 = require("./utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Create HTML file for a project rubric
 * @param {object} rubric JSON data for project rubric
 * @param {object} projectJSON JSON data for project (from lesson parent JSON key)
 * @param {string} htmlSidebar sidebar html content
 * @param {string} outputPath target directory
 */
async function writeHtmlRubric(rubric, projectJSON, htmlSidebar, outputPath) {
  const {
    sections
  } = rubric; // need to use the project title from projectJSON instead of from the rubric
  // This allow the Nanodegree and lesson summary pages to be able to link
  // to the correct file because they only have access to projectJSON object.

  const {
    title
  } = projectJSON; // create html rubric

  let htmlRubric = (0, _rubric.createHtmlRubricSections)(sections); // create html for standout tips if available

  if (rubric.stand_out) {
    const standout = await (0, _utils2.createHtmlText)(rubric.stand_out, outputPath, 'rubric-standout');
    htmlRubric += `
      <div class="jumbotron">
        <h3>Tips to make your project standout:</h3>
        <p>${standout}</p>
      </div>
    `;
  } // decide how many folders it needs to go up to access the assets


  const pathToAssets = '../'; // write html file

  const templateDataIndex = {
    contentMain: htmlRubric,
    docTitle: title,
    sidebar: htmlSidebar,
    pathToAssets,
    title
  };
  let file = (0, _utils.filenamify)(`Project Rubric - ${title}.html`);
  file = _path.default.join(outputPath, file);
  await (0, _.writeHtml)(templateDataIndex, file);

  _utils.logger.info(`Completed rendering rubric file ${file}`);

  _utils.logger.info('____________________\n');
}