#!/usr/bin/env ruby
require 'json'

# JSON file needs Emojibase-formatted entries, see https://emojibase.dev
# Also see customizer.rb in this directory.

if ARGV.length < 2
  puts "
  Usage:
    make-contact-sheet.rb <json input file> <html_output file>

  Examples:
    make-contact-sheet.rb emojibase.pretty.json full-sheet.html
    make-contact-sheet.rb custom.json custom-sheet.html
"
  exit 1
end

fjson = ARGV[0]
fhtml = ARGV[1]

json = File.read(fjson)
list = JSON.parse(json)

html = File.open(fhtml,'w');
html.puts '<html><head><meta charset="utf-8"></head>'
html.puts '<body>'
html.puts "<h1>#{list.length} emoji</h1>"

# Print stats for the custom set
stats_txt = `ruby getstats.rb #{fjson}`
html.puts "<pre>#{stats_txt}</pre>"

# Now print the emoji by group
group = nil
group_style='style="background:#FAA;font-weight:bold;"'
list.each do |e|
  if e['group'] != group
    group = e['group']
    html.puts "<br><span #{group_style}}>Group #{group}:</span> "
  end
  html.puts "<span title=\"#{e['label']}\">#{e['emoji']}</span>"
end

html.puts "</body></html>"
html.close

puts "Wrote #{list.length} emoji to #{fhtml}."
