xhiveframework.provide("xhiveframework.ui.misc");
xhiveframework.ui.misc.about = function () {
	if (!xhiveframework.ui.misc.about_dialog) {
		var d = new xhiveframework.ui.Dialog({ title: __("XhiveFramework Framework") });

		$(d.body).html(
			repl(
				"<div>\
		<p>" +
					__("Open Source Applications for the Web") +
					"</p>  \
		<p><i class='fa fa-globe fa-fw'></i>\
			Website: <a href='https://xhiveframework.co' target='_blank'>https://xhiveframework.co</a></p>\
		<p><i class='fa fa-github fa-fw'></i>\
			Source: <a href='https://github.com/xhiveframework' target='_blank'>https://github.com/xhiveframework</a></p>\
		<p><i class='fa fa-linkedin fa-fw'></i>\
			Linkedin: <a href='https://linkedin.com/company/xhiveframework-tech' target='_blank'>https://linkedin.com/company/xhiveframework-tech</a></p>\
		<p><i class='fa fa-facebook fa-fw'></i>\
			Facebook: <a href='https://facebook.com/xhiveerp' target='_blank'>https://facebook.com/xhiveerp</a></p>\
		<p><i class='fa fa-twitter fa-fw'></i>\
			Twitter: <a href='https://twitter.com/xhiveerp' target='_blank'>https://twitter.com/xhiveerp</a></p>\
		<hr>\
		<h4>Installed Apps</h4>\
		<div id='about-app-versions'>Loading versions...</div>\
		<hr>\
		<p class='text-muted'>&copy; Xhive Global Ltd. and contributors </p> \
		</div>",
				xhiveframework.app
			)
		);

		xhiveframework.ui.misc.about_dialog = d;

		xhiveframework.ui.misc.about_dialog.on_page_show = function () {
			if (!xhiveframework.versions) {
				xhiveframework.call({
					method: "xhiveframework.utils.change_log.get_versions",
					callback: function (r) {
						show_versions(r.message);
					},
				});
			} else {
				show_versions(xhiveframework.versions);
			}
		};

		var show_versions = function (versions) {
			var $wrap = $("#about-app-versions").empty();
			$.each(Object.keys(versions).sort(), function (i, key) {
				var v = versions[key];
				if (v.branch) {
					var text = $.format("<p><b>{0}:</b> v{1} ({2})<br></p>", [
						v.title,
						v.branch_version || v.version,
						v.branch,
					]);
				} else {
					var text = $.format("<p><b>{0}:</b> v{1}<br></p>", [v.title, v.version]);
				}
				$(text).appendTo($wrap);
			});

			xhiveframework.versions = versions;
		};
	}

	xhiveframework.ui.misc.about_dialog.show();
};
