${escapeHtml(row.establishment || "بدون اسم منشأة")}
${escapeHtml(row.statusMain || "-")}
${escapeHtml(row.statusOther || "-")}
${escapeHtml(row.survey || "بدون اسم مسح")}const rawRows = Array.isArray(window.DATA) ? window.DATA : []; const selectors = { total: document.getElementById("totalCount"), researchers: document.getElementById("researcherCount"), inspectors: document.getElementById("inspectorCount"), tabs: document.querySelectorAll(".modeTab"), panels: document.querySelectorAll(".searchPanel"), researcherInput: document.getElementById("researcherInput"), researcherSelect: document.getElementById("researcherSelect"), inspectorGrid: document.getElementById("inspectorGrid"), inspectorResearcherSelect: document.getElementById("inspectorResearcherSelect"), resultEyebrow: document.getElementById("resultEyebrow"), resultTitle: document.getElementById("resultTitle"), resultCount: document.getElementById("resultCount"), results: document.getElementById("results"), }; let selectedInspector = ""; function clean(value) { return String(value ?? "").trim(); } function normalizeArabic(value) { return clean(value) .toLowerCase() .replace(/[\u064B-\u065F\u0670\u06D6-\u06ED]/g, "") .replace(/\u0640/g, "") .replace(/[إأآٱ]/g, "ا") .replace(/ى/g, "ي") .replace(/ة/g, "ه") .replace(/\s+/g, " "); } function valueOf(row, keys, index) { if (Array.isArray(row)) return clean(row[index]); for (const key of keys) { if (row && Object.prototype.hasOwnProperty.call(row, key)) return clean(row[key]); } return ""; } function mapRow(row) { return { establishment: valueOf(row, ["establishment", "name", "sample", "اسم المنشأة", "إسم المنشأة"], 0), statusMain: valueOf(row, ["statusMain", "status_b", "b", "حالة العينة في المسح", "حالة العينة في المسح "], 1), statusOther: valueOf(row, ["statusOther", "status_c", "c", "حالة العينة في مسح اخر", "حالة العينة في مسح آخر"], 2), survey: valueOf(row, ["survey", "surveyName", "اسم المسح"], 3), researcher: valueOf(row, ["researcher", "researcherName", "اسم الباحث الحالي", "اسم الباحث"], 4), inspector: valueOf(row, ["inspector", "inspectorName", "المفتش", "اسم المفتش"], 5), }; } function unique(values) { return [...new Set(values.filter(Boolean))].sort((a, b) => a.localeCompare(b, "ar")); } function escapeHtml(value) { return clean(value) .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """) .replaceAll("'", "'"); } function optionHtml(value) { return ``; } const rows = rawRows .map(mapRow) .filter((row) => normalizeArabic(row.statusMain) !== normalizeArabic(row.statusOther)); const researchers = unique(rows.map((row) => row.researcher)); const inspectors = unique(rows.map((row) => row.inspector)); selectors.total.textContent = rows.length; selectors.researchers.textContent = researchers.length; selectors.inspectors.textContent = inspectors.length; function setMode(mode) { selectors.tabs.forEach((tab) => { const active = tab.dataset.mode === mode; tab.classList.toggle("active", active); tab.setAttribute("aria-selected", String(active)); }); selectors.panels.forEach((panel) => panel.classList.toggle("active", panel.id === `${mode}Panel`)); if (mode === "researcher") selectors.researcherInput.focus(); } function byResearcher(query, sourceRows = rows) { const tokens = normalizeArabic(query).split(" ").filter(Boolean); if (!tokens.length) return []; return sourceRows.filter((row) => { const name = normalizeArabic(row.researcher); return tokens.every((token) => name.includes(token)); }); } function byInspector(name) { const target = normalizeArabic(name); return rows.filter((row) => normalizeArabic(row.inspector) === target); } function renderControls() { selectors.researcherSelect.innerHTML = `${researchers.map(optionHtml).join("")}`; selectors.inspectorGrid.innerHTML = inspectors.map((name) => ( `` )).join(""); } function renderInspectorResearchers(inspectorName) { const list = byInspector(inspectorName); const names = unique(list.map((row) => row.researcher)); selectors.inspectorResearcherSelect.disabled = names.length === 0; selectors.inspectorResearcherSelect.innerHTML = `${names.map(optionHtml).join("")}`; } function renderResults(list, title, eyebrow = "النتائج") { selectors.resultEyebrow.textContent = eyebrow; selectors.resultTitle.textContent = title; selectors.resultCount.textContent = list.length; if (!list.length) { selectors.results.innerHTML = `
${escapeHtml(row.statusMain || "-")}
${escapeHtml(row.statusOther || "-")}
${escapeHtml(row.survey || "بدون اسم مسح")}