/**
 * 크로스시스템 네비게이션 배너
 * tkreport 페이지 상단에 시스템 간 이동 링크를 제공
 */
document.addEventListener('DOMContentLoaded', function() {
    var path = window.location.pathname;
    var host = window.location.hostname;
    var protocol = window.location.protocol;

    // tkqc URL 결정
    var tkqcUrl;
    if (host.includes('technicalkorea.net')) {
        tkqcUrl = protocol + '//tkqc.technicalkorea.net';
    } else {
        tkqcUrl = protocol + '//' + host + ':30200';
    }

    // 현재 페이지 판별
    var isIssueReport = path.includes('issue-report');
    var isReportStatus = path.includes('report-status');
    var isChatReport = path.includes('chat-report');

    var nav = document.createElement('div');
    nav.id = 'crossNav';
    nav.innerHTML =
        '<a href="/pages/safety/issue-report.html" class="cn-link' + (isIssueReport ? ' cn-active' : '') + '">신고하기</a>' +
        '<a href="/pages/safety/report-status.html" class="cn-link' + (isReportStatus ? ' cn-active' : '') + '">신고현황</a>' +
        '<a href="/pages/safety/chat-report.html" class="cn-link' + (isChatReport ? ' cn-active' : '') + '">AI 도우미</a>' +
        '<a href="' + tkqcUrl + '" class="cn-link cn-external">부적합관리(TKQC) &rarr;</a>';

    var style = document.createElement('style');
    style.textContent =
        '#crossNav{display:flex;align-items:center;gap:0.25rem;padding:0.5rem 0.75rem;background:#1e293b;overflow-x:auto;-webkit-overflow-scrolling:touch;}' +
        '.cn-link{color:rgba(255,255,255,0.7);text-decoration:none;font-size:0.8125rem;font-weight:500;padding:0.25rem 0.625rem;border-radius:0.375rem;white-space:nowrap;transition:background 0.15s,color 0.15s;-webkit-tap-highlight-color:transparent;}' +
        '.cn-link:hover,.cn-link:active{color:#fff;background:rgba(255,255,255,0.1);}' +
        '.cn-active{color:#fff !important;background:rgba(255,255,255,0.15) !important;font-weight:600;}' +
        '.cn-external{margin-left:auto;color:#38bdf8;border:1px solid rgba(56,189,248,0.3);font-size:0.75rem;}' +
        '.cn-external:hover,.cn-external:active{background:rgba(56,189,248,0.15);color:#7dd3fc;}';

    document.head.appendChild(style);
    document.body.insertBefore(nav, document.body.firstChild);
});
