import{t as e}from"./funnel-D_tjolhV.js";import{i as t,n,r,t as i}from"./accordion-hb1BiBOM.js";import{Cn as a,Eu as o,Fl as s,Hl as c,Kl as l,Ld as u,Nl as d,P as f,Pd as p,Pl as m,Tn as h,Vl as g,_i as _,bl as v,dn as y,ed as b,ju as x,nr as S,ql as C,rn as w,sr as T,tr as E,vd as D,zd as O}from"./index-Q5R6-AeA.js";import{t as k}from"./use-url-query-Cos8nKH-.js";import{t as A}from"./page-layout-Cl29SycZ.js";var j=u((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.calcSlices=e.applyPatch=e.calcPatch=e.lcs=e.diff=e.diff_core=void 0;function t(e,t){let{b:n,eq:r,stack_base:i}=e,{i:a,N:o,j:s,M:c,Z:l,stack_top:u}=e;for(;;)switch(t){case 0:Z_block:for(;o>0&&c>0;){n.fill(0,0,2*l);let e=o-c,t=o+c,d=t&1,f=a+o-1,p=s+c-1,m=(t+d)/2,h;h_loop:for(let t=0;t<=m;t++){let m=2*Math.max(0,t-c)-t,g=t-2*Math.max(0,t-o);for(let f=m;f<=g;f+=2){let p=n[f-1-l*Math.floor((f-1)/l)],m=n[f+1-l*Math.floor((f+1)/l)],g=f===-t||f!==t&&p<m?m:p+1,_=g-f,v=g,y=_;for(;v<o&&y<c&&r(a+v,s+y);)v++,y++;if(n[f-l*Math.floor(f/l)]=v,d===1&&(h=e-f)>=1-t&&h<t&&v+n[l+h-l*Math.floor(h/l)]>=o)if(t>1||v!==g){i[u++]=a+v,i[u++]=o-v,i[u++]=s+y,i[u++]=c-y,o=g,c=_,l=2*(Math.min(o,c)+1);continue Z_block}else break h_loop}for(let _=m;_<=g;_+=2){let m=n[l+_-1-l*Math.floor((_-1)/l)],g=n[l+_+1-l*Math.floor((_+1)/l)],v=_===-t||_!==t&&m<g?g:m+1,y=v-_,b=v,x=y;for(;b<o&&x<c&&r(f-b,p-x);)b++,x++;if(n[l+_-l*Math.floor(_/l)]=b,d===0&&(h=e-_)>=-t&&h<=t&&b+n[h-l*Math.floor(h/l)]>=o)if(t>0||b!==v){i[u++]=a+o-v,i[u++]=v,i[u++]=s+c-y,i[u++]=y,o-=b,c-=x,l=2*(Math.min(o,c)+1);continue Z_block}else break h_loop}}if(o!==c){c>o?(a+=o,s+=o,c-=o,o=0):(a+=c,s+=c,o-=c,c=0);break}}if(o+c!==0)if(e.pxe===a||e.pye===s)e.pxe=a+o,e.pye=s+c;else{let t=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=a,e.pxe=a+o,e.pys=s,e.pye=s+c,t>=0)return e.i=a,e.N=o,e.j=s,e.M=c,e.Z=l,e.stack_top=u,1}case 1:if(u===0)return 2;c=i[--u],s=i[--u],o=i[--u],a=i[--u],l=2*(Math.min(o,c)+1),t=0}}var n=class{constructor(e){this.state=e,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){let{state:e,result:n}=this;if(this.c>1)return n.done=!0,n.value=void 0,n;let r=t(e,this.c);return this.c=r,r===1?(n.value=[e.oxs,e.oxe,e.oys,e.oye],n):e.pxs>=0?(n.value=[e.pxs,e.pxe,e.pys,e.pye],n):(n.done=!0,n.value=void 0,n)}};function r(e,t,r,i,a){let o=(Math.min(t,i)+1)*2,s=t+i;return new n({i:e,N:t,j:r,M:i,Z:o,b:new(s<256?Uint8Array:s<65536?Uint16Array:Uint32Array)(2*o),eq:a,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}e.diff_core=r;function i(e,t,n){let[i,a,o]=[0,e.length,t.length];if(typeof n==`function`){for(;i<a&&i<o&&n(i,i);)i++;if(i===a&&i===o)return[][Symbol.iterator]();for(;n(--a,--o)&&a>i&&o>i;);}else{for(;i<a&&i<o&&e[i]===t[i];)i++;if(i===a&&i===o)return[][Symbol.iterator]();for(;e[--a]===t[--o]&&a>i&&o>i;);n=(n,r)=>e[n]===t[r]}return r(i,a+1-i,i,o+1-i,n)}e.diff=i;var a=class{constructor(e,t){this.diff=e,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){let e=this.diff.next();if(e.done){let{i:t,j:n,N:r}=this;return t<r&&(e.done=!1,e.value=[t,n,r-t],this.i=r),e}let t=e.value,n=t[0],r=t[1],i=t[3],{i:a,j:o}=this;return a!==n&&(t.length--,t[0]=a,t[1]=o,t[2]=n-a),this.i=r,this.j=i,e}};function o(e,t,n){return new a(i(e,t,n),e.length)}e.lcs=o;function*s(e,t,n){let r=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let a of i(e,t,n))a[2]=r.call(t,a[2],a[3]),yield a}e.calcPatch=s;function*c(e,t){let n=0,r=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let[i,a,o]of t)n<i&&(yield r.call(e,n,i)),o.length>0&&(yield o),n=a;n<e.length&&(yield r.call(e,n))}e.applyPatch=c;function*l(e,t,n){let r=0,a=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let[o,s,c,l]of i(e,t,n))r<o&&(yield[0,a.call(e,r,o)]),o<s&&(yield[-1,a.call(e,o,s)]),c<l&&(yield[1,a.call(t,c,l)]),r=s;r<e.length&&(yield[0,e.slice(r)])}e.calcSlices=l})),M=O(p(),1),N=j(),P=o(),F=({children:e})=>(0,P.jsx)(`span`,{className:`bg-green-100`,children:e}),I=({children:e})=>(0,P.jsx)(`span`,{className:`bg-red-100 line-through`,children:e}),L=({children:e})=>(0,P.jsx)(`span`,{children:e}),R=({content:e,contentOrigin:t,monthDate:n})=>{let r=(0,M.useMemo)(()=>{let n=[];if(!t)return n;let r=e.split(``),i=t.split(``),a=Array.from((0,N.calcPatch)(i,r)),o=[],s=0;for(let[e,t,r]of a)if(o.length===0&&e>=17&&t<=25&&r.length===t-e){if(a.length===1)return n;continue}else s<e&&o.push([i.slice(s,e).join(``),L]),t>e&&o.push([i.slice(e,t).join(``),I]),r.length>0&&o.push([r.join(``),F]),s=t;s<i.length&&o.push([i.slice(s).join(``),L]);let c=[];for(let[e,t]of o){let r=e.split(`
`);r.length===1?c.push((0,P.jsx)(t,{children:e},`unchanged-${c.length}`)):r.map((e,r)=>{c.push((0,P.jsx)(t,{children:e},r)),n.push((0,P.jsx)(`div`,{children:c},n.length-1)),c=[]})}return c.length>0&&n.push((0,P.jsx)(`div`,{children:c},n.length-1)),n},[e,t]);return(0,P.jsxs)(`div`,{className:`flex flex-col`,children:[(0,P.jsxs)(`div`,{className:`text-sm text-gray-500 flex flex-row gap-2`,children:[(0,P.jsx)(`span`,{className:`font-bold`,children:`Month:`}),(0,P.jsx)(`span`,{children:n.slice(0,7)}),!r.length&&(0,P.jsx)(D,{className:`text-green-500`})]}),!!r.length&&r]})},z=({filter:e})=>{let[{data:t,fetching:n,hasNext:r}]=d({query:v,variables:e}),i=(0,M.useMemo)(()=>[...t?.pcnByDate??[]].sort((e,t)=>t.date>e.date?1:t.date<e.date?-1:0),[t?.pcnByDate]);return n?(0,P.jsx)(`div`,{className:`w-full h-full flex justify-center`,children:(0,P.jsx)(b,{className:`h-10 w-10 animate-spin mr-2 self-center`})}):(0,P.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[!!t&&r&&(0,P.jsx)(`div`,{className:`w-full h-full flex justify-center`,children:(0,P.jsx)(b,{className:`h-10 w-10 animate-spin mr-2 self-center`})}),i.map((e,t)=>(0,P.jsx)(R,{content:e.content,contentOrigin:e.diffContent,monthDate:e.date},t))]})},B=O(_(),1);function V({filter:e,setFilter:t,closeModal:n}){let{control:r,handleSubmit:i,setValue:o}=h({defaultValues:{...e}}),{selectableBusinesses:c,fetching:l}=w();return(0,P.jsxs)(P.Fragment,{children:[l?(0,P.jsx)(`div`,{children:`Loading...`}):(0,P.jsx)(`div`,{}),(0,P.jsxs)(`form`,{onSubmit:i(e=>{t(e),n()}),children:[(0,P.jsx)(a,{name:`businessId`,control:r,defaultValue:void 0,render:({field:e,fieldState:t})=>(0,P.jsx)(T,{...e,data:c,value:e.value,disabled:l,label:`Businesses`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message})}),(0,P.jsx)(y,{label:`From date`,defaultValue:e?.fromMonthDate?new Date(e.fromMonthDate):new Date,defaultDate:e?.fromMonthDate?new Date(e.fromMonthDate):new Date,onChange:e=>{o(`fromMonthDate`,s(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}}),(0,P.jsx)(y,{label:`To date`,defaultValue:e?.toMonthDate?new Date(e.toMonthDate):new Date,defaultDate:e?.toMonthDate?new Date(e.toMonthDate):new Date,onChange:e=>{o(`toMonthDate`,s(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}}),(0,P.jsxs)(`div`,{className:`flex justify-center mt-5 gap-3`,children:[(0,P.jsx)(C,{type:`submit`,children:`Filter`}),(0,P.jsx)(C,{type:`button`,onClick:n,children:`Cancel`})]})]})]})}function H({filter:t,setFilter:n}){let[r,i]=(0,M.useState)(!1),{get:a,set:o}=k(),{userContext:c}=(0,M.useContext)(S);function l(e){e||={businessId:c?.context.adminBusinessId??t.businessId,fromMonthDate:s(m(new Date,1),`yyyy-MM-15`),toMonthDate:s(new Date,`yyyy-MM-15`)},(0,B.default)(e,t)||n(e)}return(0,M.useEffect)(()=>{let e=x(t??{});e!==a(`validateReportsFilters`)&&o(`validateReportsFilters`,e)},[t,a,o]),(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(f,{opened:r,onClose:()=>i(!1),content:(0,P.jsx)(V,{filter:t,setFilter:l,closeModal:()=>i(!1)})}),(0,P.jsx)(C,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>i(!0),children:(0,P.jsx)(e,{className:`size-5`})})]})}var U=()=>{let{get:e}=k(),{setFiltersContext:a}=(0,M.useContext)(E),[o,u]=(0,M.useState)((0,M.useMemo)(()=>{try{if(e(`validateReportsFilters`))return JSON.parse(decodeURIComponent(e(`validateReportsFilters`)))}catch(e){console.error(`Error parsing filter from URL`,e)}return{fromMonthDate:s(m(new Date,1),`yyyy-MM-15`),toMonthDate:s(new Date,`yyyy-MM-15`)}},[e]));return(0,M.useEffect)(()=>{a((0,P.jsx)(`div`,{className:`flex flex-row gap-2`,children:(0,P.jsx)(H,{filter:{...o},setFilter:u})}))},[o,a]),(0,P.jsx)(A,{title:`Report Validations`,children:(0,P.jsx)(i,{type:`single`,collapsible:!0,children:(0,P.jsx)(r,{value:`pcn874`,children:(0,P.jsxs)(g,{className:`p-4`,children:[(0,P.jsx)(t,{children:(0,P.jsx)(l,{children:`Monthly VAT (PCN874)`})}),(0,P.jsx)(n,{children:(0,P.jsx)(c,{children:(0,P.jsx)(z,{filter:o})})})]})})})})};export{U as ValidateReportsScreen};