(function(){ // ============================================================ // start.jsx — StartTab (Heute / Dashboard) // Depends on window: parseDuration, cleanTitle, localISO, todayISO, // hexToRgba, prioCol, Spinner // ============================================================ const {useState, useEffect} = React; function StartTab({ nonDeletedTodos, activeTodos, data, isMobile, today, clock, aiGreeting, settings, dashQuick, setDashQuick, setData, setTab, freeCalEvents, nonDeletedExams, upcomingExams, todayStudyBlocks, studyTimer, setStudyTimer, startStudyTimer, pauseStudyTimer, resumeStudyTimer, stopStudyTimer, examColor, fmtMs, toggleRefresh, activeTimerId, activeTimerElapsed, startTimer, stopTimer, studyBlockIds, updateHabit, setPlanMode, setPlanFocusDate, focusMode, setFocusMode, onOpenPip }){ const {parseDuration, cleanTitle, localISO, todayISO, hexToRgba, prioCol, t, tList, GREETINGS_TR} = window; const dateLocale = window.currentLang==="en" ? "en-GB" : "de-CH"; const hour=new Date().getHours(); const openCount=nonDeletedTodos.filter(t=>!t.done&&!t.recurring).length; const todayCount=activeTodos.length; const next7days=Array.from({length:7},(_,i)=>{const d=new Date();d.setDate(d.getDate()+i);return localISO(d);}); const deadlineCount=nonDeletedTodos.filter(t=>!t.done&&!t.recurring&&t.deadline&&next7days.includes(t.deadline)).length; const upcomingDeadlines=nonDeletedTodos.filter(t=>!t.done&&t.deadline&&t.deadline>=todayISO()).sort((a,b)=>a.deadline>b.deadline?1:-1).slice(0,6); const weekDays=Array.from({length:7},(_,i)=>{ const d=new Date();const dow=d.getDay()||7;d.setDate(d.getDate()-dow+1+i);const iso=localISO(d); const deadlines=nonDeletedTodos.filter(t=>!t.done&&t.deadline===iso).length; const tasks=nonDeletedTodos.filter(t=>!t.done&&!t.recurring&&t.plannedDay===iso&&t.deadline!==iso).length; const events=freeCalEvents.filter(e=>e.start?.dateTime?.slice(0,10)===iso).length; return{iso,label:[t("week.mon"),t("week.tue"),t("week.wed"),t("week.thu"),t("week.fri"),t("week.sat"),t("week.sun")][i],day:d.getDate(),isToday:iso===todayISO(),deadlines,tasks,events,count:deadlines+tasks+events}; }); const noteKey="planer_daynote_"+(getAuthUsername()||"")+"_"+todayISO(); // FIXED L2: daynote key user-scoped const[dayNote,setDayNote]=useState(()=>{try{return localStorage.getItem("planer_daynote_"+(getAuthUsername()||"")+"_"+todayISO())||"";}catch{return "";}}); useEffect(()=>{try{setDayNote(localStorage.getItem(noteKey)||"");}catch{}},[noteKey]); function dashAddTodo(){ if(!dashQuick.trim())return; const dur=parseDuration(dashQuick); const txt=dur?cleanTitle(dashQuick):dashQuick.trim(); const todo={id:Date.now(),createdAt:Date.now(),updatedAt:Date.now(),text:txt,done:false,priority:"mittel",plannedDay:todayISO(),deadline:null,category:null,subcategory:null,subtasks:[],comments:[],duration:dur,recurring:null}; setData(d=>({...d,todos:[...d.todos,todo]})); setDashQuick(""); } return(
{/* Editorial hero */}
{clock.toLocaleDateString(dateLocale,{weekday:"long",day:"numeric",month:"long",year:"numeric"})}
{clock.toLocaleTimeString(dateLocale,{hour:"2-digit",minute:"2-digit"})}
{hour<5?t("hero.night"):hour<12?t("hero.morning"):hour<13?t("hero.noon"):hour<17?t("hero.afternoon"):t("hero.evening")}{settings.name?` · ${settings.name}`:""}
{aiGreeting?tList(GREETINGS_TR,aiGreeting.period,aiGreeting.idx):(hour<5?t("hero.fallback.night"):hour<12?t("hero.fallback.morning"):hour<17?t("hero.fallback.afternoon"):t("hero.fallback.evening"))}
{[{n:openCount,l:t("hero.open")},{n:todayCount,l:t("hero.dueToday")},{n:deadlineCount,l:t("hero.deadlines7d")}].map((s,i)=>(
{s.n}
{s.l}
))}
{/* Quick Add */}
setDashQuick(e.target.value)} onKeyDown={e=>e.key==="Enter"&&dashAddTodo()} style={{flex:1,fontSize:14,border:"none",background:"transparent",outline:"none",color:"var(--col-text)",fontFamily:"var(--serif)",fontStyle:"italic",padding:0,overflowX:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}/>{/* FIXED E4: quick-add input overflow handled */}
{/* 2-Column Grid */}
{/* Heute Todos */}
{t("today.title")}
{activeTodos.length===0&&

{t("today.empty")}

} {activeTodos.slice(0,6).map(t=>{ const isTA=String(activeTimerId)===String(t.id); const tMs=isTA?activeTimerElapsed:(t.timeLog||[]).reduce((sum,e)=>{const end=e.end||e.start;return sum+(end-e.start);},0); const fmtT=ms=>{const s=Math.floor(ms/1000),h=Math.floor(s/3600),m=Math.floor((s%3600)/60),sc=s%60;return h>0?`${h}:${String(m).padStart(2,'0')}:${String(sc).padStart(2,'0')}`:`${m}:${String(sc).padStart(2,'0')}`;}; return(
}
); })} {activeTodos.length>6&&
setTab("todos")} className="mono" style={{fontSize:10,color:"var(--col-text-3)",cursor:"pointer",letterSpacing:"0.06em",marginTop:8}}>+{activeTodos.length-6} {t("common.more")}
} {openCount>activeTodos.length&&
setTab("todos")} className="mono" style={{fontSize:10,color:"var(--col-text-3)",marginTop:8,letterSpacing:"0.04em",cursor:"pointer"}}>{t("today.laterDays",{n:openCount-activeTodos.length})}
}
{/* Upcoming Deadlines */}
{t("deadlines.title")}
{upcomingDeadlines.length===0&&

{t("deadlines.empty")}

} {upcomingDeadlines.map(td=>{ const daysLeft=Math.round((new Date(td.deadline+"T12:00:00")-new Date(todayISO()+"T12:00:00"))/86400000); const urgent=daysLeft<=2; return(
{td.text} {daysLeft===0?t("deadlines.today"):daysLeft===1?t("deadlines.tomorrow"):t("deadlines.daysShort",{n:daysLeft})}
); })}
{/* Prüfungs-Erinnerungen */} {upcomingExams.length>0&&(
{upcomingExams.map(e=>{ const urgent=e.daysLeft<=2; const ec=examColor(e); return(
setTab("pruefung")} style={{display:"flex",alignItems:"center",gap:12,padding:"10px 14px",borderRadius:8,background:urgent?hexToRgba(ec,0.08):"var(--col-bg)",border:`1px solid ${urgent?ec:"var(--col-border-soft)"}`,borderLeft:`4px solid ${ec}`,marginBottom:6,cursor:"pointer"}}>
{e.name}
{e.openBlocks.length>0&&
{e.openBlocks.length===1?t("exam.blocksOpen",{n:e.openBlocks.length}):t("exam.blocksOpenPlural",{n:e.openBlocks.length})}
}
{e.daysLeft===0?t("exam.today"):e.daysLeft===1?t("exam.tomorrow"):t("exam.daysLeft",{n:e.daysLeft})}
{t("exam.label")}
); })}
)} {/* Lernblock-Timer */} {(nonDeletedExams.length>0||studyTimer)&&(
{t("study.title")}
{studyTimer&&} {!studyTimer&&} {t("study.todayCount",{n:todayStudyBlocks.length})}
{studyTimer?._interrupted&&(
{t("study.restored",{x:fmtMs(studyTimer.elapsed)})}
)} {studyTimer?(()=>{ const elapsed=studyTimer.elapsed+(studyTimer.running?Date.now()-studyTimer.startTs:0); const total=studyTimer.hours*3600000; const remaining=total-elapsed; const prog=total>0?Math.min(1,Math.max(0,elapsed/total)):0; const eColor=examColor({id:studyTimer.examId}); const overdue=remaining<0; return(
{/* Full-width progress bar at top */}
{/* Exam name + running indicator */}
{studyTimer.running&&} {!studyTimer.running&&} {studyTimer.examName} {studyTimer.subject!==studyTimer.examName&&{studyTimer.subject}} {studyTimer.running?t("study.running"):t("study.paused")}
{/* Time display */}
{fmtMs(elapsed)}
{t("study.elapsed")}
{fmtMs(remaining)}
{overdue?t("study.overdue"):t("study.remaining")}
{const h=parseFloat(e.target.value)||studyTimer.hours;setStudyTimer(t=>t?{...t,hours:h}:null);}} disabled={studyTimer.running} style={{width:60,fontSize:13,fontWeight:600,opacity:studyTimer.running?0.4:1,cursor:studyTimer.running?"not-allowed":"auto"}}/>
{/* Block switcher */} {todayStudyBlocks.length>1&&(
{todayStudyBlocks.map(b=>{const bc=examColor(b.exam);const isCur=studyTimer.blockId===b.id;return( );})}
)} {/* Controls */}
{onOpenPip&&}
); })():(
{todayStudyBlocks.length===0&&

{t("study.empty")}

} {todayStudyBlocks.map(b=>{ const bc=examColor(b.exam); const done=b._timedOut; return(
{done?"✓ ":""}{b.exam.name}
{b.exam.subject&&
{b.exam.subject}
}
{b.hours}h
); })}
)}
)} {/* Gewohnheiten Heute */} {(data.habits||[]).filter(h=>!h.deletedAt).length>0&&(
{t("habits.title")}
{(data.habits||[]).filter(h=>!h.deletedAt).map(h=>{ let wc=null,wTarget=null,weekDone2=false; if(h.freq==="xweekly"){ const d2=new Date(today+"T12:00:00"); const dow2=(d2.getDay()+6)%7; d2.setDate(d2.getDate()-dow2); const ws=localISO(d2); const we=new Date(d2);we.setDate(we.getDate()+6); wc=(h.completions||[]).filter(iso=>iso>=ws&&iso<=localISO(we)&&iso<=today).length; wTarget=h.timesPerWeek||1; weekDone2=wc>=wTarget; } const todayChecked=(h.completions||[]).includes(today); const done=h.freq==="xweekly"?weekDone2:todayChecked; function habitToggle(){ const c=h.completions||[]; updateHabit({...h,completions:todayChecked?c.filter(x=>x!==today):[...c,today],updatedAt:Date.now()}); } return(
{done?"✓":""}
{h.name}
{h.freq==="xweekly"&&
{wc}/{wTarget} {t("habits.thisWeek")}
}
); })}
)} {/* Mini Week Calendar */}
{t("week.title")}
{weekDays.map((d,i)=>(
{setPlanMode("agenda");setPlanFocusDate(d.iso);setTab("plan");}} style={{padding:"10px 10px 8px",cursor:"pointer",borderTop:d.isToday?"2px solid var(--col-accent)":"1px solid var(--col-border-soft)",borderRight:!isMobile&&i<6?"1px solid var(--col-border-soft)":"none"}}>
{d.label}
{d.day}
{(()=>{ const parts=[]; if(d.deadlines>0)parts.push({n:d.deadlines,l:d.deadlines===1?t("week.deadline"):t("week.deadlines"),col:"#b91c1c"}); if(d.tasks>0)parts.push({n:d.tasks,l:d.tasks===1?t("week.task"):t("week.tasks"),col:"var(--col-text-sec)"}); if(d.events>0)parts.push({n:d.events,l:d.events===1?t("week.event"):t("week.events"),col:"var(--col-text-sec)"}); if(parts.length===0)return
; return parts.map((p,k)=>(
{p.n} {p.l}
)); })()}
))}
{/* Tages-Notiz */}
{t("note.title")}