<commit_before>'use strict';
var _ = require('lodash'),
  moment = require('moment'),
  dom = require('./dom'),
  ds = require('dollar-slice'),
  state = require('./page-state'),
  paneController = require('../controllers/pane'),
  publishPaneController = require('../controllers/publish-pane');

/**
 * create pane
 * @param {string} header
 * @param {Element|DocumentFragment} innerEl
 * @returns {Element}
 */
function createPane(header, innerEl) {
  var template = dom.find('.kiln-pane-template'),
    el = document.importNode(template.content, true);

  // add header and contents
  el.querySelector('.pane-header').innerHTML = header;
  el.querySelector('.pane-inner').appendChild(innerEl);

  return el;
}

/**
 * close an open pane
 */
function close() {
  var pane  = dom.find('.kiln-toolbar-pane-background');

  if (pane) {
    dom.removeElement(pane);
  }
}

/**
 * open a pane
 * @param {string} header will display at the top of the pane, html accepted
 * @param {Element} innerEl will display inside the pane
 * @returns {Element} pane
 */
function open(header, innerEl) {
  var toolbar = dom.find('.kiln-toolbar'),
    el = createPane(header, innerEl),
    pane;

  close(); // close any other panes before opening a new one
  dom.insertBefore(toolbar, el);
  pane = toolbar.previousElementSibling; // now grab a reference to the dom
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', pane);
  // trick browser into doing a repaint, to force the animation
  setTimeout(function () { dom.find(pane, '.kiln-toolbar-pane').classList.add('on'); }, 0);
  return pane;
}

/**
 * create messages for the publish pane, depending on the state
 * @param {object} res
 * @returns {Element}
 */
function createPublishMessages(res) {
  var messages = dom.create('<div class="messages"></div>'),
    draftMessage = dom.create('<p>In Draft.</p>'),
    effectMessage = dom.create('<p>Changes you make outside of the article will also be published.</p>');

  // add messages (in order)
  if (res.published) {
    // published message
    messages.appendChild(dom.create(`<p>Published ${state.formatTime(res.publishedAt)}</p>`)); // todo: get published time
  } else {
    messages.appendChild(draftMessage);
  }

  if (res.scheduled) {
    // scheduled message
    messages.appendChild(dom.create(`<p>This is scheduled to publish ${state.formatTime(res.scheduledAt)}.</p>`));
  }

  // message about what publishing affects
  messages.appendChild(effectMessage);

  return messages;
}

/**
 * create actions for the publish pane, depending on the state
 * @param {object} res
 * @returns {Element}
 */
function createPublishActions(res) {
  var today = moment().format('YYYY-MM-DD'),
    now = moment().format('HH:mm'),<commit_msg>fixed language<commit_after>'use strict';
var _ = require('lodash'),
  moment = require('moment'),
  dom = require('./dom'),
  ds = require('dollar-slice'),
  state = require('./page-state'),
  paneController = require('../controllers/pane'),
  publishPaneController = require('../controllers/publish-pane');

/**
 * create pane
 * @param {string} header
 * @param {Element|DocumentFragment} innerEl
 * @returns {Element}
 */
function createPane(header, innerEl) {
  var template = dom.find('.kiln-pane-template'),
    el = document.importNode(template.content, true);

  // add header and contents
  el.querySelector('.pane-header').innerHTML = header;
  el.querySelector('.pane-inner').appendChild(innerEl);

  return el;
}

/**
 * close an open pane
 */
function close() {
  var pane  = dom.find('.kiln-toolbar-pane-background');

  if (pane) {
    dom.removeElement(pane);
  }
}

/**
 * open a pane
 * @param {string} header will display at the top of the pane, html accepted
 * @param {Element} innerEl will display inside the pane
 * @returns {Element} pane
 */
function open(header, innerEl) {
  var toolbar = dom.find('.kiln-toolbar'),
    el = createPane(header, innerEl),
    pane;

  close(); // close any other panes before opening a new one
  dom.insertBefore(toolbar, el);
  pane = toolbar.previousElementSibling; // now grab a reference to the dom
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', pane);
  // trick browser into doing a repaint, to force the animation
  setTimeout(function () { dom.find(pane, '.kiln-toolbar-pane').classList.add('on'); }, 0);
  return pane;
}

/**
 * create messages for the publish pane, depending on the state
 * @param {object} res
 * @returns {Element}
 */
function createPublishMessages(res) {
  var messages = dom.create('<div class="messages"></div>'),
    draftMessage = dom.create('<p>In Draft.</p>'),
    effectMessage = dom.create('<p>Changes you make outside of the article will also be published.</p>');

  // add messages (in order)
  if (res.published) {
    // published message
    messages.appendChild(dom.create(`<p>Published ${state.formatTime(res.publishedAt)}</p>`)); // todo: get published time
  } else {
    messages.appendChild(draftMessage);
  }

  if (res.scheduled) {
    // scheduled message
    messages.appendChild(dom.create(`<p>Scheduled to publish ${state.formatTime(res.scheduledAt)}.</p>`));
  }

  // message about what publishing affects
  messages.appendChild(effectMessage);

  return messages;
}

/**
 * create actions for the publish pane, depending on the state
 * @param {object} res
 * @returns {Element}
 */
function createPublishActions(res) {
  var today = moment().format('YYYY-MM-DD'),
    now = moment().format('HH:mm'),
{'fraction_non_alphanumeric': 0.155343305100018, 'fraction_numerical': 0.0003604253018561903, 'mean_word_length': 3.9377224199288254, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6463823', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1648, 'n_words': 460}