//-		DS2 core (c) 2024 Alexander McIlwraith 
//-		Core licensed under CC BY-SA 4.0 

extends ../../../core/_master-pattern
block content
	- 
	- let list = []
	- for(let i = 0; i < content.length; i++) {
	-	list.push({ "name": content[i].name, "core": (typeof content[i].core != 'undefined' && content[i].core ? 'true' : 'false'), "path": content[i].name, "status": content[i].status, "display": (content[i].hasOwnProperty("display") && content[i].display != "" ? content[i].display : content[i].name.toSentenceCase().toContent())  } )
	-	if (content[i].files != undefined) {
	-		for (let ii = 0; ii < content[i].files.length; ii++) {
	-			list.push({ "name": content[i].files[ii].name, "core": (typeof content[i].files[ii].core != 'undefined' && content[i].files[ii].core ? 'true' : 'false'), "path": content[i].name +"."+ content[i].files[ii].name, "status": content[i].files[ii].status, "display": (content[i].files[ii].hasOwnProperty("display") && content[i].files[ii].display != "" ? content[i].files[ii].display : content[i].files[ii].name.toSentenceCase().toContent()) } )
	-			if (content[i].files[ii].files != undefined) {
	-				for (let iii = 0; iii < content[i].files[ii].files.length; iii++) {
	-					list.push({ "name": content[i].files[ii].files[iii].name, "core": (typeof content[i].files[ii].files[iii].core != 'undefined' && content[i].files[ii].files[iii].core ? 'true' : 'false'), "path": content[i].name +"."+ content[i].files[ii].name + "." + content[i].files[ii].files[iii].name, "status": content[i].files[ii].files[iii].status, "display": (content[i].files[ii].files[iii].hasOwnProperty("display") && content[i].files[ii].files[iii].display != "" ? content[i].files[ii].files[iii].display : content[i].files[ii].files[iii].name.toSentenceCase().toContent()) } )
	-				}
	-			}
	-		}
	- 	}
	- }
	- list.sort((a, b) => {
	-	if (a.display < b.display) {
	-		return -1;
	-	}
	-	if (a.display > b.display) {
	-		return 1;
	-	}
	-	return 0;
	- });
	- function createURL(p) {
	-	p = p.split(".")
	// - 	return p.length
	- 	return "./?p=" + p[0] + (p.length >= 2 ? "/" + p[1] : "") + (p.length >= 3 ? "/" + p[2] : "") 
	- }
	- function getCategory(p) {
	-	p = p.split(".")
	// - 	return p.length
	- 	return (p.length > 1 ? p[0].toContent().toSentenceCase() : "") + (p.length > 2 ? " / " + p[1].toContent().toSentenceCase() : "") + (p.length > 3 ? " / " + p[2].toContent().toSentenceCase() : "") 
	- }
	- function getCount(obj) {
	-	console.log(obj.name)
	-	let count = 0;
	-	if (obj.files != undefined) {
	-		for(let i=0; i<obj.files.length; i++) {
	-			count = count + getCount(obj.files[i])
	-		}
	-	}
	-	count++;
	-	return count;
	- }

	div.tab-group#status-report
		div.status-report.status-report-structure(data-tab="by&nbsp;structure")
			table.custom(role="presentation")
				tbody 
					each category in content
						tr
							td(colspan="2")= category.name.toContent().toSentenceCase() + " (" +  getCount(category) + ")"
						tr
							td
								a(href="./?p=" + category.name) 
									if category.display
										| !{category.display}
									else 
										| !{category.name.toContent().toSentenceCase()}
							td
								if typeof category.core && category.core 
									span.status-complete Complete (Core)
								else 
									span(class="status-" + category.status)= category.status.toContent().toSentenceCase()
							
							
							if category.files
								each pattern in category.files
									tr
										td
											a(href="./?p=" + category.name + "/" + pattern.name ) 
												if pattern.display
													| !{pattern.display}
												else 
													| !{pattern.name.toContent().toSentenceCase()}
										td
											if typeof pattern.core && pattern.core 
												span.status-complete Complete (Core)
											else 
												span(class="status-" + pattern.status)= pattern.status.toContent().toSentenceCase()
										
									if pattern.files
										
										each sub in pattern.files
											tr
												td.indent
													a(href="./?p=" + category.name + "/" + pattern.name + "/" + sub.name )
														if sub.display
															| !{sub.display}
														else 
															| !{sub.name.toContent().toSentenceCase()}
												td
													if typeof sub.core && sub.core 
														span.status-complete Complete (Core)
													else 
														span(class="status-" + sub.status)= sub.status.toContent().toSentenceCase()

		div.status-report.status-report-status(data-tab="by&nbsp;status")
			table(role="presentation")
				tbody
					- bystatus = list;
					- for(i=0; i < bystatus.length; i++) {
					-	if (bystatus[i].core == "true") {
					- 		bystatus[i].status = "complete"
					-	}
					- }
					each status in statuses || []
						- out = bystatus.filter(list => list.status === status.name)
						tr 
							td(colspan="2")
								span(class="status-" + status.name)= status.name.toContent().toSentenceCase() + " (" + out.length + ")"

						each item in out
							tr 
								td 
									a(href= createURL(item.path) )
										if item.display
											| !{item.display}
										else 
											| !{item.name.toContent().toSentenceCase()}
								td
									if item.core == "true"
										span (core)
								td= getCategory(item.path)

		div.status-report.status-report-alpha(data-tab="alphabetical")
			table(role="presentation")
				tbody 
					each item in list
						tr 
							td 
								a(href= createURL(item.path) )
									if item.display
										| !{item.display}
									else 
										| !{item.name.toContent().toSentenceCase()}
							td
								span 
									if item.core == "true"
										span.status-complete Complete (Core)
									else 
										span(class="status-" + item.status)= item.status.toContent().toTitleCase()
							td= getCategory(item.path)

