function deleteManagementGroup()

in script.js [939:959]


  function deleteManagementGroup() {
    if (!selectedMgId || !currentData) return;

    // Check if there are any child management groups
    const hasChildren = currentData.management_groups.some(mg => mg.parent_id === selectedMgId);
    if (hasChildren) {
      alert('Cannot delete a management group with children. Please reassign or delete the children first.');
      return;
    }

    // Remove the management group
    currentData.management_groups = currentData.management_groups.filter(mg => mg.id !== selectedMgId);

    // Reset selection
    selectedMgId = null;
    noSelection.style.display = 'block';
    editForm.style.display = 'none';

    renderManagementGroups();
    updateJsonPreview();
  }