'use strict'

var dateformat = require('dateformat')

var days = { 'Monday': 'Lundi', 'Tuesday': 'Mardi', 'Wednesday': 'Mercredi', 'Thursday': 'Jeudi', 'Friday': 'Vendredi', 'Saturday': 'Samedi', 'Sunday': 'Dimanche' }

var months = { 'January': 'Janvier', 'February': 'Février', 'March': 'Mars', 'April': 'Avril', 'May': 'Mai', 'June': 'Juin', 'July': 'Juillet', 'August': 'Août', 'September': 'Septembre', 'October': 'Octobre', 'November': 'November', 'December': 'Decembre' }

module.exports = DateTimeMenuItem

/**
 * @class
 * @param {string} mask
 */
function DateTimeMenuItem (mask) {
  this.text = this.format(mask)
  this.mask = mask
  this.title = mask
  this.setId()
}

/**
 * @method
 * @param {DOMElement} element
 */
DateTimeMenuItem.prototype.setElement = function ($element) {
  this.node = $element[0]
  console.log(this.node)
}

DateTimeMenuItem.prototype.PREFIX_ID = 'dynamicdate-'

DateTimeMenuItem.prototype.setId = function () {
  var id = (this.PREFIX_ID + this.mask)
    .replace(/ /gi, '-space-')
    .replace(/\//gi, '-slash-')
    .replace(/:/gi, '-dots-')
    .replace(/,/gi, '-comma-')
    .replace(/'/gi, '-singlequote-')
  this.id = id
}

DateTimeMenuItem.prototype.format = function (mask) {
  var now = new Date()
  var formatted = dateformat(now, mask)
  // replace english days by french days
  for (var enDay in days) {
    var frDay = days[enDay]
    formatted = formatted.replace(enDay, frDay)
  }
  // replace english months by french ones
  for (var enMonth in months) {
    var frMonth = months[enMonth]
    formatted = formatted.replace(enMonth, frMonth)
  }
  return formatted
}

@@ -1,8 +1,108 @@
+/**%0A * @module DateTimeMenuItem%0A * @description This module exports the DateTimeMenuItem class%0A */%0A%0A
 'use str
@@ -608,24 +608,87 @@
 nuItem%0A%0A/**%0A
+ * This class instances permit to manage the plugin menu items%0A
  * @class%0A *
@@ -848,221 +848,558 @@
 %0A * 
-@method%0A * @param %7BDOMElement%7D element%0A */%0ADateTimeMenuItem.prototype.setElement = function ($element) %7B%0A  this.node = $element%5B0%5D%0A  console.log(this.node)%0A%7D%0A%0ADateTimeMenuItem.prototype.PREFIX_ID = 'dynamicdate-'%0A
+Set an menu item element to its object instance%0A * @method%0A * @param %7BDOMElement%7D element The element to set to its object instance (as a jquery set of one element)%0A * @returns %7Bundefined%7D%0A */%0ADateTimeMenuItem.prototype.setElement = function ($element) %7B%0A  this.node = $element%5B0%5D%0A%7D%0A%0A/**%0A * Shared prefix for all menu item element's id%0A * @constant%0A * @static%0A */%0ADateTimeMenuItem.prototype.PREFIX_ID = 'dynamicdate-'%0A%0A/**%0A * Computes and encodes the id for the menu item element, then set it in the id property%0A * @method%0A * @returns %7Bundefined%7D%0A */
 %0ADat
@@ -1663,16 +1663,207 @@
 = id%0A%7D%0A%0A
+/**%0A * Formats and translate in french a new date against the given date mask%0A * @method%0A * @param %7Bstring%7D mask The given mask%0A * @returns %7Bstring%7D the mask-formated now-date, in french%0A */%0A
 DateTime

document DateTimeMenuItem