(function() { var cfg = document.getElementById('tab-project-code-cfg'); var projectId = cfg.dataset.projectId; var projectSlug = cfg.dataset.projectSlug; var btn = document.getElementById('link-repo-btn'); var sel = document.getElementById('link-repo-select'); if (!btn || !sel) return; btn.addEventListener('click', function() { var name = sel.value; if (!name) return; fetch('/api/projects/' + projectId + '/repos', { method: 'POST', headers: {'Content-Type': 'application/json', ...csrfHeaders()}, body: JSON.stringify({name: name}) }).then(function() { htmx.ajax('GET', '/dashboard/project/' + projectSlug + '/tabs/code', {target: '#tab-content', swap: 'innerHTML'}); }).catch(function() { var status = document.getElementById('create-repo-status'); if (status) { status.textContent = 'Failed to link repository. Please try again.'; status.classList.add('is-error'); } }); }); })();