/* tkpurchase-partner-portal.js - Partner portal logic (2-step flow) */ let portalSchedules = []; let portalRequests = []; let portalCheckins = {}; let partnerCompanyId = null; let companyWorkersCache = null; async function loadMySchedules() { try { const r = await api('/schedules/my'); const data = r.data || {}; portalSchedules = Array.isArray(data) ? data : (data.schedules || []); portalRequests = Array.isArray(data) ? [] : (data.requests || []); } catch(e) { console.warn('Load schedules error:', e); portalSchedules = []; portalRequests = []; } } async function loadMyCheckins() { try { const r = await api('/checkins/my'); const list = r.data || []; portalCheckins = {}; list.forEach(c => { if (c.schedule_id && !portalCheckins[c.schedule_id]) portalCheckins[c.schedule_id] = c; }); } catch(e) { console.warn('Load checkins error:', e); portalCheckins = {}; } } async function loadCompanyWorkers() { if (companyWorkersCache) return companyWorkersCache; try { const r = await api('/partners/' + partnerCompanyId + '/workers'); companyWorkersCache = (r.data || []).filter(w => w.is_active !== 0); return companyWorkersCache; } catch(e) { console.warn('Load workers error:', e); companyWorkersCache = []; return []; } } async function renderScheduleCards() { await Promise.all([loadMySchedules(), loadMyCheckins()]); const container = document.getElementById('scheduleCards'); const requestCardsEl = document.getElementById('requestCards'); const workRequestFormEl = document.getElementById('workRequestForm'); if (!portalSchedules.length) { container.innerHTML = ''; // 신청 건 표시 if (portalRequests.length) { requestCardsEl.classList.remove('hidden'); requestCardsEl.innerHTML = portalRequests.map(r => { const isRejected = r.status === 'rejected'; const statusBg = isRejected ? 'bg-red-50 border-red-200' : 'bg-amber-50 border-amber-200'; const statusIcon = isRejected ? 'fa-times-circle text-red-400' : 'fa-clock text-amber-400'; const statusText = isRejected ? '반려됨' : '승인 대기 중'; const statusTextClass = isRejected ? 'text-red-600' : 'text-amber-600'; return `
${escapeHtml(s.work_description)}
` : ''}