function openLayer(field) {
    const layer = document.getElementById(`${field}_layer`);
    if (layer) layer.style.display = 'block';
}

function closeLayer(field) {
    const layer = document.getElementById(`${field}_layer`);
    if (layer) layer.style.display = 'none';
}

function addComponentFromLabel(field, value, text) {
    const listDiv = document.getElementById(`${field}_list`);
    if (!listDiv) return;

    const wrapper = document.createElement('div');
    wrapper.className = 'server_partinfo_item';

    const checkbox = document.createElement('input');
    checkbox.type = 'checkbox';
    checkbox.name = `${field}[]`;
    checkbox.value = value;
    checkbox.checked = true;

    // 체크 해제되면 해당 항목 삭제
    checkbox.addEventListener('change', () => {
        if (!checkbox.checked) {
            wrapper.remove();
        }
    });

    const label = document.createElement('label');
    label.textContent = text;
    label.style.marginLeft = '5px';

    wrapper.appendChild(checkbox);
    wrapper.appendChild(label);

    listDiv.appendChild(wrapper);
}

function openPartPopup(field) {
    window.open('/admin/equipment/part/popup?type=' + encodeURIComponent(field), 'PartPopup', 'width=800,height=500,scrollbars=yes');
}