xhiveframework.provide("xhiveframework.ui.misc");
xhiveframework.ui.misc.about = function () {
	if (!xhiveframework.ui.misc.about_dialog) {
		var d = new xhiveframework.ui.Dialog({ title: __("Xhive 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.com' target='_blank'>https://xhiveframework.com</a></p>
					<p><i class='fa fa-github fa-fw'></i>
						${__("Source")}:
						<a href='https://lab.membtech.com/xhiveframework' target='_blank'>https://lab.membtech.com/xhiveframework</a></p>
					<p><i class='fa fa-graduation-cap fa-fw'></i>
						XhiveFramework School: <a href='https://xhiveframework.school' target='_blank'>https://xhiveframework.school</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-twitter fa-fw'></i>
						Twitter: <a href='https://twitter.com/xhiveframeworktech' target='_blank'>https://twitter.com/xhiveframeworktech</a></p>
					<p><i class='fa fa-youtube fa-fw'></i>
						YouTube: <a href='https://www.xhiveerp.com/@xhiveframeworktech' target='_blank'>https://www.xhiveerp.com/@xhiveframeworktech</a></p>
					<hr>
					<h4>${__("Installed Apps")}</h4>
					<div id='about-app-versions'>${__("Loading versions...")}</div>
					<hr>
					<p class='text-muted'>${__("&copy; XhiveFramework Technologies Pvt. 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];
				let text;
				if (v.branch) {
					text = $.format("<p><b>{0}:</b> v{1} ({2})<br></p>", [
						v.title,
						v.branch_version || v.version,
						v.branch,
					]);
				} else {
					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();
};
