/* Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *	http://www.samsung.com/
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 * or just google for it.
 *
 * HTML report generator.
 * Written by Igor Zhbanov <i.zhbanov@samsung.com>
 * 2012.10 */

/* Uncomment to disable asserts */
/*#define NDEBUG*/

#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include <format>

#include "report-formatter-html.h"
#include "css.h" /* For HTML-report header */

/* ************************************************************************ */

#ifdef EXTERNAL_CSS_FILE /* Where is it defined? */
static const char report_html_alternative_head[] =
	"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
		"\"http://www.w3.org/TR/html4/loose.dtd\">\n"
	"<html>\n"
	"<head>\n"
	"<title>PowerTOP report</title>\n"
	"<link rel=\"stylesheet\" href=\"powertop.css\">\n"
	"</head>\n"
	"<body>\n";
#endif /* EXTERNAL_CSS_FILE */

/* ************************************************************************ */

static const char report_html_footer[] =
	"</body>\n"
	"</html>\n";

/* ************************************************************************ */

void
report_formatter_html::init_markup()
{
	/*here all html code*/
}

/* ************************************************************************ */

report_formatter_html::report_formatter_html()
{
	init_markup();
	add_doc_header();
}

/* ************************************************************************ */

void
report_formatter_html::finish_report()
{
	add_doc_footer();
}

/* ************************************************************************ */

void
report_formatter_html::add_doc_header()
{
#ifdef EXTERNAL_CSS_FILE /* Where is it defined? */
	add_exact(report_html_alternative_head);
#else /* !EXTERNAL_CSS_FILE */
	add_exact(css);
#endif /* !EXTERNAL_CSS_FILE */
}

/* ************************************************************************ */

void
report_formatter_html::add_doc_footer()
{
	add_exact(report_html_footer);
}

/* ************************************************************************ */
std::string
report_formatter_html::escape_string(const std::string &str)
{
	std::string res;

	for (size_t i = 0; i < str.length(); i++) {
		switch (str[i]) {
			case '<':
				res += "&lt;";
				continue;
			case '>':
				res += "&gt;";
				continue;
			case '&':
				res += "&amp;";
				continue;
#ifdef REPORT_HTML_ESCAPE_QUOTES
			case '"':
				res += "&quot;";
				continue;
			case '\'':
				res += "&apos;";
				continue;
#endif /* REPORT_HTML_ESCAPE_QUOTES */
		}

		res += str[i];
	}

	return res;
}


/* Report Style */
void
report_formatter_html::add_logo()
{
add_exact(std::format("<img alt=\"{}\" class=\"pwtop_logo\" src=\"data:image/png;base64,", escape_string(_("PowerTop"))));
	add_exact("iVBORw0KGgoAAAANSUhEUgAAAbQAAABDCAYAAAD01PBTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA"
		"GXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAGsxJREFUeNrsXQt4FNXZ/nLhmutq"
		"VdAKMXJHTMhiLGAuLUEfSg2xSFSUgIkkRPQ3QiHxqcRwswQrRq2EBKjhapvU3yCgtaQ+CRGUSyAB"
		"vNDfRhArqEA2FwjksvnPN0xokpnZPWd2dnd297w851kyt3OZ+c4773e+c8aro6MDODg4ODg4XB3e"
		"vAk4ODg4ODihcXBwcHBwcELj4ODg4ODQDr68CWxCrPgbTlJwj33l4m81SSbeVBwcHBz2hRcPCqEG"
		"ElaCSGKYBldXV4PJZILO325MF3uN68LDwyE4OLheJLjOVM2bk4ODg4MTmqMxB4mMENa08vJyKC0t"
		"FQispqaG+gKDBw8WiA1JLiEhAUJCQk6TzXkklZJ0ijcxBwcHByc0e6qxDEyExILy8vJgx44dml08"
		"LCwMMjIyBHIj6m0T2ZTDiY2Dwz3xzsEbM3tsWkV5ahVJJV3/fizyQhlvURsJzcvLaw/5iX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LPDHwwxK8UFl4Oj7dvz+Y"
		"/OScPXv2ubzXX4fKykqHlwFJ8sUXX4SIsWNryJ8J4ydMOMUfTw4O1wchuK7uV3wZoHXH9pxHVkUI"
		"jK+WwwmNDvv37YslP0VHjx4dvHHjRjhaXW33PP38/SAlOQWVWT2S6oSJE/P4neDg4ODghKYJ9n2y"
		"bw6SCxJbcXExVH6ivWJDRZacnAzRUdHg7+//OuY38b6JJt76HBwcHJzQNMcnlZVIbBnnzp0L21tZ"
		"Kbgiq21QbbcMuBmi74uGKVOm4NjbaVSDJOXdFxXFiYyDg4ODE5r9Ubl3bwj5QXLD9a7C0BVZffQo"
		"NDY1wddffy0c0yT+f8Att8AAcRFkorxg6JAhMIQkDB4hqgxJrJyk0qjo6FLeshwcHByc0JyGvRUV"
		"GEASTlIsSSFiQuD2MJJwLKxTxpnE/wspOibmFG9BDg4ODk5oHBwcHBwcivDmTcDBwcHB4Q74fwEG"
		"APNNNssrHc8WAAAAAElFTkSuQmCC\">");
}

void
report_formatter_html::add_header()
{
	add_exact("<header id=\"main_header\">\n");
}

void
report_formatter_html::end_header()
{
	add_exact("</header>\n\n");
}

void
report_formatter_html::add_div(const struct tag_attr *div_attr)
{
	std::string  empty="";

	if (div_attr->css_class == empty && div_attr->css_id == empty)
		add_exact("<div>\n");

	else if (div_attr->css_class == empty && div_attr->css_id != empty)
		add_exact(std::format("<div id=\"{}\">\n", div_attr->css_id));

	else if (div_attr->css_class != empty && div_attr->css_id == empty)
		add_exact(std::format("<div class=\"{}\">\n", div_attr->css_class));

	else if (div_attr->css_class != empty && div_attr->css_id != empty)
		add_exact(std::format("<div class=\"{}\" id=\"{}\">\n",
				div_attr->css_class, div_attr->css_id));
}

void
report_formatter_html::end_div()
{
	add_exact("</div>\n");
}

void
report_formatter_html::add_title(const struct tag_attr *title_att, const std::string &title)
{
	add_exact(std::format("<h2 class=\"{}\"> {} </h2>\n", title_att->css_class, escape_string(title)));
}

void
report_formatter_html::add_navigation()
{
	add_exact("<br/><div id=\"main_menu\"> </div>\n");
}

void
report_formatter_html::add_summary_list(const std::vector<std::string> &list)
{
	add_exact("<div><br/> <ul>\n");
	for (size_t i = 0; i + 1 < list.size(); i += 2) {
		add_exact(std::format("<li class=\"summary_list\"> <b> {} </b> {} </li>",
				escape_string(list[i]), escape_string(list[i+1])));
	}
	add_exact("</ul> </div> <br />\n");
}


void
report_formatter_html::add_table(const std::vector<std::string> &system_data, const struct table_attributes* tb_attr)
{
	int i, j;
	int offset=0;
	std::string  empty="";

	if (tb_attr->table_class == empty)
		add_exact("<table>\n");
	else
		add_exact(std::format("<table class=\"{}\">\n", tb_attr->table_class));

	for (i=0; i < tb_attr->rows; i++){
		if (tb_attr->tr_class == empty)
			add_exact("<tr> ");
		else
			add_exact(std::format("<tr class=\"{}\"> ", tb_attr->tr_class));

		for (j=0; j < tb_attr->cols; j++){
			offset = i * (tb_attr->cols) + j;

			if (offset >= (int)system_data.size())
				break;

std::string escaped_data = (system_data[offset] == "&nbsp;") ? system_data[offset] : escape_string(system_data[offset]);

			if (tb_attr->pos_table_title == T &&  i==0)
				add_exact(std::format("<th class=\"{}\"> {} </th> ",
				tb_attr->th_class, escaped_data));
			else if (tb_attr->pos_table_title == L &&  j==0)
				add_exact(std::format("<th class=\"{}\"> {} </th> ",
				tb_attr->th_class, escaped_data));
			else if (tb_attr->pos_table_title == TL && ( i==0 || j==0 ))
				add_exact(std::format("<th class=\"{}\"> {} </th> ",
				tb_attr->th_class, escaped_data));
			else if (tb_attr->pos_table_title == TC && ((i % tb_attr->title_mod ) == 0))
				add_exact(std::format("<th class=\"{}\"> {} </th> ", tb_attr->th_class,
					escaped_data));
			else if (tb_attr->pos_table_title == TLC && ((i % tb_attr->title_mod) == 0 || j==0))
				add_exact(std::format("<th class=\"{}\"> {} </th> ", tb_attr->th_class,
				escaped_data));
			else
				if ( tb_attr->td_class == empty)
					add_exact(std::format("<td > {} </td> ", escaped_data));
				else
					add_exact(std::format("<td class=\"{}\"> {} </td> ", tb_attr->td_class,
						escaped_data));
		}
		add_exact("</tr>\n");
	}
	add_exact("</table>\n");
}

