
# dependencies
Markdown = require './Markdown'

# value formatter
write = (item) ->
  return item if typeof item is 'string'
  return item if typeof item is 'number'
  return (write x for x in item).join ', ' if Array.isArray item
  item_name = item.name?.replace /\(/g, '&#40;'
  item_name = item_name?.replace /\)/g, '&#41;'
  if item.slug
    return "(#{item_name})->[/#{item.slug}]"
  else
    return "#{item_name}"

# template
module.exports = (obj) ->

  # create markdown content
  content = []
  for key, value of obj
    if typeof value is 'number' and not key.match /year/i
      value = value.toLocaleString()
    content.push "| **#{key}** | #{write value} |"
  content = content.join '\n'

  div '.key-value-table', ->
    Markdown content
