/* a test's section chips: its own sections (as the admin named them), else its questions' subjects */
function catSecs(t){return t&&t.sections&&t.sections.length?t.sections.map(x=>x.name):(t&&t.subjects)||[];}
const CAT_SLOTS=window.SB_PAGE_DATA.catSlots;
// CAT has 68 questions from 2024 (DILR 22), 66 in 2021-2023.
const PYQ_ROWS=CAT_SLOTS.map(s=>({badge:'CAT',dur:'2 Hours',q:/^202[45]/.test(s)?68:66,title:'CAT '+s+' — Question Paper + Key',tags:['VARC','DILR','QUANT'],test:null,pdf:s==='2024 (Slot - 1)'?'assets/CAT_2024_Slot_01_Solved_Paper.pdf':null}));
function PapersGrid(){
const {Badge,Button}=window.ScorebuddyDesignSystem_ee75f2;
// Admin placements: attach a test to a paper, rename or hide it, or add papers (same design).
const LS=window.SBListings,L=LS?LS.use('cat-papers'):[];
// Admin extras per row: the paper PDF (o.pdf) and a test per section chip (o.sections).
/* One name per section, whatever it is called: QA / QUANT / Quantitative / Maths -> QUANT, VA / Verbal -> VARC, LRDI -> DILR. */
const secKey=(s)=>{const u=String(s||'').toUpperCase().replace(/[^A-Z]/g,'');return /^(QA|QUANT|MATH)/.test(u)?'QUANT':/^(VARC|VA|VERBAL|ENGLISH|READING)/.test(u)?'VARC':/^(DILR|LRDI|DI|LR)/.test(u)?'DILR':u;};
/* CAT paper order: VARC, DILR, QA */
const SEC_ORDER=['VARC','DILR','QUANT'];
const extras=(o)=>({pdf:o.pdf?o.pdf.url:null,pdfName:o.pdf?o.pdf.name:null,secLinks:Object.fromEntries((o.sections||[]).map(x=>[secKey(x.label),x.href]))});
let rows=PYQ_ROWS.map((r,i)=>{const o=LS&&LS.forSlot(L,'',CAT_SLOTS[i]);if(!o)return r;if(o.hidden)return null;const t=o.test,x=extras(o);
return Object.assign({},r,{title:o.title||r.title,test:t?t.href:r.test,q:t?t.questions:r.q,dur:t?LS.mins(t.durationMin):r.dur,tags:t&&catSecs(t).length?catSecs(t).map(s=>s.toUpperCase()):r.tags,
pdf:x.pdf||r.pdf,pdfName:x.pdfName,secLinks:x.secLinks});}).filter(Boolean);
if(LS)rows=LS.insert(rows,LS.added(L,'').map(o=>Object.assign({position:o.position,badge:o.test.exam||'CAT',dur:LS.mins(o.test.durationMin),q:o.test.questions,title:o.title,tags:catSecs(o.test).map(s=>s.toUpperCase()),test:o.test.href},extras(o))));
const rowEls=rows.map((r,i)=>{
/* Section tiles: the sectional test attached in Admin → Tests & Mocks → Website pages, by section. */
const NAME={QUANT:'Quant (QA)',QA:'Quant (QA)',VARC:'VARC',DILR:'DILR'};
/* every CAT section once (VARC, DILR, QA, plus any other section of the paper), in CAT order */
const keys=[...new Set(SEC_ORDER.concat(r.tags.map(secKey),Object.keys(r.secLinks||{})))].sort((a,b)=>(SEC_ORDER.indexOf(a)+1||9)-(SEC_ORDER.indexOf(b)+1||9));
const sections=keys.map(k=>({name:NAME[k]||k,href:(r.secLinks&&r.secLinks[k])||null}));
return React.createElement(React.Fragment,{key:i},window.SBPaperCard({
badge:r.badge,title:r.title,
meta:[{icon:'⏱',text:r.dur},{icon:'📝',text:r.q?r.q+' questions':''},{icon:'🧩',text:sections.length?sections.length+' sections':''}],
sections,fullHref:r.test||null,pdf:r.pdf||null,pdfName:r.pdfName||(r.pdf?String(r.pdf).split('/').pop():undefined)}));
});
const heading=React.createElement('h2',{style:{fontFamily:'var(--font-display)',fontWeight:800,fontSize:28,color:'var(--text-heading)',marginBottom:28}},'Previous Year ',React.createElement('span',{style:{color:'var(--brand-accent)'}},'Question Papers'));
const list=React.createElement('div',{style:{display:'flex',flexDirection:'column',gap:16}},rowEls);
/* the same papers as free reading pages (question + solution, no sign-up) — also how search engines find them */
const read=React.createElement('p',{style:{fontFamily:'var(--font-body)',fontSize:14.5,color:'var(--text-muted)',margin:'20px 0 0',textAlign:'center'}},'Prefer reading? ',React.createElement('a',{href:'/cat/pyq',style:{fontWeight:700}},'Every CAT question with its solution — year-wise & topic-wise, free →'));
return React.createElement('section',{style:{padding:'64px 48px',maxWidth:900,margin:'0 auto'}},heading,list,read);
}
window.PapersGrid=PapersGrid;
