function TopicwiseSection(){
const {Badge,Button,Tag}=window.ScorebuddyDesignSystem_ee75f2;
const D=window.TOPICWISE_DATA;
const SECTIONS=['VARC','Quant','DILR'];
const [sec,setSec]=React.useState('VARC');
// Admin placements: attach a test to a topic row, rename or hide it, or add rows (same design).
const LS=window.SBListings,L=LS?LS.use('cat-topicwise'):[];
function withPlacements(s){
let maxN=0;
const groups=D[s].groups.map(g=>({area:g.area,topics:g.topics.map(t=>{maxN=Math.max(maxN,t.n);const o=LS&&LS.forSlot(L,s,t.n);if(!o)return t;if(o.hidden)return null;
return Object.assign({},t,{topic:o.title||t.topic,also:o.subtitle||t.also,size:o.test?o.test.questions:t.size,href:o.test?o.test.href:null});}).filter(Boolean)}));
if(LS)LS.added(L,s).forEach(o=>{let g=groups.find(x=>x.area===o.area);if(!g){g={area:o.area||'MORE TESTS',topics:[]};groups.push(g);}
g.topics.push({n:++maxN,topic:o.title,also:o.subtitle||'',size:o.test.questions,href:o.test.href});});
const live=groups.filter(g=>g.topics.length);
return {meta:D[s].meta,groups:live,total:live.reduce((a,g)=>a+g.topics.length,0)};
}
const cur=withPlacements(sec);
const heading=React.createElement('h2',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:28,textAlign:'center',color:'var(--text-heading)',marginBottom:8}},'CAT Previous Year ',React.createElement('span',{style:{color:'var(--brand-accent)'}},'Topic-wise Questions'));
const sub=React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:15,color:'var(--text-muted)',textAlign:'center',margin:'0 0 24px',lineHeight:1.6}},'One timed test per topic, built from CAT 2017-2025 PYQs (all slots). ',cur.meta);
const tabs=React.createElement('div',{style:{display:'flex',gap:10,justifyContent:'center',marginBottom:10,flexWrap:'wrap'}},
SECTIONS.map(s=>React.createElement(Tag,{key:s,active:sec===s,onClick:()=>setSec(s)},s+' · '+(s===sec?cur:withPlacements(s)).total+' tests')));
const counts=React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:13,color:'var(--text-muted)',textAlign:'center',margin:'0 0 26px'}},cur.groups.map(g=>g.area.split(' - ')[0]).filter((v,i,a)=>a.indexOf(v)===i).join(' · '));
const groupEls=cur.groups.map(g=>{
const head=React.createElement('div',{style:{display:'flex',alignItems:'center',gap:12,margin:'30px 0 14px'}},
React.createElement('h3',{style:{margin:0,fontFamily:'var(--font-display)',fontWeight:700,fontSize:17,letterSpacing:'.02em',color:'var(--brand-accent)'}},g.area),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-muted)'}},g.topics.length+' topics'),
React.createElement('div',{style:{flex:1,height:1,background:'var(--border-default)'}}));
const rows=g.topics.map(t=>{
const left=React.createElement('div',{style:{flex:1,minWidth:230}},
React.createElement('div',{style:{display:'flex',alignItems:'center',gap:10,flexWrap:'wrap'}},
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontWeight:700,fontSize:11.5,color:'var(--text-muted)',background:'var(--gray-100)',borderRadius:'var(--radius-sm)',padding:'3px 8px'}},'Test '+t.n),
React.createElement('span',{style:{fontFamily:'var(--font-display)',fontWeight:700,fontSize:15.5,color:'var(--text-heading)'}},t.topic),
React.createElement('span',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-muted)'}},'📄 '+t.size+' Qs')),
t.also?React.createElement('div',{style:{fontFamily:'var(--font-body)',fontSize:12.5,color:'var(--text-muted)',marginTop:5}},'Also covers: '+t.also):null);
const btns=React.createElement('div',{style:{display:'flex',gap:10,flexWrap:'wrap'}},
React.createElement(Button,{variant:'secondary',size:'sm',disabled:true,title:'PDF coming soon'},'📄 Download PDF'),
t.href?React.createElement('a',{href:t.href},React.createElement(Button,{variant:'primary',size:'sm'},'Take Test →')):React.createElement(Button,{variant:'primary',size:'sm',disabled:true,title:'Test coming soon'},'Take Test →'));
return React.createElement('div',{key:t.n,style:{border:'1px solid var(--border-default)',borderRadius:'var(--radius-md)',padding:'14px 18px',display:'flex',justifyContent:'space-between',alignItems:'center',gap:16,flexWrap:'wrap',background:'var(--white)'}},left,btns);
});
return React.createElement('div',{key:g.area},head,React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:10}},rows));
});
return React.createElement('section',{style:{background:'var(--gray-50)',padding:'64px 48px'}},
React.createElement('div',{style:{maxWidth:900,margin:'0 auto'}},heading,sub,tabs,counts,groupEls));
}
window.TopicwiseSection=TopicwiseSection;
