// core and prism
import * as core from './_core.js';
import * as Prism from "../../node_modules/prismjs/prism";
import '../../node_modules/prismjs/components/prism-json';
import '../../node_modules/prismjs/components/prism-pug';
import '../../node_modules/prismjs/components/prism-sass';
import "../../node_modules/prismjs/plugins/toolbar/prism-toolbar";
import "../../node_modules/prismjs/plugins/line-numbers/prism-line-numbers";

// import pattern stuff.
import * as swtch from "../pg/patterns/components/switch-core/_switch.js";
import * as stickynote from "../pg/patterns/components/sticky-note-core/_sticky-note.js";
import * as tabs from "../pg/patterns/layouts/tabs-core/_tabs.js";

// init core
core.init({
	success: (a) => { 
		tabs.init(a);
		swtch.init(a);
		stickynote.init(a);
	},
	notFound: (a, path) => {
		a.innerHTML = `${a.innerHTML}<div class='notification-box error'><p>This pattern appears to be missing.<br><small>(${path} returned http status 404)</small></p></div>`;
	}
});






// handler for the deprecated switch

/*
// selectable content
jQuery.fn.OneClickSelect = function () {
	return jQuery(this).on('click', function () {
		// In here, "this" is the element
		var range, selection;
		if (window.getSelection) {
			selection = window.getSelection();
			range = document.createRange();
			range.selectNodeContents(this);
			selection.removeAllRanges();
			selection.addRange(range);
		} else if (document.body.createTextRange) {
			range = document.body.createTextRange();
			range.moveToElementText(this);
			range.select();
		}
	});
};
*/

jQuery(document).ready(function($){
	// show deprecated switch
	function flipDeprecated() {
		setTimeout(function(){
			if ($("#deprecated").attr("aria-checked") == "false") {
				$(".status-deprecated").closest("article").addClass("status-deprecated");
				core.cookie.set("show-deprecated", false, 30, "/");
			} else {
				$("article.status-deprecated").removeClass("status-deprecated");
				core.cookie.set("show-deprecated", true, 30, "/");
			}
		}, 50);
	}

	$("#deprecated").on("click", flipDeprecated).on("keypress", flipDeprecated);
	setTimeout( function() {
		if (core.cookie.get("show-deprecated") == "true") {
			$("#deprecated").attr("aria-checked", "true");
			flipDeprecated();
		}
	}, 200);
	console.log("hide deprecated", { "type": (typeof core.cookie.get("show-deprecated")), "value": core.cookie.get("show-deprecated") });
	// /hide deprecated switch

})

	// import("../pg/patterns/layouts/main-navigation/_main-navigation.js");