"use strict";

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

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

var _ = require(".");

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

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

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

/**
 * Write HTML file for Project Description
 * @param {object} project JSON data for project
 * @param {string} htmlSidebar sidebar html content
 * @param {string} outputPath target directory
 */
async function writeHtmlProjectDescription(project, htmlSidebar, outputPath) {
  if (!project) {
    return;
  }

  let {
    description,
    summary
  } = project;
  const {
    title
  } = project;
  const mediaFileLabel = 'project-desc';
  description = await (0, _utils2.createHtmlText)(description, outputPath, mediaFileLabel);
  summary = await (0, _utils2.createHtmlText)(summary, outputPath, mediaFileLabel); // create HTML body content

  const htmlSummary = summary ? `
    <p class="text-center">${summary}</p>

    <hr>
  ` : '';
  const contentMain = `
    ${htmlSummary}
    ${description}
  `; // decide how many folders it needs to go up to access the assets

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

  const templateDataIndex = {
    contentMain,
    docTitle: title || 'Project Description',
    sidebar: htmlSidebar,
    pathToAssets,
    title
  };
  let file = (0, _utils.filenamify)(`Project Description - ${title}.html`);
  file = _path.default.join(outputPath, file);

  try {
    await (0, _.writeHtml)(templateDataIndex, file);

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

    _utils.logger.info('____________________\n');
  } catch (error) {
    throw error;
  }
}