"use strict";

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

var _handlebars = _interopRequireDefault(require("handlebars"));

var _templates = require("../templates");

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

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

/**
 * Download youtube video and and create HTML for it
 * @param {string} videoId Youtube video id to construct download url
 * @param {string} outputPath directory to save the file
 * @param {string} prefix file prefix
 * @param {string} title title of atom
 */
async function createHtmlVideo(videoId, outputPath, prefix, title) {
  let video;

  try {
    video = await (0, _utils.downloadYoutube)(videoId, outputPath, prefix, title);
  } catch (error) {
    throw error;
  }

  if (!video) return '';
  const html = await (0, _templates.loadTemplate)('atom.video');
  const data = {
    video
  };

  const template = _handlebars.default.compile(html);

  return template(data);
}