PageSourceSearch

https://www.faithassembly.org.uk/assets/GiftAidPortal-CbzcvCd6.js

js faithassembly.org.uk collected 2026-09-25 13:55:15 UTC 56,979 bytes, 1 lines download raw bytes

1import{r,j as e,ag as u}from"./vendor-BFIOfVip.js";import{dO as pe,dP as Y,a3 as be,dQ as je,dR as V,dh as we,cN as W,a4 as re,dp as ie,de as ve,cJ as fe,dS as ye,dm as me,cG as ke,dT as Ce,bP as le,cP as Se,dU as De,cM as Ie,dV as ge,di as Ae,bQ as ce,dW as Re,dX as Te,dY as Le,dZ as Oe,d_ as Ee,bT as He,ci as Fe}from"./vendor-icons-BjlO8Ivt.js";import{d as A,h as Me,c as te}from"./index-CKRbob3g.js";import{k as _,C as P,F as X,E as K,I as Z,D as $,G as he,e as se,n as ae,_ as ee,r as ne,B as oe,M as J,u as U,T as z,H as Ge,t as Pe}from"./vendor-firebase-dJP658Hw.js";import{A as Ne,m as q}from"./vendor-motion-C4-LgF0B.js";import{u as B,w as ue,r as Be}from"./vendor-xlsx-CKN5doRT.js";const $e=({onBuildClick:t,onHistoryClick:b})=>{const[c,f]=r.useState({totalAmount:0,pendingCount:0,lastSubmission:null}),[x,i]=r.useState([]),[w,m]=r.useState(!0),[C,D]=r.useState(!1),l=new Date,a=l.getFullYear(),d=l.getMonth();let h="January - March";d>=3&&d<=5&&(h="April - June"),d>=6&&d<=8&&(h="July - September"),d>=9&&d<=11&&(h="October - December"),r.useEffect(()=>{const y=async()=>{try{const L=_(A,"Donations"),O=P(L,$("claimState","==","eligible")),E=await he(O);let n=0,g=0;E.forEach(I=>{const s=I.data();n+=s.amount||0,g++});const o=_(A,"ClaimBatches"),N=P(o,K("createdAt","desc"),X(1)),p=await he(N),S=p.empty?null:p.docs[0].data();f({totalAmount:n,pendingCount:g,lastSubmission:S})}catch(L){console.error(L)}finally{m(!1)}},T=_(A,"AuditLog"),k=P(T,K("timestamp","desc"),X(5)),R=Z(k,L=>{i(L.docs.map(O=>O.data()))});return y(),()=>R()},[]);const v=[{title:"Aggregated Claims",detail:"Donations under £30 can be aggregated into a single entry for HMRC submission."},{title:"Validity Period",detail:"Gift Aid can be claimed on donations made in the last 4 years."},{title:"Postcode Rule",detail:"Donors must have a valid UK postcode and a full house number/name."},{title:"Digital Evidence",detail:"You must maintain digital records of Gift Aid declarations for 6 years."},{title:"Company Claims",detail:"Gift Aid is not applicable to donations from companies or via Payroll Giving."}];return w?e.jsx("div",{className:"flex items-center justify-center p-20 animate-pulse font-black text-rose-600 tracking-widest text-xs",children:"INITIALIZING COMPLIANCE ENGINE..."}):e.jsxs("div",{className:"space-y-10 animate-in fade-in duration-500",children:[e.jsx(Ne,{children:C&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx(q.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},onClick:()=>D(!1),className:"absolute inset-0 bg-stone-900/60 backdrop-blur-sm"}),e.jsx(q.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"bg-white w-full max-w-2xl rounded-[3rem] shadow-2xl relative z-10 overflow-hidden",children:e.jsxs("div",{className:"p-10 space-y-8",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-3xl font-black text-stone-800 tracking-tight",children:"System Compliance Guidelines"}),e.jsx("button",{onClick:()=>D(!1),className:"p-2 bg-stone-100 rounded-xl hover:bg-stone-200 transition-colors",children:e.jsx(pe,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"grid gap-4",children:v.map((y,T)=>e.jsxs("div",{className:"flex gap-4 p-4 rounded-2xl bg-stone-50 border border-stone-100",children:[e.jsx(Y,{className:"w-6 h-6 text-emerald-500 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black text-stone-800 uppercase text-xs tracking-widest",children:y.title}),e.jsx("div",{className:"text-sm text-stone-500 font-medium mt-1",children:y.detail})]})]},T))}),e.jsxs("div",{className:"p-6 bg-rose-50 rounded-[2rem] flex gap-4 items-center",children:[e.jsx(be,{className:"w-8 h-8 text-rose-500"}),e.jsx("div",{className:"text-xs font-bold text-rose-700",children:"Following these guidelines ensures your R68 claims are processed by HMRC without rejection or audit triggers."})]})]})})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-8",children:[e.jsxs("div",{className:"bg-gradient-to-br from-emerald-500 to-teal-600 p-8 rounded-[2.5rem] text-white shadow-xl shadow-emerald-100 flex flex-col justify-between overflow-hidden relative group",children:[e.jsx(je,{className:"absolute -right-4 -top-4 w-32 h-32 opacity-10 group-hover:scale-110 transition-transform"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-emerald-100 text-xs font-black uppercase tracking-[0.2em]",children:"Ready for Claim"}),e.jsxs("div",{className:"text-5xl font-black",children:["£",(c.totalAmount*.25).toLocaleString()]}),e.jsxs("div",{className:"text-emerald-50 text-xs font-bold mt-2",children:["Available from £",c.totalAmount.toLocaleString()," eligible donations"]})]}),e.jsx("button",{onClick:t,className:"mt-8 bg-white/20 hover:bg-white/30 backdrop-blur-md px-6 py-2 rounded-xl text-xs font-black uppercase tracking-widest transition-all w-fit self-end",children:"Build New Batch"})]}),e.jsx("div",{className:"bg-white p-8 rounded-[2.5rem] border border-stone-200 shadow-sm flex flex-col justify-between",title:"This counts donations marked as eligible but not yet included in a claim batch",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-stone-400 text-xs font-black uppercase tracking-widest",children:"Pending Records"}),e.jsxs("div",{className:"text-4xl font-black text-rose-600",children:[c.pendingCount," RECORDS"]}),e.jsx("p",{className:"text-stone-500 text-sm font-medium",children:"Validated & awaiting batching"})]}),e.jsx("div",{className:"p-3 bg-emerald-50 text-emerald-600 rounded-2xl",children:e.jsx(V,{className:"w-8 h-8"})})]})}),e.jsxs("div",{className:"bg-stone-900 p-8 rounded-[2.5rem] text-white shadow-2xl flex flex-col justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-stone-500 text-xs font-black uppercase tracking-widest",children:"Last Submission"}),c.lastSubmission?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-2xl font-black uppercase tracking-tight truncate",children:c.lastSubmission.status}),e.jsxs("div",{className:"text-stone-400 text-xs font-mono mt-1",children:["ID: ",c.lastSubmission.claimBatchId.slice(0,8),"..."]})]}):e.jsx("div",{className:"text-2xl font-black text-stone-600",children:"NO BATCHES YET"})]}),e.jsxs("div",{className:"mt-6 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-stone-500",children:"View Details"}),e.jsx("button",{onClick:b,className:"w-10 h-10 bg-stone-800 hover:bg-stone-700 text-rose-500 rounded-xl flex items-center justify-center transition-colors shadow-lg",children:e.jsx(we,{className:"w-6 h-6"})})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-r from-rose-600 to-rose-500 p-10 rounded-[3rem] text-white shadow-xl shadow-rose-100 relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-white/5 rounded-full blur-3xl -mr-32 -mt-32"}),e.jsxs("div",{className:"max-w-2xl relative z-10 space-y-4",children:[e.jsx("h2",{className:"text-3xl font-black tracking-tight leading-tight",children:"Next submission window is closing soon."}),e.jsxs("p",{className:"text-rose-50 font-medium",children:["Generate your quarterly R68 claim for ",h," ",a,". Automate your HMRC submission in one click."]}),e.jsxs("div",{className:"flex gap-4 pt-4",children:[e.jsxs("button",{onClick:t,className:"bg-white text-rose-600 px-8 py-3 rounded-2xl font-black text-sm uppercase tracking-widest shadow-lg hover:scale-105 transition-transform active:scale-95 flex items-center gap-2",children:[e.jsx(W,{className:"rotate-45"})," Start Quarterly Batch"]}),e.jsx("button",{onClick:()=>D(!0),className:"bg-rose-700/30 border border-white/20 px-8 py-3 rounded-2xl font-black text-sm uppercase tracking-widest hover:bg-rose-700/50 transition-all shadow-lg",children:"Review Guidelines"})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center px-4",children:[e.jsx("h3",{className:"font-black text-lg uppercase tracking-widest text-stone-700",children:"Recent System Activity"}),e.jsx("button",{onClick:b,className:"text-rose-600 text-xs font-black uppercase tracking-widest hover:underline",children:"View All Logs"})]}),e.jsx("div",{className:"bg-white rounded-[2.5rem] border border-stone-100 shadow-sm overflow-hidden divide-y divide-stone-50",children:x.length===0?e.jsx("div",{className:"p-10 text-center text-stone-400 font-bold uppercase tracking-widest text-xs",children:"No activity recorded yet"}):x.map((y,T)=>{var k,R;return e.jsxs("div",{className:"p-6 flex items-center gap-6 hover:bg-stone-50 transition-colors",children:[e.jsx("div",{className:"w-12 h-12 bg-stone-100 rounded-2xl flex items-center justify-center text-stone-400",children:e.jsx(re,{className:"w-6 h-6"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"text-sm font-black text-stone-900 capitalize",children:[y.actionType.replace(/_/g," "),": ",y.entityType]}),e.jsxs("div",{className:"text-xs text-stone-400 font-medium font-mono",children:[(k=y.timestamp)==null?void 0:k.toDate().toLocaleStr
1ing()," • ID: ",(R=y.entityId)==null?void 0:R.slice(0,8),"..."]})]}),e.jsx("div",{className:"px-3 py-1 bg-emerald-50 text-emerald-600 rounded-lg text-[10px] font-black uppercase tracking-widest",children:"SUCCESS"})]},y.auditId||T)})})]})]})},_e=()=>{const[t,b]=r.useState([]),[c,f]=r.useState({date:"Date",amount:"Amount",reference:"Reference",donorName:"Payee"}),[x,i]=r.useState(1),[w,m]=r.useState(!1),C=a=>a?a instanceof Date?a.toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):typeof a=="number"&&a>3e4?new Date((a-25569)*86400*1e3).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):a.toString():"—",D=a=>{var v;const d=(v=a.target.files)==null?void 0:v[0];if(!d)return;const h=new FileReader;h.onload=y=>{var T;try{const k=(T=y.target)==null?void 0:T.result,R=Be(k,{type:"array",cellDates:!0}),L=R.SheetNames[0],O=R.Sheets[L],E=B.sheet_to_json(O);if(console.log("Parsed Data:",E),E.length===0){u.error("The file appears to be empty.");return}b(E),i(2)}catch(k){console.error("File read error:",k),u.error("Failed to read file. Please ensure it's a valid Excel or CSV file.")}},h.readAsArrayBuffer(d)},l=async()=>{if(t.length!==0){m(!0);try{const a=se(Me),d=ae(a,"giftAidImportDonations"),h=t.map((y,T)=>{var E,n,g;let k=y[c.date];typeof k=="number"&&k>3e4?k=new Date((k-25569)*86400*1e3).toISOString():k instanceof Date&&(k=k.toISOString());let R=((E=y[c.amount])==null?void 0:E.toString())||"0",L=R.replace(/[^\d.-]/g,""),O=parseFloat(L);return isNaN(O)&&(console.warn(`Row ${T+1}: Invalid amount "${R}"`),O=0),{dateReceived:k,amount:O,bankReference:((n=y[c.reference])==null?void 0:n.toString())||"",donorName:((g=y[c.donorName])==null?void 0:g.toString())||""}});console.log("Sending donations to backend:",h.length);const v=await d({donations:h});if(v.data.success)u.success(`Import complete: ${v.data.imported} new records, ${v.data.duplicates} duplicates skipped.`),i(3);else throw new Error(v.data.message||"Import failed on server")}catch(a){console.error("Import error:",a),u.error(a.message||"Failed to import donations. Please check your network and try again.")}finally{m(!1)}}};return e.jsxs("div",{className:"space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h2",{className:"text-2xl font-black uppercase tracking-tight text-stone-800",children:"Import Statements"}),e.jsx("div",{className:"flex gap-2",children:[1,2,3].map(a=>e.jsx("div",{className:`w-3 h-3 rounded-full ${x>=a?"bg-rose-600":"bg-stone-200"}`},a))})]}),x===1&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center p-20 border-4 border-dashed border-stone-100 rounded-[3rem] bg-stone-50/30 hover:bg-stone-50 transition-colors",children:[e.jsx(ie,{className:"w-20 h-20 text-stone-300 mb-6"}),e.jsxs("label",{className:"bg-rose-600 text-white px-8 py-4 rounded-2xl font-black text-lg cursor-pointer hover:bg-rose-700 transition-all shadow-xl shadow-rose-200 active:scale-95",children:["Choose Statement File (CSV/XLSX)",e.jsx("input",{type:"file",className:"hidden",accept:".csv,.xlsx,.xls",onChange:D})]}),e.jsx("p",{className:"mt-4 text-stone-400 font-medium font-mono text-sm uppercase",children:"Max file size: 10MB"})]}),e.jsx("div",{className:"flex justify-center",children:e.jsxs("button",{onClick:()=>{const a=B.json_to_sheet([{Date:"01/01/2026",Amount:"100.00",Reference:"DONATION-REF",Payee:"John Doe"}]),d=B.book_new();B.book_append_sheet(d,a,"Template"),ue(d,"gift_aid_import_template.xlsx")},className:"text-stone-400 font-bold uppercase text-xs hover:text-rose-600 transition-colors flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Download CSV Template"]})})]}),x===2&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsxs("div",{className:"lg:col-span-1 space-y-6 bg-stone-50 p-8 rounded-[2rem] border border-stone-200 self-start",children:[e.jsx("h3",{className:"font-black text-lg uppercase tracking-widest text-stone-600",children:"Map Columns"}),Object.entries(c).map(([a,d])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-black uppercase text-stone-400 ml-1",children:a}),e.jsx("select",{value:d,onChange:h=>f(v=>({...v,[a]:h.target.value})),className:"w-full bg-white border-2 border-stone-200 p-3 rounded-xl font-bold outline-none focus:border-rose-500 transition-colors",children:t.length>0&&Object.keys(t[0]).map(h=>e.jsx("option",{value:h,children:h},h))})]},a)),e.jsxs("button",{onClick:l,disabled:w,className:"w-full bg-rose-600 text-white py-4 rounded-2xl font-black text-lg hover:bg-rose-700 transition-all shadow-xl shadow-rose-200 flex items-center justify-center gap-2 disabled:opacity-50",children:[w?"Processing...":"Run Import",e.jsx(ve,{})]})]}),e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsx("h3",{className:"font-black text-lg uppercase tracking-widest text-stone-600",children:"Data Preview"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>{const a=B.json_to_sheet(t),d=B.book_new();B.book_append_sheet(d,a,"Preview"),ue(d,"import_preview.xlsx")},className:"text-[10px] font-black text-stone-400 uppercase hover:text-rose-600 transition-colors",children:"Export Preview"}),e.jsxs("span",{className:"text-xs font-black text-stone-400 uppercase",children:[t.length," records foun
1d"]})]})]}),e.jsxs("div",{className:"bg-white rounded-3xl border border-stone-200 overflow-hidden shadow-inner",children:[e.jsxs("table",{className:"w-full text-left bg-transparent",children:[e.jsx("thead",{className:"bg-stone-100 border-b border-stone-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Date"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Amount"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Reference"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Donor"})]})}),e.jsx("tbody",{className:"divide-y divide-stone-100",children:t.slice(0,10).map((a,d)=>e.jsxs("tr",{children:[e.jsx("td",{className:"p-4 text-sm font-bold text-stone-600 font-mono",children:C(a[c.date])}),e.jsxs("td",{className:"p-4 text-sm font-black text-rose-600",children:["£",parseFloat(a[c.amount]).toFixed(2)]}),e.jsx("td",{className:"p-4 text-sm font-medium text-stone-500",children:a[c.reference]}),e.jsx("td",{className:"p-4 text-sm font-black text-stone-900",children:a[c.donorName]})]},d))})]}),t.length>10&&e.jsxs("div",{className:"p-4 text-center text-xs font-bold text-stone-400 uppercase bg-stone-50 border-t border-stone-100",children:["+ ",t.length-10," more rows"]})]})]})]}),x===3&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-20 text-center",children:[e.jsx(q.div,{initial:{scale:0},animate:{scale:1},className:"w-24 h-24 bg-emerald-500 rounded-full flex items-center justify-center text-white text-5xl mb-6 shadow-xl shadow-emerald-200",children:e.jsx(Y,{})}),e.jsx("h3",{className:"text-3xl font-black tracking-tight text-stone-800",children:"Import Successful!"}),e.jsx("p",{className:"text-stone-500 font-medium max-w-md mt-2",children:"Donations have been uploaded and deduplicated. They are now being validated in the background."}),e.jsx("button",{onClick:()=>i(1),className:"mt-8 bg-stone-900 text-white px-8 py-3 rounded-xl font-bold hover:bg-stone-800 transition shadow-lg active:scale-95",children:"Import Another File"})]})]})},Ve=()=>{const[t,b]=r.useState([]),[c,f]=r.useState(!0),[x,i]=r.useState(""),[w,m]=r.useState(null),[C,D]=r.useState(!1),[l,a]=r.useState([]),[d,h]=r.useState(!1),[v,y]=r.useState({total:0,missingDeclaration:0,unmatched:0}),T=async()=>{try{const n=_(A,"Donations"),g=P(n,$("giftAidEligible","==",!1)),o=await ee(g),N=P(n,$("giftAidEligible","==",!1),$("validationFlags","array-contains","NO_ACTIVE_DECLARATION")),p=await ee(N),S=P(n,$("giftAidEligible","==",!1),$("validationFlags","array-contains","MISSING_DONOR_MATCH")),I=await ee(S);y({total:o.data().count,missingDeclaration:p.data().count,unmatched:I.data().count})}catch(n){console.error("Failed to fetch total counts:",n)}},k=async()=>{D(!0);const n=u.loading("Executing intelligent auto-match...");try{const g=ne(te,"donor"),o=await oe(g);if(!o.exists()){u.error("No donors found in main database",{id:n});return}const N=o.val(),p=new Map;Object.keys(N).forEach(j=>{const F=N[j],M=(F["First Name"]||F.firstName||"").toLowerCase().trim(),G=(F["Last Name"]||F.lastName||"").toLowerCase().trim(),de=H(`${M} ${G}`);de&&p.set(de,j);const xe=H(`${G} ${M}`);if(xe&&p.set(xe,j),G&&M){const Q=M.charAt(0);p.set(H(`${G}${Q}`),j),p.set(H(`${G} ${Q}`),j),p.set(H(`${Q}${G}`),j),p.set(H(`${Q} ${G}`),j)}});const S=t.filter(j=>!j.donorId),I=J(A);let s=0;S.forEach(j=>{const F=H(j.unmatchedDonorText||""),M=p.get(F);if(M){const G=U(A,"Donations",j.donationId);I.update(G,{donorId:M,giftAidEligible:!0,validationFlags:[],updatedAt:z.now()}),s++}}),s>0?(await I.commit(),u.success(`Successfully auto-linked ${s} records!`,{id:n})):u("No new matches found using the current patterns.",{id:n,icon:"ℹ️"})}catch(g){console.error(g),u.error("Process failed",{id:n})}finally{D(!1)}},R=async n=>{if(!window.confirm(`Are you sure you want to permanently remove ${n.length} record(s)? This cannot be undone.`))return;h(!0);const g=u.loading(`Removing ${n.length} record(s)...`);try{const o=J(A);n.forEach(N=>{o.delete(U(A,"Donations",N))}),await o.commit(),u.success("Records removed successfully",{id:g}),a([])}catch(o){console.error(o),u.error("Failed to remove records",{id:g})}finally{h(!1)}},L=()=>{l.length===t.length&&t.length>0?a([]):a(t.map(n=>n.donationId))},O=n=>{a(g=>g.includes(n)?g.filter(o=>o!==n):[...g,n])};r.useEffect(()=>{const n=P(_(A,"Donations"),$("giftAidEligible","==",!1),X(100)),g=Z(n,o=>{const N=o.docs.map(p=>({...p.data(),donationId:p.id}));b(N),f(!1)});return()=>g()},[]),r.useEffect(()=>{T()},[t]);const E=n=>n.includes("MISSING_DONOR_MATCH")?e.jsx(ke,{className:"text-amber-500"}):n.includes("INVALID_POSTCODE")?e.jsx(Ce,{className:"text-rose-500"}):e.jsx(le,{className:"text-stone-400"});return e.jsxs("div",{className:"space-y-8 animate-in fade-in duration-500",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black uppercase tracking-tight text-stone-800",children:"Validation Queue"}),e.jsx("p",{className:"text-stone-500 font-medium",children:"Fix records that failed automatic HMRC compliance checks"})]}),e.jsxs("div",{className:"flex gap-2 w-full md:w-auto",children:[e.jsxs("div",{className:"relative flex-1 md:w-64",children:[e.jsx(fe,{className:"absolute left-3 top-3.5 text-stone-400"}),e.jsx("input",{type:"text",placeholder:"Search list...",value:x,onChange:n=>i(n.target.value),className:"w-full pl-10 pr-4 py-3 bg-stone-100 rounded-xl font-bold outline-none focus:ring-2 focus:ring-rose-500 transition-all border-none"})]}),e.jsxs("button",{onClick:k,disabled:C||c,className:"bg-stone-900 text-white px-6 py-3 rounded-xl font-black text-sm shadow-xl shadow-stone-100 hover:bg-stone-800 transition-all active:scale-95 flex items-center gap-2 disabled:opacity-50",children:[e.jsx(ye,{className:"w-5 h-5 text-rose-500"}),C?"AUTO-LINKING...":"AUTO-LINK ALL"]}),l.length>0&&e.jsxs("button",{onClick:()=>R(l),disabled:d,className:"bg-rose-600 text-white px-6 py-3 rounded-xl font-black text-sm shadow-xl shadow-rose-100 hover:bg-rose-700 transition-all active:scale-95 flex items-center gap-2",children:[e.jsx(me,{className:"w-5 h-5"}
1),"DELETE (",l.length,")"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-rose-50 p-6 rounded-3xl border border-rose-100",children:[e.jsx("div",{className:"text-rose-600 text-xs font-black uppercase tracking-widest mb-1",children:"Total Errors"}),e.jsx("div",{className:"text-4xl font-black text-rose-700",children:v.total})]}),e.jsxs("div",{className:"bg-amber-50 p-6 rounded-3xl border border-amber-100",children:[e.jsx("div",{className:"text-amber-600 text-xs font-black uppercase tracking-widest mb-1",children:"Missing Declarations"}),e.jsx("div",{className:"text-4xl font-black text-amber-700",children:v.missingDeclaration})]}),e.jsxs("div",{className:"bg-sky-50 p-6 rounded-3xl border border-sky-100",children:[e.jsx("div",{className:"text-sky-600 text-xs font-black uppercase tracking-widest mb-1",children:"Unmatched Donors"}),e.jsx("div",{className:"text-4xl font-black text-sky-700",children:v.unmatched})]})]}),e.jsx("div",{className:"bg-white rounded-[2rem] border border-stone-200 overflow-hidden",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{className:"bg-stone-50 border-b border-stone-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-4 w-12",children:e.jsx("input",{type:"checkbox",checked:l.length===t.length&&t.length>0,onChange:L,className:"w-5 h-5 rounded border-stone-300 text-rose-600 focus:ring-rose-500 transition-all cursor-pointer"})}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Donation Details"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Unmatched Info"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500",children:"Compliance Flags"}),e.jsx("th",{className:"p-4 text-xs font-black uppercase text-stone-500 text-right",children:"Action"})]})}),e.jsx("tbody",{className:"divide-y divide-stone-100",children:c?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-20 text-center text-stone-400 font-bold animate-pulse uppercase tracking-widest",children:"Checking Compliance..."})}):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Y,{className:"w-16 h-16 text-emerald-500"}),e.jsx("p",{className:"font-black text-stone-800 text-xl",children:"Inbox Zero! No errors found."})]})})}):t.map(n=>{var g;return e.jsxs("tr",{className:`hover:bg-stone-50/50 transition-colors ${l.includes(n.donationId)?"bg-rose-50/30":""}`,children:[e.jsx("td",{className:"p-6",children:e.jsx("input",{type:"checkbox",checked:l.includes(n.donationId),onChange:()=>O(n.donationId),className:"w-5 h-5 rounded border-stone-300 text-rose-600 focus:ring-rose-500 transition-all cursor-pointer"})}),e.jsxs("td",{className:"p-6",children:[e.jsxs("div",{className:"font-black text-stone-900",children:["£",n.amount.toFixed(2)]}),e.jsxs("div",{className:"text-xs font-mono text-stone-400 mt-1 uppercase",children:[n.dateReceived.toDate().toLocaleDateString()," • ",n.bankReference]})]}),e.jsxs("td",{className:"p-6",children:[e.jsx("div",{className:"text-stone-600 font-bold",children:n.unmatchedDonorText||"Unknown"}),e.jsx("div",{className:"text-[10px] font-black text-stone-400 uppercase mt-1",children:"From Bank State"})]}),e.jsx("td",{className:"p-6",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:(g=n.validationFlags)==null?void 0:g.map(o=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 bg-rose-50 text-rose-600 rounded-full text-[10px] font-black uppercase border border-rose-100",children:[E([o]),o.replace(/_/g," ")]},o))})}),e.jsx("td",{className:"p-6 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>m(n),className:"px-4 py-2 bg-stone-900 text-white rounded-xl font-bold text-xs hover:bg-stone-800 shadow-lg active:scale-95 transition-all",children:"FIX RECORD"}),e.jsx("button",{onClick:()=>R([n.donationId]),className:"p-2 text-stone-400 hover:text-rose-600 transition-colors",title:"Remove Record",children:e.jsx(me,{className:"w-5 h-5"})})]})})]},n.donationId)})})]})}),w&&e.jsx(Ue,{donation:w,allDonations:t,onClose:()=>m(null)})]})},H=t=>t?t.toLowerCase().replace(/\b(mr|mrs|ms|dr|miss|rev|pastor|pst|elder|deacon|deaconess|bro|sis)\b\.?/gi,"").replace(/Offering/gi,"").replace(/Tithes/gi,"").replace(/Tithe/gi,"").replace(/Donation/gi,"").replace(/Gift/gi,"").replace(/Aid/gi,"").replace(/FAU/gi,"").replace(/Church/gi,"").replace(/Faith/gi,"").replace(/Assembly/gi,"").replace(/offer/gi,"").replace(/[^a-z0-9]/g,"").trim():"",Ue=({donation:t,allDonations:b,onClose:c})=>{const[f,x]=r.useState("link"),[i,w]=r.useState(""),[m,C]=r.useState([]),[D,l]=r.useState(!1),[a,d]=r.useState(!1),[h,v]=r.useState(!1),[y,T]=r.useState(t.amount.toString()),[k,R]=r.useState(t.dateReceived.toDate().toISOString().split("T")[0]);r.useEffect(()=>{L()},[]);const L=async()=>
1{l(!0);try{const o=ne(te,"donor"),N=await oe(o);if(N.exists()){const p=N.val(),S=H(t.unmatchedDonorText||""),I=Object.keys(p).map(s=>({donorId:s,...p[s]})).filter(s=>{const j=H(`${s["First Name"]} ${s["Last Name"]}`);return j&&S&&(j.includes(S)||S.includes(j))}).slice(0,5);I.length>0&&C(I.map(s=>({donorId:s.donorId,firstName:s["First Name"]||s.firstName||"Unknown",lastName:s["Last Name"]||s.lastName||"",postcode:s.Postcode||s.postcode||"No Postcode",addressLine1:s["Street Name"]||s.street||s.Address||"No Address"})))}}finally{l(!1)}},O=async o=>{d(!0);const N=u.loading("Linking records...");try{const p=J(A),S=H(t.unmatchedDonorText||""),I=b.filter(s=>H(s.unmatchedDonorText||"")===S);I.forEach(s=>{const j=U(A,"Donations",s.donationId);p.update(j,{donorId:o,giftAidEligible:!0,validationFlags:[],updatedAt:z.now()})}),await p.commit(),u.success(`Linked ${I.length} similar record(s)!`,{id:N}),c()}catch(p){console.error(p),u.error("Failed to link donations",{id:N})}finally{d(!1)}},E=async()=>{if(i.trim()){l(!0);try{const o=ne(te,"donor"),N=await oe(o);if(N.exists()){const p=N.val(),S=i.toLowerCase(),I=Object.keys(p).map(s=>({donorId:s,...p[s]})).filter(s=>{const j=(s["First Name"]||s.firstName||"").toLowerCase(),F=(s["Last Name"]||s.lastName||"").toLowerCase(),M=(s.Email||s.email||"").toLowerCase();return j.includes(S)||F.includes(S)||M.includes(S)}).slice(0,20).map(s=>({donorId:s.donorId,firstName:s["First Name"]||s.firstName||"Unknown",lastName:s["Last Name"]||s.lastName||"",postcode:s.Postcode||s.postcode||"No Postcode",addressLine1:s["Street Name"]||s.street||s.Address||"No Address"}));C(I)}else C([])}catch{u.error("Failed to search donors")}finally{l(!1)}}},n=async()=>{v(!0);const o=u.loading("Updating records...");try{const N=J(A),p=H(t.unmatchedDonorText||""),S=parseFloat(y),I=new Date(k);if(isNaN(S))throw new Error("Invalid amount");if(isNaN(I.getTime()))throw new Error("Invalid date");const s=b.filter(j=>H(j.unmatchedDonorText||"")===p);s.forEach(j=>{const F=U(A,"Donations",j.donationId);N.update(F,{amount:S,dateReceived:z.fromDate(I),updatedAt:z.now()})}),await N.commit(),u.success(`Updated ${s.length} record(s)!`,{id:o}),c()}catch(N){u.error(N.message||"Failed to update records",{id:o})}finally{v(!1)}},g=async()=>{u.error("Please link a donor first to send them a declaration link.")};return e.jsx("div",{className:"fixed inset-0 bg-stone-900/60 backdrop-blur-sm z-[100] flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white rounded-[3rem] w-full max-w-2xl shadow-2xl overflow-hidden flex flex-col max-h-[90vh] animate-in zoom-in-95 duration-200",children:[e.jsxs("header",{className:"p-8 border-b border-stone-100 flex justify-between items-center bg-stone-50/50",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black text-stone-900 tracking-tight",children:"Fix Compliance Record"}),e.jsx("p",{className:"text-stone-500 text-sm font-medium",children:"Link this unmatched donation to a registered donor."})]}),e.jsx("button",{onClick:c,className:"w-12 h-12 rounded-full hover:bg-stone-100 flex items-center justify-center text-stone-400 transition-colors",children:e.jsx(pe,{className:"text-2xl"})})]}),e.jsxs("div",{className:"flex px-8 border-b border-stone-100",children:[e.jsx("button",{onClick:()=>
1x("link"),className:`flex-1 py-4 text-[10px] font-black uppercase tracking-widest transition-all border-b-2 ${f==="link"?"text-rose-600 border-rose-600":"text-stone-400 border-transparent hover:text-stone-600"}`,children:"1. Link Donor"}),e.jsx("button",{onClick:()=>x("data"),className:`flex-1 py-4 text-[10px] font-black uppercase tracking-widest transition-all border-b-2 ${f==="data"?"text-rose-600 border-rose-600":"text-stone-400 border-transparent hover:text-stone-600"}`,children:"2. Correct Data"}),e.jsx("button",{onClick:()=>x("actions"),className:`flex-1 py-4 text-[10px] font-black uppercase tracking-widest transition-all border-b-2 ${f==="actions"?"text-rose-600 border-rose-600":"text-stone-400 border-transparent hover:text-stone-600"}`,children:"3. Quick Actions"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-8 space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 bg-stone-900 rounded-[2rem] text-white",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-black uppercase text-stone-500 tracking-widest mb-1",children:"Source Reference"}),e.jsx("div",{className:"text-lg font-black",children:t.unmatchedDonorText||"Unknown"})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[10px] font-black uppercase text-stone-500 tracking-widest mb-1",children:"Current Amount"}),e.jsxs("div",{className:"text-2xl font-black text-rose-500",children:["£",t.amount.toFixed(2)]})]})]}),f==="link"&&e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-bottom-2 duration-300",children:[m.length>0&&!i&&e.jsxs("div",{className:"p-4 bg-emerald-50 rounded-2xl border border-emerald-100 flex items-center gap-3",children:[e.jsx(Se,{className:"text-emerald-500 w-5 h-5 animate-pulse"}),e.jsx("span",{className:"text-[11px] font-black text-emerald-800 uppercase tracking-tight",children:"AI Found potential matches below!"})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(fe,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-stone-400"}),e.jsx("input",{type:"text",placeholder:"Manually search name or email...",value:i,onChange:o=>w(o.target.value),onKeyDown:o=>o.key==="Enter"&&E(),className:"w-full pl-12 pr-4 py-4 bg-stone-100 rounded-2xl font-bold outline-none border-2 border-transparent focus:border-rose-500 transition-all text-sm"})]}),e.jsx("button",{onClick:E,disabled:D,className:"bg-stone-900 text-white px-8 rounded-2xl font-black hover:bg-stone-800 transition-all active:scale-95 disabled:opacity-50 text-xs",children:"SEARCH"})]})}),e.jsx("div",{className:"space-y-2",children:m.length>0?m.map(o=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-stone-50 rounded-2xl border border-stone-100 hover:border-rose-200 hover:bg-white hover:shadow-xl transition-all group",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"w-10 h-10 bg-white rounded-xl flex items-center justify-center text-stone-400 group-hover:text-rose-600 shadow-sm font-black italic border border-stone-100",children:[o.firstName[0],o.lastName[0]]}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-stone-900",children:[o.firstName," ",o.lastName]}),e.jsxs("div",{className:"text-[10px] text-stone-400 font-black uppercase tracking-tighter",children:[o.postcode," • ",o.addressLine1]})]})]}),e.jsx("button",{onClick:()=>O(o.donorId),disabled:a,className:"px-4 py-2 bg-stone-900 text-white rounded-lg font-black text-[10px] hover:bg-rose-600 transition-all uppercase tracking-widest disabled:opacity-50",children:"LINK"})]},o.donorId)):e.jsxs("div",{className:"text-center py-12 bg-stone-50 rounded-[2rem] border border-dashed border-stone-200",children:[e.jsx(De,{className:"w-8 h-8 text-stone-300 mx-auto mb-2 animate-spin-slow"}),e.jsx("p",{className:"text-stone-400 font-bold uppercase text-[10px] tracking-widest",children:"Searching Donor Database..."})]})})]}),f==="data"&&e.jsx("div",{className:"space-y-6 animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsxs("div",{className:"bg-rose-50 p-6 rounded-[2rem] border border-rose-100 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-rose-600 font-black text-[10px] uppercase tracking-widest mb-2",children:[e.jsx(Ie,{className:"w-4 h-4"}),"Manual Override"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Correct Amount (£)"}),e.jsx("input",{type:"number",value:y,onChange:o=>T(o.target.value),className:"w-full p-4 bg-white border-2 border-stone-200 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Correct Date"}),e.jsx("input",{type:"date",value:k,onChange:o=>R(o.target.value),className:"w-full p-4 bg-white border-2 border-stone-200 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all"})]})]}),e.jsxs("button",{onClick:n,disabled:h,className:"w-full bg-rose-600 text-white py-4 rounded-2xl font-black text-sm shadow-xl shadow-rose-100 hover:bg-rose-700 transition-all active:scale-95 flex items-center justify-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5"}),h?"UPDATING...":"SAVE DATA CORRECTION"]}),e.jsx("p",{className:"text-[9px] text-stone-400 font-bold text-center italic",children:"Tip: This fix will be applied to all similar unmatched records automatically."})]})}),f==="actions"&&e.jsx("div",{className:"space-y-4 animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsxs("div",{className:"p-8 bg-stone-50 rounded-[2.5rem] border border-stone-100 text-center space-y-6",children:[e.jsx("div",{className:"w-20 h-20 bg-white rounded-[2rem] flex items-center justify-center text-rose-600 mx-auto 
1shadow-sm border border-stone-100",children:e.jsx(W,{className:"w-10 h-10 rotate-45"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-black text-stone-900",children:"Request Declaration"}),e.jsx("p",{className:"text-stone-500 text-sm font-medium",children:"Link a donor first to invite them to sign a master Gift Aid declaration via SMS/Email."})]}),e.jsx("button",{onClick:g,className:"px-8 py-4 bg-stone-200 text-stone-400 rounded-2xl font-black text-sm cursor-not-allowed uppercase tracking-widest",children:"Invitation Options"})]})})]})]})})},qe=()=>{const[t,b]=r.useState([]),[c,f]=r.useState(!0),[x,i]=r.useState(!1),[w,m]=r.useState({start:"",end:"",name:""});r.useEffect(()=>{const l=P(_(A,"ClaimBatches"),K("createdAt","desc")),a=Z(l,d=>{const h=d.docs.map(v=>v.data());b(h),f(!1)});return()=>a()},[]);const C=async l=>{l.preventDefault(),i(!0);const a=se(),d=ae(a,"giftAidBuildBatch");try{await d({startDate:w.start,endDate:w.end,name:w.name}),u.success("Batch created successfully! Check the draft below."),m({start:"",end:"",name:""})}catch(h){u.error(h.message||"Failed to create batch")}finally{i(!1)}},D=async l=>{if(!window.confirm("Are you sure you want to submit this batch to HMRC? This action cannot be undone."))return;const a=se(),d=ae(a,"giftAidSubmitBatch"),h=u.loading("Generating XML and connecting to HMRC...");try{await d({batchId:l}),u.success("Batch submitted successfully!",{id:h})}catch(v){u.error(v.message||"Submission failed",{id:h})}};return e.jsxs("div",{className:"space-y-12 animate-in fade-in duration-500",children:[e.jsx("div",{className:"bg-stone-50 p-10 rounded-[3rem] border border-stone-200",children:e.jsxs("div",{className:"max-w-xl space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-stone-800 tracking-tight",children:"Generate New Claim Batch"}),e.jsx("p",{className:"text-stone-500 font-medium",children:"Select a period to snapshot eligible donations into an R68 claim."})]}),e.jsxs("form",{onSubmit:C,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Period Start"}),e.jsx("input",{type:"date",required:!0,value:w.start,onChange:l=>m(a=>({...a,start:l.target.value})),className:"w-full p-4 bg-white border-2 border-stone-100 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Period End"}),e.jsx("input",{type:"date",required:!0,value:w.end,onChange:l=>m(a=>({...a,end:l.target.value})),className:"w-full p-4 bg-white border-2 border-stone-100 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all"})]})]}),e.jsxs("button",{type:"submit",disabled:x,className:"w-full bg-rose-600 text-white py-5 rounded-3xl font-black text-lg shadow-xl shadow-rose-200 hover:bg-rose-700 transition-all active:scale-95 flex items-center justify-center gap-3 disabled:opacity-50",children:[e.jsx(Ae,{className:"w-6 h-6 border-2 border-current rounded-lg"}),x?"PROCESSING...":"INITIALIZE SNAPSHOT"]})]})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"font-black text-lg uppercase tracking-widest text-stone-700 px-4",children:"Claim Batch History"}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:c?e.jsx("div",{className:"p-20 text-center font-black text-stone-300 uppercase tracking-widest animate-pulse",children:"Loading Archive..."}):t.length===0?e.jsx("div",{className:"p-20 text-center bg-white rounded-[2rem] border border-stone-200 text-stone-400 font-bold uppercase tracking-widest",children:"No batches generated yet"}):t.map(l=>e.jsxs("div",{className:"bg-white p-6 rounded-[2.5rem] border border-stone-200 shadow-sm flex flex-col md:flex-row items-center gap-8 hover:border-rose-200 transition-colors group",children:[e.jsx("div",{className:`w-20 h-20 rounded-3xl flex items-center justify-center text-3xl shadow-inner ${l.status==="submitted"?"bg-emerald-50 text-emerald-500":"bg-rose-50 text-rose-500"}`,children:e.jsx(ce,{})}),e.jsxs("div",{className:"flex-1 space-y-1 text-center md:text-left",children:[e.jsxs("div",{className:"flex items-center gap-3 justify-center md:justify-start",children:[e.jsxs("h4",{className:"text-xl font-black text-stone-800 uppercase tracking-tight",children:["Claim Period ",l.claimBatchId.slice(0,5)]}),e.jsx("span",{className:`px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest ${l.status==="submitted"?"bg-emerald-100 text-emerald-700":"bg-amber-100 text-amber-700"}`,children:l.status})]}),e.jsxs("p",{className:"text-stone-400 font-bold font-mono text-xs uppercase",children:[l.claimPeriodStart.toDate().toLocaleDateString()," — ",l.claimPeriodEnd.toDate().toLocaleDateString()]})]}),e.jsxs("div",{className:"text-center md:text-right px-8 border-x border-stone-100",children:[e.jsxs("div",{className:"text-2xl font-black text-stone-900",children:["£",l.totalG
1iftAidClaim.toLocaleString()]}),e.jsx("div",{className:"text-[10px] font-black text-rose-600 uppercase tracking-widest",children:"HMRC Repayment"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:"p-4 bg-stone-100 text-stone-600 rounded-2xl hover:bg-stone-200 transition-colors",title:"Download Official Schedule",children:e.jsx(Re,{className:"w-6 h-6"})}),e.jsxs("button",{onClick:()=>l.status==="draft"?D(l.claimBatchId):u.success("Reviewing submission receipt..."),className:"bg-rose-600 text-white px-8 py-4 rounded-2xl font-black text-sm uppercase tracking-widest shadow-lg shadow-rose-100 hover:scale-105 transition-transform active:scale-95 flex items-center gap-2",children:[e.jsx(W,{className:"rotate-45"})," ",l.status==="draft"?"Review & Submit":"View Receipt"]})]})]},l.claimBatchId))})]})]})},Qe=()=>{const[t,b]=r.useState([]),[c,f]=r.useState(!0);r.useEffect(()=>{const i=P(_(A,"AuditLog"),K("timestamp","desc"),X(50)),w=Z(i,m=>{const C=m.docs.map(D=>D.data());b(C),f(!1)});return()=>w()},[]);const x=i=>i.includes("SUBMIT")?"text-rose-600 bg-rose-50 border-rose-100":i.includes("IMPORT")?"text-sky-600 bg-sky-50 border-sky-100":i.includes("CREATE")?"text-emerald-600 bg-emerald-50 border-emerald-100":"text-stone-600 bg-stone-50 border-stone-100";return e.jsxs("div",{className:"space-y-8 animate-in fade-in duration-500",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black uppercase tracking-tight text-stone-800",children:"Compliance & Audit Logs"}),e.jsx("p",{className:"text-stone-500 font-medium",children:"Immutable record of all Gift Aid operations and HMRC interactions"})]}),e.jsx("div",{className:"bg-white rounded-[2.5rem] border border-stone-200 shadow-xl shadow-stone-200/50 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{className:"bg-stone-50 border-b border-stone-200 text-[10px] font-black uppercase tracking-widest text-stone-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-6",children:"Timestamp & Actor"}),e.jsx("th",{className:"p-6",children:"Action Type"}),e.jsx("th",{className:"p-6",children:"Entity Context"}),e.jsx("th",{className:"p-6",children:"Audit Evidence"})]})}),e.jsx("tbody",{className:"divide-y divide-stone-50 font-medium",children:c?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-20 text-center text-stone-300 font-black uppercase tracking-widest animate-pulse",children:"Retrieving Secure Logs..."})}):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-20 text-center text-stone-400 font-bold uppercase tracking-widest",children:"No logs found"})}):t.map(i=>{var w;return e.jsxs("tr",{className:"hover:bg-stone-50/50 transition-colors group",children:[e.jsx("td",{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-stone-100 rounded-xl flex items-center justify-center text-stone-400",children:e.jsx(re,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-stone-900 font-black text-sm",children:(w=i.timestamp)==null?void 0:w.toDate().toLocaleString()}),e.jsxs("div",{className:"text-[10px] font-black text-stone-400 uppercase tracking-widest flex items-center gap-1",children:[e.jsx(V,{className:"text-rose-400"})," ",i.actorRole," · ",i.actorUserId.slice(0,8)]})]})]})}),e.jsx("td",{className:"p-6",children:e.jsx("span",{className:`px-4 py-1.5 rounded-full text-[10px] font-black tracking-widest border ${x(i.actionType)}`,children:i.actionType})}),e.jsx("td",{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"text-stone-300"}),e.jsxs("div",{className:"text-xs font-black text-stone-600 uppercase tracking-tighter",children:[i.entityType,": ",e.jsx("span",{className:"text-rose-600",children:i.entityId.slice(0,12)})]})]})}),e.jsx("td",{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1 text-stone-400 font-mono",children:[e.jsx(Le,{})," ",i.auditId.slice(0,6)]}),e.jsx("button",{onClick:()=>console.log(i),className:"px-3 py-1 bg-stone-100 text-stone-500 rounded-lg font-black text-[9px] uppercase tracking-widest hover:bg-stone-200 transition-colors opacity-0 group-hover:opacity-100",children:"View Raw"})]})})]},i.auditId)})})]})})})]})},ze=()=>{const[t,b]=r.useState(!0),[c,f]=r.useState(!1),[x,i]=r.useState({charityName:"",regNo:"",hmrcRef:"",gatewayId:"",gatewayPassword:""});r.useEffect(()=>{(async()=>{try{const C=U(A,"Settings","GiftAidHMRC"),D=await Ge(C);D.exists()&&i(D.data())}catch(C){console.error(C),u.error("Failed to load HMRC configuration")}finally{b(!1)}})()},[]);const w=async m=>{m.preventDefault(),f(!0);try{await Pe(U(A,"Settings","GiftAidHMRC"),{...x,updatedAt:new Date}),u.success("HMRC Configuration saved successfully")}catch(C){console.error(C),u.error("Failed to save configuration")}finally{f(!1)}};return t?e.jsx("div",{className:"flex items-center justify-center p-20 animate-pulse font-black text-rose-600 tracking-widest text-xs",children:"LOADING GATEWAY CONFIGURATION..."}):e.jsxs("div",{className:"max-w-4xl space-y-12 animate-in fade-in duration-500",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-3xl font-black text-stone-800 tracking-tight",children:"HMRC Gateway Setup"}),e.jsx("p",{className:"text-stone-500 font-medium",children:"Configure your charity credentials for direct R68 submissions."})]}),e.jsxs("form",{onSubmit:w,className:"space-y-8",children:[e.jsxs("div",{className:"bg-stone-50 p-10 rounded-[3rem] border border-stone-100 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 text-rose-600 mb-2",children:[e.jsx(Oe,{className:"w-6 h-6"}),e.jsx("h3",{className:"font-black uppercase tracking-widest text-sm text-stone-700",children:"Organization Details"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Full Charity Name"}),e.jsx("input",{type:"text",value:x.charityName,onChange:m=>i({...x,charityName:m.target.value}),placeholder:"e.g. Faith Assembly Uxbridge",className:"w-full p-4 bg-white border-2 border-stone-200 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all shadow-sm",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-400 ml-1",children:"Charity Reg Number"}),e.jsx("input",{type:"text",value:x.regNo,onChange:m=>i({...x,regNo:m.target.value}),placeholder:"e.g. 1112223",className:"w-full p-4 bg-white border-2 border-stone-200 rounded-2xl font-bold outline-none focus:border-rose-500 transition-all shadow-sm",required:!0})]})]})]}),e.jsxs("div",{className:"bg-stone-900 p-10 rounded-[3rem] text-white space-y-6 shadow-2xl relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-rose-600/10 rounded-full blur-3xl -mr-32 -mt-32"}),e.jsxs("div",{className:"flex items-center gap-3 text-rose-500 mb-2 relative z-10",children:[e.jsx(Ee,{className:"w-6 h-6"}),e.jsx("h3",{className:"font-black uppercase tracking-widest text-sm text-rose-100",children:"Gateway Credentials"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 relative z-10",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-500 ml-1",children:"HMRC Reference (HMRC Ref)"}),e.jsx("input",{type:"text",value:x.hmrcRef,onChange:m=>i({...x,hmrcRef:m.target.value}),placeholder:"e.g. AB12345",className:"w-full p-4 bg-white/5 border-2 border-white/10 rounded-2xl font-bold font-mono outline-none focus:border-rose-500 transition-all",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-500 ml-1",children:"Government Gateway ID"}),e.jsx("input",{type:"text",value:x.gatewayId,onChange:m=>i({...x,gatewayId:m.target.value}),placeholder:"12-digit number",className:"w-full p-4 bg-white/5 border-2 border-white/10 rounded-2xl font-bold font-mono outline-none focus:border-rose-500 transition-all",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase text-stone-500 ml-1",children:"Gateway Password"}),e.jsx("input",{type:"password",value:x.gatewayPassword,onChange:m=>i({...x,gatewayPassword:m.target.value}),placeholder:"••••••••",className:"w-full p-4 bg-white/5 border-2 border-white/10 rounded-2xl font-bold font-mono outline-none focus:border-rose-500 transition-all",required:!0})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-8 bg-emerald-50 rounded-[2.5rem] border border-emerald-100",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-white rounded-2xl text-emerald-600 shadow-sm",children:e.jsx(V,{className:"w-8 h-8"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black text-emerald-900 uppercase text-xs tracking-widest",children:"Encrypted Storage"}),e.jsx("div",{className:"text-sm text-emerald-700 font-medium",children:"Your credentials are stored securely and used only for direct HMRC communication."})]})]}
1),e.jsxs("button",{type:"submit",disabled:c,className:"bg-rose-600 text-white px-10 py-5 rounded-[2rem] font-black text-lg shadow-xl shadow-rose-200 hover:bg-rose-700 transition-all active:scale-95 flex items-center gap-3 disabled:opacity-50",children:[e.jsx(ge,{className:"w-6 h-6"}),c?"SAVING...":"SAVE CONFIGURATION"]})]})]})]})},Ye=()=>{const t=[{title:"1. Configure HMRC Gateway",description:"Go to the 'HMRC Setup' tab and enter your Charity credentials. Your Gateway ID and HMRC Reference are required for direct digital submission.",icon:He,color:"bg-blue-500",tabName:"HMRC Setup"},{title:"2. Import Bank Statement",description:"Upload your CSV or Excel statements. Map your columns (Date, Amount, Donor Name) to our system fields for processing.",icon:ie,color:"bg-indigo-500",tabName:"Import Statement"},{title:"3. Clear Validation Queue",description:"The system automatically checks for compliance (e.g., valid postcodes, full names, 4-year limit). Fix any red flags in the Validation Queue before claiming.",icon:le,color:"bg-rose-500",tabName:"Validation Queue"},{title:"4. Build Claim Batch",description:"Group your validated donations into a 'Batch'. This creates an immutable snapshot of exactly what you are claiming from HMRC for a specific period.",icon:ce,color:"bg-amber-500",tabName:"Claim Batches"},{title:"5. Digital Submission",description:"Once happy with your batch, click 'Review & Submit'. The system generates the R68 XML, computes the IRmark, and submits directly to HMRC servers.",icon:W,color:"bg-emerald-500",tabName:"Claim Batches"}];return e.jsxs("div",{className:"max-w-5xl space-y-12 animate-in fade-in duration-500 pb-20",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-rose-600 rounded-xl text-white shadow-lg",children:e.jsx(V,{className:"w-8 h-8"})}),e.jsx("h2",{className:"text-4xl font-black text-stone-800 tracking-tight",children:"System Workflow Guide"})]}),e.jsx("p",{className:"text-xl text-stone-500 font-medium max-w-3xl",children:"Welcome to the Enterprise Gift Aid Hub. Follow these steps to automate your quarterly claims with full HMRC compliance."})]}),e.jsxs("div",{className:"grid gap-8 relative",children:[e.jsx("div",{className:"absolute left-10 top-20 bottom-20 w-1 bg-stone-100 hidden md:block"}),t.map((b,c)=>e.jsxs(q.div,{initial:{opacity:0,x:-20},whileInView:{opacity:1,x:0},viewport:{once:!0},transition:{delay:c*.1},className:"flex flex-col md:flex-row gap-8 relative items-start group",children:[e.jsx("div",{className:`shrink-0 w-20 h-20 rounded-[2rem] flex items-center justify-center text-white text-3xl shadow-xl shadow-stone-200 z-10 transition-transform group-hover:scale-110 ${b.color}`,children:e.jsx(b.icon,{})}),e.jsx("div",{className:"flex-1 bg-white p-10 rounded-[3rem] border border-stone-100 shadow-sm hover:border-rose-200 transition-all hover:shadow-xl hover:shadow-rose-50/50",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx("h3",{className:"text-2xl font-black text-stone-800 tracking-tight underline decoration-rose-500/30 decoration-4 underline-offset-4",children:b.title}),e.jsxs("span",{className:"px-4 py-1 bg-stone-50 text-stone-400 rounded-full text-[10px] font-black uppercase tracking-widest",children:["Phase ",c+1]})]}),e.jsx("p",{className:"text-stone-500 font-medium text-lg leading-relaxed",children:b.description}),e.jsxs("div",{className:"flex items-center gap-2 pt-4",children:[e.jsx("span",{className:"text-[10px] font-black text-stone-400 uppercase tracking-widest",children:"Active Tab:"}),e.jsx("span",{className:"px-3 py-1 bg-rose-50 text-rose-600 rounded-lg text-xs font-black uppercase tracking-widest",children:b.tabName})]})]})})]},c))]}),e.jsxs("div",{className:"bg-stone-900 p-12 rounded-[4rem] text-white overflow-hidden relative shadow-2xl",children:[e.jsx("div",{className:"absolute top-0 right-0 w-96 h-96 bg-rose-600/20 rounded-full blur-3xl -mr-48 -mt-48"}),e.jsxs("div",{className:"relative z-10 space-y-6",children:[e.jsx("h3",{className:"text-3xl font-black tracking-tight",children:"Ready to start?"}),e.jsx("p",{className:"text-stone-400 font-medium text-lg max-w-2xl",children:'Begin by checking your HMRC credentials in the setup tab. If you encounter any "Validation Queue" items, ensure you have the correct donor addresses and declarations on file.'}),e.jsxs("div",{className:"flex gap-4 pt-4 text-xs font-black uppercase tracking-[0.2em] text-stone-500",children:[e.jsx("span",{children:"Compliance Guaranteed"}),e.jsx("span",{children:"•"}),e.jsx("span",{children:"Direct HMAC Encryption"}),e.jsx("span",{children:"•"}),e.jsx("span",{children:"Audit Trail Enabled"})]})]})]})]})},tt=()=>
1{const[t,b]=r.useState("dashboard"),c=[{id:"dashboard",label:"Dashboard",icon:V},{id:"guide",label:"How it Works",icon:be},{id:"import",label:"Import Statement",icon:ie},{id:"validation",label:"Validation Queue",icon:le},{id:"batches",label:"Claim Batches",icon:ce},{id:"history",label:"Audit & Submission",icon:re},{id:"setup",label:"HMRC Setup",icon:V}];return e.jsx("div",{className:"min-h-screen bg-stone-50/50 p-4 md:p-8 font-sans text-stone-900",children:e.jsxs("div",{className:"max-w-7xl mx-auto space-y-8",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-black tracking-tight flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-rose-600 shadow-lg shadow-rose-200 rounded-xl text-white",children:e.jsx(Fe,{className:"w-8 h-8"})}),"Enterprise Gift Aid"]}),e.jsx("p",{className:"text-stone-500 font-medium mt-1",children:"Direct HMRC Integration & Compliance Hub"})]}),e.jsx("div",{className:"flex bg-white p-1 rounded-2xl shadow-sm border border-stone-200",children:c.map(f=>e.jsxs("button",{onClick:()=>b(f.id),className:`flex items-center gap-2 px-6 py-3 rounded-xl font-bold text-sm transition-all ${t===f.id?"bg-rose-600 text-white shadow-md":"text-stone-500 hover:text-stone-900 hover:bg-stone-50"}`,children:[e.jsx(f.icon,{className:"w-5 h-5"}),e.jsx("span",{className:"hidden lg:inline",children:f.label})]},f.id))})]}),e.jsx("div",{className:"bg-white rounded-[2.5rem] shadow-xl shadow-stone-200/50 border border-stone-100 overflow-hidden min-h-[70vh]",children:e.jsx(Ne,{mode:"wait",children:e.jsxs(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"p-8",children:[t==="dashboard"&&e.jsx($e,{onBuildClick:()=>b("batches"),onHistoryClick:()=>b("history")}),t==="guide"&&e.jsx(Ye,{}),t==="import"&&e.jsx(_e,{}),t==="validation"&&e.jsx(Ve,{}),t==="batches"&&e.jsx(qe,{}),t==="history"&&e.jsx(Qe,{}),t==="setup"&&e.jsx(ze,{})]},t)})})]})})};export{tt as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.