@buzztech/boi-ui 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/boi-ui.js +609 -594
- package/dist/boi-ui.js.map +1 -1
- package/dist/boi-ui.umd.cjs +1 -1
- package/dist/boi-ui.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/boi-ui.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(S,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(S=typeof globalThis<"u"?globalThis:S||self,e(S.BoiUi={},S.Vue))})(this,(function(S,e){"use strict";const H=((o,y)=>{const t=o.__vccOpts||o;for(const[m,c]of y)t[m]=c;return t})(e.defineComponent({__name:"BoiButton",props:{label:{},variant:{}},setup(o){return(y,t)=>(e.openBlock(),e.createElementBlock("button",{type:"button",class:e.normalizeClass(["boi-button",[o.variant?`boi-button--${o.variant}`:"boi-button--primary"]])},[e.renderSlot(y.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(o.label),1)],!0)],2))}}),[["__scopeId","data-v-96425342"]]);function W(...o){return o.flat(1/0).filter(Boolean).join(" ")}const pe="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",fe={default:"bg-primary text-white shadow-xs hover:bg-primary/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-white shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},be={default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"};function ge(o={}){const y=o.variant??"default",t=o.size??"default";return[pe,fe[y],be[t]].join(" ")}const ke=["type","disabled"],q=e.defineComponent({__name:"Button",props:{type:{default:"button"},variant:{default:"default"},size:{default:"default"},class:{type:[Boolean,null,String,Object,Array]},disabled:{type:Boolean,default:!1}},setup(o){const y=o;return(t,m)=>(e.openBlock(),e.createElementBlock("button",{type:o.type,disabled:o.disabled,"data-slot":"button",class:e.normalizeClass(e.unref(W)(e.unref(ge)({variant:y.variant,size:y.size}),y.class))},[e.renderSlot(t.$slots,"default")],10,ke))}}),z={getBanks:()=>"/api/edoc/banks",initializeConsent:()=>"/api/edoc/consent/initialize",attachAccount:()=>"/api/edoc/consent/attach-account",getTransactions:()=>"/api/edoc/consent/transactions",manualUpload:()=>"/api/edoc/manual-upload"},ye={class:"boi-emts-integration space-y-4"},he={key:0},xe={class:"boi-emts-instructions rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm"},Be={class:"list-inside list-decimal space-y-1 text-amber-800"},we=["disabled"],Ee={key:1,class:"boi-emts-otp space-y-3 rounded-lg border-2 border-primary bg-primary/5 p-4"},Ve={class:"flex flex-wrap items-end gap-3"},ve={class:"min-w-[140px]"},_e=["disabled"],Se={key:1,class:"text-sm text-red-600"},Ne={key:2,class:"text-sm text-amber-600"},J="inline-flex items-center justify-center rounded-md bg-black px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-neutral-900 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",Q=e.defineComponent({__name:"EmtsIntegration",props:{account:{},edocBanks:{},bankOptions:{},api:{},companyEmail:{},industrialSector:{},applicationId:{},disabled:{type:Boolean,default:!1},integrationBaseUrl:{default:""}},emits:["update:consentId","statement-retrieved","error"],setup(o,{emit:y}){const t=o;function m(l){const r=(t.integrationBaseUrl??"").replace(/\/$/,"");if(!r)return l;const f=l.startsWith("/")?l:`/${l}`;return`${r}${f}`}const c=y,E=e.ref(!1),V=e.ref(!1);function d(l){const r=t.bankOptions.find(f=>f.value===l);return[(r==null?void 0:r.label)??"",...(r==null?void 0:r.searchKeywords)??[]].filter(Boolean)}function h(l,r=!1){if(!l||!t.edocBanks.length)return;const f=d(l);return t.edocBanks.find(b=>{const D=b.bankCode===l||b.code===l,I=f.some(P=>{var O;return(O=b.name)==null?void 0:O.toLowerCase().includes(P.toLowerCase())});return(D||I)&&(!r||b.enabled!==!1)})}const _=l=>h(l,!1),B=l=>!!h(l,!0),C=e.computed(()=>{var l,r;return!!((r=(l=_(t.account.bank))==null?void 0:l.bankInstructions)!=null&&r.length)}),w=e.computed(()=>{var r;const l=t.account;return!!l.bank&&((r=l.account_number)==null?void 0:r.length)===10&&!E.value&&!V.value}),v=e.computed(()=>!!t.account.otp&&!V.value),A=l=>{var r,f,b;return((f=(r=l==null?void 0:l.response)==null?void 0:r.data)==null?void 0:f.message)??((b=l==null?void 0:l.data)==null?void 0:b.message)??(l==null?void 0:l.message)??"An unexpected error occurred"},M=l=>({email:l,referenceId:`loan_${t.applicationId??"new"}_${t.account.id}`,firstName:"Company",lastName:"Account",state:"Lagos",fundType:"online portal",statementDuration:"12",redirectionUrl:typeof window<"u"?window.location.origin+"/loan-application":"",industrialSector:t.industrialSector??void 0});async function g(l){var I,P;const r=t.account.email||t.companyEmail||"",f=await t.api.post(m(z.initializeConsent()),M(r)),b=f==null?void 0:f.data;if(!(b!=null&&b.success))throw new Error((b==null?void 0:b.message)??"Failed to initialize consent");const D=(P=(I=b==null?void 0:b.data)==null?void 0:I.data)==null?void 0:P.consentId;if(!D)throw new Error("No consent ID returned");return c("update:consentId",D),await t.api.post(m(z.attachAccount()),{consentId:D,bankId:l.bankId,accountNumber:t.account.account_number,accountType:"Business",statementDuration:"12",monthType:"Period",uploadType:"Digital"}),D}async function k(){var r;const l=_(t.account.bank);if(!t.account.bank)return c("error","Please select a bank");if(((r=t.account.account_number)==null?void 0:r.length)!==10)return c("error","Please provide a valid 10-digit account number");if(!l)return c("error","Selected bank does not support electronic statement retrieval");E.value=!0;try{await g(l)}catch(f){c("error",A(f))}finally{E.value=!1}}async function x(){var l;if(!t.account.otp||!t.account.consent_id)return c("error","Please enter OTP");V.value=!0;try{const r=await t.api.post(m(z.getTransactions()),{consentId:t.account.consent_id,verificationCode:t.account.otp,bankStatementId:t.account.id}),f=r==null?void 0:r.data;if(!(f!=null&&f.success))return c("error",(f==null?void 0:f.message)??"Failed to retrieve transactions");(l=f.data)!=null&&l.statement&&c("statement-retrieved",f.data.statement)}catch(r){c("error",A(r))}finally{V.value=!1}}async function p(){var r,f;const l=_(t.account.bank);if(!t.account.bank||((r=t.account.account_number)==null?void 0:r.length)!==10)return c("error","Please select a bank and provide a valid 10-digit account number");if(!l)return c("error","Selected bank does not support electronic statement retrieval");V.value=!0;try{const b=await g(l),D=await t.api.post(m(z.getTransactions()),{consentId:b,verificationCode:"",bankStatementId:t.account.id}),I=D==null?void 0:D.data;if(!(I!=null&&I.success))return c("error",(I==null?void 0:I.message)??"Failed to retrieve transactions");(f=I.data)!=null&&f.statement&&c("statement-retrieved",I.data.statement)}catch(b){c("error",A(b))}finally{V.value=!1}}return(l,r)=>{var f;return e.openBlock(),e.createElementBlock("div",ye,[B(o.account.bank)?(e.openBlock(),e.createElementBlock("div",he,[C.value&&!o.account.statement_generated?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("div",xe,[r[1]||(r[1]=e.createElementVNode("p",{class:"mb-2 font-semibold text-amber-900"},"Bank-specific instructions",-1)),e.createElementVNode("ol",Be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList((f=_(o.account.bank))==null?void 0:f.bankInstructions,(b,D)=>(e.openBlock(),e.createElementBlock("li",{key:D},e.toDisplayString(b),1))),128))])]),e.createVNode(H,{label:V.value?"Retrieving…":"Retrieve statement",variant:"primary",disabled:!w.value||o.disabled,onClick:p},null,8,["label","disabled"])],64)):!C.value&&!o.account.statement_generated?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[o.account.showOtpInput?(e.openBlock(),e.createElementBlock("div",Ee,[r[3]||(r[3]=e.createElementVNode("p",{class:"text-sm font-medium text-gray-700"},"Enter the OTP sent to your bank-registered email.",-1)),e.createElementVNode("div",Ve,[e.createElementVNode("div",ve,[r[2]||(r[2]=e.createElementVNode("label",{class:"mb-1 block text-xs font-medium text-gray-600"},"OTP code",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":r[0]||(r[0]=b=>o.account.otp=b),type:"text",maxlength:"6",placeholder:"6-digit OTP",class:"w-full rounded border border-gray-300 px-3 py-2 text-lg tracking-widest"},null,512),[[e.vModelText,o.account.otp]])]),e.createElementVNode("button",{type:"button",class:e.normalizeClass(J),disabled:!v.value||o.disabled,onClick:x}," Verify OTP ",8,_e)])])):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(J),disabled:!w.value||o.disabled,onClick:k},e.toDisplayString(E.value?"Sending OTP…":"Send OTP"),9,we))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),o.account.edoc_status==="failed"?(e.openBlock(),e.createElementBlock("div",Se,"Statement retrieval failed. Please try again or upload manually.")):e.createCommentVNode("",!0),o.account.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("div",Ne,"Processing…")):e.createCommentVNode("",!0)])}}});function Ce(o){if(!o||typeof o!="object")return[];const y=o,t=y.success?y.data:y.data??y;return Array.isArray(t)?t:t&&typeof t=="object"&&Array.isArray(t.data)?t.data:[]}function Y(o,y){return o===void 0?y:typeof o=="function"?o():o}function Z(o){const{get:y,getBanksUrl:t,fallbackBanksUrl:m}=o,c=e.ref([]),E=e.ref([]),V=e.ref(!1),d=e.ref(null);let h=null;return{edocBanks:c,banks:E,loading:V,error:d,loadBanksForStatement:async()=>c.value.length>0?c.value:h||(V.value=!0,d.value=null,h=(async()=>{var C,w;try{const v=await y(Y(t,z.getBanks())),A=Ce(v==null?void 0:v.data);if(A.length)return c.value=E.value=A,A}catch{}const B=m!=null?Y(m,""):"";if(B)try{const v=await y(B),A=Array.isArray(v==null?void 0:v.data)?v.data:[];return c.value=E.value=A,A}catch(v){throw d.value=((w=(C=v==null?void 0:v.response)==null?void 0:C.data)==null?void 0:w.message)??"Failed to load banks",v}return[]})().finally(()=>{V.value=!1,h=null}),h),invalidateCache:()=>{c.value=E.value=[],h=null,d.value=null}}}const L=e.ref({});function ee(o){const y=()=>typeof o=="function"&&o.length===0?o():o,t=d=>`${d.bank??""}_${d.account_number??""}`,m=d=>{const h=t(d);return L.value[h]??{isLoading:!1,isSuccess:!1,isError:!1}},c=d=>{d.account_name=""},E=async d=>{const h=d.bank,_=d.account_number,B=t(d),C=y();if(!C||!h||!_||_.length!==10){delete L.value[B],(_==null?void 0:_.length)!==10&&c(d);return}c(d),L.value[B]={isLoading:!0,isSuccess:!1,isError:!1};try{const w=await C(_,h),v=(w==null?void 0:w.account_name)??(w==null?void 0:w.accountName)??"";v?(d.account_name=v,L.value[B]={isLoading:!1,isSuccess:!0,isError:!1}):L.value[B]={isLoading:!1,isSuccess:!1,isError:!0,errorMessage:"Account verification failed"}}catch(w){L.value[B]={isLoading:!1,isSuccess:!1,isError:!0,errorMessage:w instanceof Error?w.message:"Verification failed"}}};return{handleAccountVerification:E,retryVerification:d=>E(d),getVerificationState:m,clearAccountName:c}}const te="/api/loan-applications";function ne(o,y=""){const t=y?`${y.replace(/\/$/,"")}${te}`:te,m=String(o);return{index:`${t}/${m}/bank-statements`,store:`${t}/${m}/bank-statements`,update:c=>`${t}/${m}/bank-statements/${c}`,destroy:c=>`${t}/${m}/bank-statements/${c}`,uploadToEdoc:c=>`${t}/${m}/bank-statements/${c}/upload-to-edoc`}}const ae={urls:ne},oe="",K={upload:()=>`${oe}/api/files/upload`,view:o=>`${oe}/api/files/view?path=${encodeURIComponent(o)}`},$e=["id","disabled"],Ae={class:"truncate text-left"},De={key:0,class:"absolute z-[1000] mt-1 w-full rounded-lg border border-gray-200 bg-white shadow-lg"},Ie={class:"border-b border-gray-100 p-2"},Ue={class:"relative"},Te={class:"max-h-48 overflow-auto py-1"},Fe=["onClick"],Pe={key:0,class:"px-3 py-2 text-center text-sm italic text-gray-500"},le=e.defineComponent({__name:"BankSelect",props:{modelValue:{},options:{},placeholder:{default:"Select bank"},disabled:{type:Boolean,default:!1},id:{}},emits:["update:modelValue"],setup(o,{emit:y}){const t=o,m=y,c=e.ref(!1),E=e.ref(null),V=e.ref(null),d=e.ref(""),h=e.ref(-1);function _(k,x){if(!x)return!0;const p=[k.label,k.shortName,...k.searchKeywords??[]].filter(r=>r!=null&&String(r).trim()!=="").map(r=>String(r).toLowerCase());if(p.some(r=>r.includes(x)))return!0;const l=x.split(/\s+/).filter(Boolean);return l.length>1?l.every(r=>p.some(f=>f.includes(r))):p.some(r=>r.startsWith(x))}const B=e.computed(()=>{var x;if(!((x=t.options)!=null&&x.length))return[];if(!d.value.trim())return t.options;const k=d.value.toLowerCase().trim();return t.options.filter(p=>_(p,k))}),C=e.computed(()=>{var k;return((k=t.options)==null?void 0:k.find(x=>String(x.value)===String(t.modelValue)))??null}),w=e.computed(()=>{var k;return((k=C.value)==null?void 0:k.label)??t.placeholder});function v(){t.disabled||(c.value=!c.value,c.value&&(d.value="",h.value=B.value.length?0:-1,e.nextTick(()=>{var k;return(k=V.value)==null?void 0:k.focus()})))}function A(k){m("update:modelValue",String(k.value)),c.value=!1,d.value=""}function M(k){if(!c.value)return;const x=B.value;switch(k.key){case"ArrowDown":k.preventDefault(),h.value=Math.min(h.value+1,x.length-1);break;case"ArrowUp":k.preventDefault(),h.value=Math.max(h.value-1,0);break;case"Enter":k.preventDefault(),h.value>=0&&x[h.value]&&A(x[h.value]);break;case"Escape":k.preventDefault(),c.value=!1;break}}function g(k){E.value&&!E.value.contains(k.target)&&(c.value=!1)}return e.watch(d,()=>{h.value=B.value.length?0:-1}),e.onMounted(()=>{typeof document<"u"&&document.addEventListener("click",g)}),e.onUnmounted(()=>{typeof document<"u"&&document.removeEventListener("click",g)}),(k,x)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"selectRef",ref:E,class:"relative"},[e.createElementVNode("button",{type:"button",id:o.id,disabled:o.disabled,class:e.normalizeClass(e.unref(W)("flex h-9 w-full min-w-0 items-center justify-between rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm transition-colors outline-none","focus:border-[var(--boi-primary)] focus:ring-1 focus:ring-[var(--boi-primary)]","disabled:cursor-not-allowed disabled:opacity-50",!C.value&&"text-gray-500")),onClick:v},[e.createElementVNode("span",Ae,e.toDisplayString(w.value),1),(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(["h-4 w-4 shrink-0 text-gray-400",{"rotate-180":c.value}]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[...x[1]||(x[1]=[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"},null,-1)])],2))],10,$e),c.value?(e.openBlock(),e.createElementBlock("div",De,[e.createElementVNode("div",Ie,[e.createElementVNode("div",Ue,[x[2]||(x[2]=e.createElementVNode("svg",{class:"absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),e.withDirectives(e.createElementVNode("input",{ref_key:"searchRef",ref:V,"onUpdate:modelValue":x[0]||(x[0]=p=>d.value=p),type:"text",placeholder:"Type to search...",class:"w-full rounded-md border-0 bg-gray-50 py-2 pl-9 pr-3 text-sm focus:bg-white focus:ring-1 focus:ring-[var(--boi-primary)]",onKeydown:M},null,544),[[e.vModelText,d.value]])])]),e.createElementVNode("div",Te,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,(p,l)=>(e.openBlock(),e.createElementBlock("button",{key:p.value,type:"button",class:e.normalizeClass(e.unref(W)("w-full cursor-pointer px-3 py-2.5 text-left text-sm transition-colors text-gray-900",l===h.value?"bg-gray-100":"hover:bg-gray-50",String(p.value)===String(o.modelValue)&&o.modelValue!==""&&o.modelValue!==void 0&&"font-semibold text-[#016837]")),onClick:r=>A(p)},e.toDisplayString(p.label),11,Fe))),128)),B.value.length===0?(e.openBlock(),e.createElementBlock("p",Pe,' No options found for "'+e.toDisplayString(d.value)+'" ',1)):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)],512))}}),Oe={class:"boi-file-input w-full space-y-2"},ze=["accept","disabled","id"],Me={class:"truncate text-sm text-gray-600"},Le={key:0,class:"text-sm text-red-600"},je={key:1,class:"text-xs text-gray-500"},Re=["href"],se=e.defineComponent({__name:"FileInput",props:{modelValue:{default:""},placeholder:{default:"Choose file"},accept:{default:"*/*"},disabled:{type:Boolean,default:!1},id:{},maxSize:{default:10*1024*1024},allowedTypes:{default:()=>["application/pdf","image/jpeg","image/jpg","image/png","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/plain","text/csv"]},uploadToServer:{type:Boolean,default:!0},showRequirements:{type:Boolean,default:!0},uploadContext:{},afterUpload:{},uploadUrl:{},viewApiBase:{},viewStoragePath:{},post:{}},emits:["update:modelValue","validation-error","validation-success","uploaded"],setup(o,{emit:y}){const t=o,m=y,c=e.ref(),E=e.ref(!1),V=e.ref(""),d=e.ref(""),h={"application/pdf":"PDF","image/jpeg":"JPG","image/jpg":"JPG","image/png":"PNG","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","text/plain":"TXT","text/csv":"CSV"},_={pdf:["application/pdf"],jpg:["image/jpeg","image/jpg"],jpeg:["image/jpeg","image/jpg"],png:["image/png"],doc:["application/msword"],docx:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],xls:["application/vnd.ms-excel"],xlsx:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],txt:["text/plain"],csv:["text/csv"]},B=e.computed(()=>[...new Set(t.allowedTypes.map(p=>{var l;return h[p]||((l=p.split("/")[1])==null?void 0:l.toUpperCase())||p}))].join(", ")),C=e.computed(()=>Math.round(t.maxSize/(1024*1024))),w=e.computed(()=>t.disabled||E.value),v=e.computed(()=>String(t.viewApiBase??"").trim().replace(/\/$/,"")),A=e.computed(()=>{const p=String(t.viewStoragePath??"").trim();return p||String(t.modelValue??"").trim()}),M=e.computed(()=>{const p=A.value;if(!p||!t.uploadToServer)return"#";const l=encodeURIComponent(p),r=v.value;return r?`${r}/api/files/view?path=${l}`:K.view(p)});function g(p){var l;if(d.value="",p.size>t.maxSize){const r=`File size must be less than ${C.value}MB`;return d.value=r,m("validation-error",r),!1}if(t.allowedTypes.length){const r=((l=p.name.split(".").pop())==null?void 0:l.toLowerCase())||"";if(!(t.allowedTypes.includes(p.type)||(_[r]||[]).some(b=>t.allowedTypes.includes(b)))){const b=`Only ${B.value} files are allowed`;return d.value=b,m("validation-error",b),!1}}return!0}async function k(p){var f,b,D,I;d.value="";const l=p.target,r=(f=l.files)==null?void 0:f[0];if(!r){V.value="",m("update:modelValue","");return}if(!g(r)){l.value="",V.value="",m("update:modelValue","");return}if(t.uploadToServer&&t.post){E.value=!0;const P=t.uploadUrl??K.upload(),O=new FormData;O.append("file",r),O.append("folder","documents"),t.uploadContext&&O.append("context",t.uploadContext);try{const T=await t.post(P,O,{headers:{"Content-Type":"multipart/form-data"}}),N=T==null?void 0:T.data;if(N!=null&&N.success&&(N!=null&&N.path))V.value=r.name,N.url&&console.log("[FileInput] S3 URL:",N.url),m("update:modelValue",N.path),m("validation-success","File uploaded successfully"),m("uploaded",N.path),(b=t.afterUpload)==null||b.call(t,N.path);else{const X=(N==null?void 0:N.message)??"Upload failed";d.value=X,m("validation-error",X),l.value="",V.value="",m("update:modelValue","")}}catch(T){const N=((I=(D=T==null?void 0:T.response)==null?void 0:D.data)==null?void 0:I.message)??(T==null?void 0:T.message)??"Upload failed";d.value=N,m("validation-error",N),l.value="",V.value="",m("update:modelValue","")}finally{E.value=!1}}else V.value=r.name,m("update:modelValue",r.name),m("uploaded",r.name)}function x(){!w.value&&c.value&&c.value.click()}return e.watch(()=>t.modelValue,p=>{V.value=(typeof p=="string"&&p?p.split("/").pop():"")||""},{immediate:!0}),(p,l)=>(e.openBlock(),e.createElementBlock("div",Oe,[e.createElementVNode("input",{ref_key:"fileInput",ref:c,type:"file",accept:o.accept,disabled:w.value,id:o.id,class:"hidden",onChange:k},null,40,ze),e.createElementVNode("div",{class:e.normalizeClass(["flex w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3 py-2 transition-colors",w.value?"cursor-not-allowed opacity-50":"cursor-pointer hover:bg-gray-50",d.value?"border-red-500":""]),onClick:x},[e.createElementVNode("span",Me,e.toDisplayString(E.value?"Uploading...":V.value||o.placeholder),1),l[0]||(l[0]=e.createElementVNode("span",{class:"text-gray-400"},"📎",-1))],2),d.value?(e.openBlock(),e.createElementBlock("p",Le,e.toDisplayString(d.value),1)):e.createCommentVNode("",!0),o.showRequirements?(e.openBlock(),e.createElementBlock("p",je,"Max "+e.toDisplayString(C.value)+" MB. Allowed: "+e.toDisplayString(B.value)+".",1)):e.createCommentVNode("",!0),A.value&&!E.value&&o.uploadToServer?(e.openBlock(),e.createElementBlock("a",{key:2,href:M.value,target:"_blank",rel:"noopener noreferrer",class:"text-sm text-blue-600 hover:underline"}," View document >>> ",8,Re)):e.createCommentVNode("",!0)]))}}),Ke=["disabled"],Xe={class:"px-4 pb-4 md:px-6 md:pb-6"},We={class:"mb-6 rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm"},Ge={class:"text-blue-900"},He={key:0,class:"mt-3 rounded-md bg-white/80 border border-blue-100 p-3"},qe={class:"list-inside list-disc space-y-0.5 text-xs text-blue-800 columns-2 gap-x-4"},Je={key:1,class:"mt-2 text-xs text-blue-700"},Qe={key:0,class:"flex items-center justify-center py-10"},Ye={key:0,class:"flex overflow-x-auto pb-2 gap-1 -mx-1"},Ze=["onClick"],et={class:"flex items-center justify-between gap-4"},tt={class:"border-b-2 border-primary pb-1 text-base font-semibold text-slate-900"},nt=["disabled","onClick"],at={class:"grid grid-cols-1 gap-4 md:grid-cols-3"},ot=["onUpdate:modelValue","onBlur"],lt=["value"],st={key:0,class:"mt-1.5 flex flex-wrap items-center gap-2 text-xs"},rt={key:0,class:"text-blue-600"},it={key:1,class:"text-green-600"},ct={key:2,class:"flex items-center gap-1"},dt={class:"text-red-600"},ut=["onClick"],mt={key:0,class:"boi-emts-wrapper"},pt={key:0,class:"mt-3 text-sm font-medium text-green-800"},ft={key:1,class:"rounded-lg border border-gray-200 bg-white p-4"},bt={class:"rounded-lg py-3"},gt={class:"flex items-center gap-2"},kt={key:0,class:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"},yt={key:0,class:"mt-1.5 text-sm text-amber-700"},ht={key:1,class:"mt-1.5 text-sm text-red-600"},xt={key:2,class:"rounded-lg border border-red-200 bg-red-50 p-4 flex items-start gap-3"},Bt={class:"flex-1 text-sm text-red-800"},wt={class:"flex justify-center"},Et=e.defineComponent({__name:"BankStatementIntegration",props:{applicationId:{},api:{},bankOptions:{},formData:{},industrialSectorOptions:{},baseUrl:{default:""},integrationBaseUrl:{default:""},isFormDisabled:{type:Boolean,default:!1},maxAccounts:{default:5},verifyBankAccount:{type:[Function,null],default:null},blockAutoSave:{},unblockAutoSave:{},pollEdocStatus:{type:Boolean,default:!0}},emits:["error"],setup(o,{emit:y}){const t=o,m=y;function c(n){const a=(t.integrationBaseUrl??"").replace(/\/$/,"");if(!a)return n;const s=n.startsWith("/")?n:`/${n}`;return`${a}${s}`}const{edocBanks:E,loadBanksForStatement:V}=Z({get:t.api.get,getBanksUrl:()=>c(z.getBanks())}),{handleAccountVerification:d,retryVerification:h,getVerificationState:_}=ee(()=>t.verifyBankAccount),B=e.ref(0),C=e.ref(""),w=e.ref(!1),v=e.ref(null);function A(){var n;(n=t.blockAutoSave)==null||n.call(t)}function M(){setTimeout(()=>{var a;const n=v.value;n&&!n.contains(document.activeElement)&&((a=t.unblockAutoSave)==null||a.call(t))},0)}const g=e.ref([]),k=e.ref(!1);let x=null;const p=e.computed(()=>{var n,a;return((n=t.integrationBaseUrl)==null?void 0:n.replace(/\/$/,""))||((a=t.baseUrl)==null?void 0:a.replace(/\/$/,""))||""}),l=e.computed(()=>t.applicationId?ae.urls(t.applicationId,p.value):null),r=e.computed(()=>t.integrationBaseUrl?c(K.upload()):void 0),f=e.computed(()=>(t.integrationBaseUrl??"").trim().replace(/\/$/,"")),b=e.computed(()=>g.value.slice(0,t.maxAccounts)),D=e.computed(()=>g.value.length<t.maxAccounts),I=e.computed(()=>g.value.length>0),P=e.computed(()=>{var n;return((n=t.formData)==null?void 0:n.email)??""});function O(){var s,u;const n=(s=t.formData)==null?void 0:s.industrial_sector_id;if(n==null)return;const a=(u=t.industrialSectorOptions)==null?void 0:u.find(i=>i.value===n||i.id===n||i.value===String(n));return(a==null?void 0:a.label)??(a==null?void 0:a.name)}function T(n){if(n==null||n==="")return!1;const a=n.trim().toLowerCase();return a.includes("edoc/statements/")&&a.endsWith(".csv")}function N(n){const a=(n??"").trim();return!a||T(a)?"":a}function X(n){var u,i;const a=(u=n.uploaded_statement_path)==null?void 0:u.trim();if(a)return a;const s=((i=n.bank_statement)==null?void 0:i.trim())??"";return s&&!T(s)?s:""}function vt(n,a){n.uploaded_statement_path=a.trim(),R(n)}function ie(n,a){var i;const s=((i=t.bankOptions.find($=>$.value===n.bank))==null?void 0:i.label)??"",u=n.account_number??"";return s&&u?`${s} (${u})`:s||(u?`Account (${u})`:`Account ${a+1}`)}function _t(n){const a={pending:"bg-gray-100 text-gray-800",processing:"bg-amber-100 text-amber-800",completed:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800"};return a[n]??a.pending}async function St(){if(l.value)try{k.value=!0;const n=await t.api.get(l.value.index),a=n==null?void 0:n.data;a!=null&&a.success&&Array.isArray(a.data)&&(g.value=a.data.map(s=>({...s,otp:"",showOtpInput:!1,uploaded_statement_path:N(s.bank_statement)})))}catch(n){console.error("Failed to load bank statements",n)}finally{k.value=!1}}async function Nt(){if(l.value)try{const n=await t.api.get(l.value.index),a=n==null?void 0:n.data;if(!(a!=null&&a.success)||!Array.isArray(a.data))return;const s=["edoc_status","consent_id","csv_url","statement_generated"];g.value=g.value.map(u=>{const i=a.data.find(U=>U.id===u.id);if(!i)return u;const $={};for(const U of s)U in i&&($[U]=i[U]);let F=u.uploaded_statement_path??"";if("bank_statement"in i&&i.bank_statement!==void 0){const U=String(i.bank_statement??"");$.bank_statement=i.bank_statement,U&&!T(U)?F=U:U&&T(U)&&F||U||(F="")}return $.uploaded_statement_path=F,{...u,...$}})}catch(n){console.error("Sync statements failed",n)}}function ce(){j(),x=setInterval(()=>{if(!g.value.some(a=>a.edoc_status==="processing")){j();return}Nt()},5e3)}function j(){x&&(clearInterval(x),x=null)}e.watch(()=>g.value.some(n=>n.edoc_status==="processing"),n=>{if(!t.pollEdocStatus){j();return}n?ce():j()});async function R(n){if(!(!l.value||n.id<0))try{await t.api.put(l.value.update(n.id),{bank:n.bank,account_number:n.account_number,account_name:n.account_name,account_type:n.account_type,bvn:n.bvn,email:n.email,bank_statement:n.bank_statement})}catch(a){console.error("Failed to save bank statement",a)}}async function Ct(){if(!l.value||!D.value)return;const n=-Date.now(),a={id:n,loan_application_id:Number(t.applicationId),bank:"",account_number:"",account_name:"",account_type:"",bvn:"",email:P.value,bank_statement:"",csv_url:"",consent_id:"",edoc_status:"pending",statement_generated:!1,otp:"",showOtpInput:!1,uploaded_statement_path:""};g.value.push(a),B.value=g.value.length-1;try{const s=await t.api.post(l.value.store,{email:P.value}),u=s==null?void 0:s.data;if(u!=null&&u.success&&u.data){const i=g.value.findIndex($=>$.id===n);i!==-1&&(g.value[i]={...u.data,otp:"",showOtpInput:!1,uploaded_statement_path:N(u.data.bank_statement)})}else g.value=g.value.filter(i=>i.id!==n),B.value=Math.max(0,g.value.length-1)}catch(s){g.value=g.value.filter(u=>u.id!==n),B.value=Math.max(0,g.value.length-1),m("error",(s==null?void 0:s.message)??"Failed to add account")}}async function $t(n){if(!l.value)return;const a=g.value.findIndex(i=>i.id===n.id),s={...n},u=n.id<0;if(g.value=g.value.filter(i=>i.id!==n.id),B.value=Math.min(B.value,Math.max(0,g.value.length-1)),!u)try{await t.api.delete(l.value.destroy(n.id))}catch(i){g.value=g.value.slice(0,a).concat(s,g.value.slice(a)),m("error",(i==null?void 0:i.message)??"Failed to remove account")}}function At(n,a){n.consent_id=a,n.showOtpInput=!0,R(n)}function Dt(n,a){Object.assign(n,a),R(n)}function It(n){C.value=n,m("error",n)}function Ut(){C.value=""}function de(n){return a=>{var i;if(!l.value)return;(i=t.blockAutoSave)==null||i.call(t),n.edoc_status="processing";const s=O(),u=()=>{setTimeout(()=>{var $;return($=t.unblockAutoSave)==null?void 0:$.call(t)},3e3)};t.api.post(l.value.uploadToEdoc(n.id),{filePath:a,industrialSector:s}).then($=>{var U;const F=(U=$==null?void 0:$.data)==null?void 0:U.data;if(F){const me=n.uploaded_statement_path??"";Object.assign(n,F),me&&F.bank_statement&&T(String(F.bank_statement))&&(n.uploaded_statement_path=me)}ce()}).catch(()=>{n.edoc_status="failed"}).finally(u)}}const ue=n=>{if(!n||!E.value.length)return!1;const a=t.bankOptions.find(u=>u.value===n),s=[(a==null?void 0:a.label)??"",...(a==null?void 0:a.searchKeywords)??[]].filter(Boolean);return E.value.some(u=>{const i=u.bankCode===n||u.code===n,$=s.some(F=>{var U;return(U=u.name)==null?void 0:U.toLowerCase().includes(F.toLowerCase())});return(i||$)&&u.enabled!==!1})},G=e.computed(()=>(E.value||[]).filter(n=>n.enabled!==!1).map(n=>n.name||n.bankCode||"Unknown").sort((n,a)=>n.localeCompare(a)));return e.onMounted(async()=>{V(),t.applicationId&&await St()}),e.onUnmounted(()=>{j()}),(n,a)=>(e.openBlock(),e.createElementBlock("fieldset",{ref_key:"rootRef",ref:v,disabled:o.isFormDisabled,class:"boi-bank-statement-integration rounded-xl border border-gray-200 bg-white shadow-sm",onFocusin:A,onFocusout:M},[a[13]||(a[13]=e.createElementVNode("div",{class:"border-b border-gray-100 px-4 py-3 md:px-6 md:py-4"},[e.createElementVNode("h2",{class:"text-lg font-bold text-slate-900"},"Company Bank Statements")],-1)),e.createElementVNode("div",Xe,[e.createElementVNode("div",We,[e.createElementVNode("p",Ge,[a[1]||(a[1]=e.createTextVNode(" Some banks support ",-1)),a[2]||(a[2]=e.createElementVNode("strong",null,"Electronic Bank Statement Retrieval",-1)),a[3]||(a[3]=e.createTextVNode(", so you may not need to upload a PDF. ",-1)),e.createElementVNode("button",{type:"button",onClick:a[0]||(a[0]=s=>w.value=!w.value),class:"ml-1 font-semibold text-blue-700 underline hover:text-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-300 rounded"},e.toDisplayString(w.value?"Hide":"See"),1),e.createTextVNode(" "+e.toDisplayString(w.value?"":" supported banks."),1)]),w.value&&G.value.length?(e.openBlock(),e.createElementBlock("div",He,[a[4]||(a[4]=e.createElementVNode("p",{class:"mb-2 text-xs font-semibold text-blue-900"},"Banks that support electronic statement retrieval:",-1)),e.createElementVNode("ul",qe,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(G.value,(s,u)=>(e.openBlock(),e.createElementBlock("li",{key:u},e.toDisplayString(s),1))),128))])])):w.value&&!G.value.length?(e.openBlock(),e.createElementBlock("p",Je," Loading supported banks… ")):e.createCommentVNode("",!0)]),k.value?(e.openBlock(),e.createElementBlock("div",Qe,[...a[5]||(a[5]=[e.createElementVNode("span",{class:"inline-block h-5 w-5 animate-spin rounded-full border-2 border-slate-300 border-t-slate-600 mr-2","aria-hidden":"true"},null,-1),e.createElementVNode("span",{class:"text-sm text-slate-600"},"Loading bank statements…",-1)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[b.value.length?(e.openBlock(),e.createElementBlock("div",Ye,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.value,(s,u)=>(e.openBlock(),e.createElementBlock("button",{key:s.id,type:"button",class:e.normalizeClass(["shrink-0 rounded-lg px-4 py-2 text-sm font-medium whitespace-nowrap transition-colors",B.value===u?"bg-primary text-white shadow-sm":"bg-slate-100 text-slate-700 hover:bg-slate-200"]),onClick:i=>B.value=u},e.toDisplayString(ie(s,u)),11,Ze))),128))])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.value,(s,u)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:s.id,class:"mt-6 space-y-6 rounded-xl border border-gray-100 bg-gray-50/50 p-4 md:p-6"},[e.createElementVNode("div",et,[e.createElementVNode("h4",tt,e.toDisplayString(ie(s,u)),1),e.createElementVNode("button",{type:"button",class:"inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 disabled:opacity-50 transition-colors",disabled:!I.value||o.isFormDisabled,onClick:i=>$t(s)},[...a[6]||(a[6]=[e.createElementVNode("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1),e.createTextVNode(" Remove account ",-1)])],8,nt)]),e.renderSlot(n.$slots,"account-fields",{account:s,bankOptions:o.bankOptions,verificationState:e.unref(_)(s),onVerify:()=>e.unref(d)(s),onRetry:()=>e.unref(h)(s)},()=>[e.createElementVNode("div",at,[e.createElementVNode("div",null,[a[7]||(a[7]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Bank",-1)),e.createVNode(le,{"model-value":s.bank,options:o.bankOptions,placeholder:"Select bank",disabled:!!o.isFormDisabled,"onUpdate:modelValue":i=>{s.bank=i,e.unref(d)(s),R(s)}},null,8,["model-value","options","disabled","onUpdate:modelValue"])]),e.createElementVNode("div",null,[a[8]||(a[8]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Account number",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":i=>s.account_number=i,type:"text",maxlength:"10",inputmode:"numeric",class:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm focus:border-primary focus:ring-1 focus:ring-primary",placeholder:"10 digits",onBlur:i=>{e.unref(d)(s),R(s)}},null,40,ot),[[e.vModelText,s.account_number]])]),e.createElementVNode("div",null,[a[9]||(a[9]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Account name",-1)),e.createElementVNode("input",{value:s.account_name,type:"text",readonly:"",class:"w-full cursor-default rounded-lg border border-gray-200 bg-gray-50 px-3 py-2.5 text-sm text-gray-700",placeholder:"Enter bank and account number to verify"},null,8,lt),o.verifyBankAccount?(e.openBlock(),e.createElementBlock("div",st,[e.unref(_)(s).isLoading?(e.openBlock(),e.createElementBlock("span",rt,"Verifying…")):e.unref(_)(s).isSuccess?(e.openBlock(),e.createElementBlock("span",it,"Account verified")):e.unref(_)(s).isError?(e.openBlock(),e.createElementBlock("span",ct,[e.createElementVNode("span",dt,e.toDisplayString(e.unref(_)(s).errorMessage),1),e.createElementVNode("button",{type:"button",class:"rounded px-2 py-0.5 text-gray-600 hover:bg-gray-100",onClick:i=>e.unref(h)(s)},"Retry",8,ut)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])])]),ue(s.bank)?(e.openBlock(),e.createElementBlock("div",mt,[e.createVNode(Q,{account:s,"edoc-banks":e.unref(E),"bank-options":o.bankOptions,api:{get:o.api.get,post:o.api.post},"company-email":P.value,"industrial-sector":O(),"application-id":o.applicationId,"integration-base-url":o.integrationBaseUrl,disabled:o.isFormDisabled,"onUpdate:consentId":i=>At(s,i),onStatementRetrieved:i=>Dt(s,i),onError:It},null,8,["account","edoc-banks","bank-options","api","company-email","industrial-sector","application-id","integration-base-url","disabled","onUpdate:consentId","onStatementRetrieved"]),s.statement_generated||s.edoc_status==="completed"?(e.openBlock(),e.createElementBlock("p",pt," Succeeded. ")):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),ue(s.bank)?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",ft,[a[11]||(a[11]=e.createElementVNode("p",{class:"mb-3 text-sm font-medium text-gray-700"},"Upload bank statement (PDF)",-1)),e.renderSlot(n.$slots,"file-upload",{account:s,afterUpload:de(s)},()=>[e.createVNode(se,{modelValue:s.bank_statement,"onUpdate:modelValue":i=>s.bank_statement=i,"view-storage-path":X(s),post:(i,$,F)=>o.api.post(i,$,F),"upload-url":r.value,"view-api-base":f.value||void 0,placeholder:"Choose 12 months bank statement (PDF)",accept:".pdf","max-size":20*1024*1024,"allowed-types":["application/pdf"],"upload-context":"bank_statement","after-upload":de(s),disabled:o.isFormDisabled,onUploaded:i=>vt(s,String(i))},null,8,["modelValue","onUpdate:modelValue","view-storage-path","post","upload-url","view-api-base","after-upload","disabled","onUploaded"]),e.createElementVNode("div",bt,[e.createElementVNode("div",gt,[a[10]||(a[10]=e.createElementVNode("span",{class:"text-sm font-medium text-gray-600"},"Bank statement status:",-1)),e.createElementVNode("span",{class:e.normalizeClass([_t(s.edoc_status||"pending"),"inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium capitalize"])},[s.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("span",kt)):e.createCommentVNode("",!0),e.createTextVNode(" "+e.toDisplayString(s.edoc_status||"pending"),1)],2)]),s.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("p",yt," Processing in progress. Please wait… ")):e.createCommentVNode("",!0),s.edoc_status==="failed"?(e.openBlock(),e.createElementBlock("p",ht," Processing failed. Please re-upload a valid bank statement or try another method. ")):e.createCommentVNode("",!0)])])])),C.value?(e.openBlock(),e.createElementBlock("div",xt,[e.createElementVNode("p",Bt,e.toDisplayString(C.value),1),e.createElementVNode("button",{type:"button",class:"shrink-0 rounded p-1 text-red-600 hover:bg-red-100",onClick:Ut,"aria-label":"Dismiss"},"×")])):e.createCommentVNode("",!0)])),[[e.vShow,B.value===u]])),128)),e.createElementVNode("div",wt,[e.createVNode(q,{type:"button",variant:"default",size:"lg",disabled:!D.value||o.isFormDisabled||!o.applicationId,onClick:Ct},{default:e.withCtx(()=>[...a[12]||(a[12]=[e.createElementVNode("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),e.createTextVNode(" Add account ",-1)])]),_:1},8,["disabled"])])],64))])],40,Ke))}});function re(o){}const Vt={install:re};S.BankSelect=le,S.BankStatementIntegration=Et,S.BoiButton=H,S.Button=q,S.EmtsIntegration=Q,S.FileInput=se,S.bankStatementsApi=ae,S.bankStatementsUrls=ne,S.default=Vt,S.edocApi=z,S.filesApi=K,S.install=re,S.useAccountVerification=ee,S.useEdocBanks=Z,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1
|
+
(function(S,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(S=typeof globalThis<"u"?globalThis:S||self,e(S.BoiUi={},S.Vue))})(this,(function(S,e){"use strict";const H=((o,k)=>{const t=o.__vccOpts||o;for(const[b,c]of k)t[b]=c;return t})(e.defineComponent({__name:"BoiButton",props:{label:{},variant:{}},setup(o){return(k,t)=>(e.openBlock(),e.createElementBlock("button",{type:"button",class:e.normalizeClass(["boi-button",[o.variant?`boi-button--${o.variant}`:"boi-button--primary"]])},[e.renderSlot(k.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(o.label),1)],!0)],2))}}),[["__scopeId","data-v-96425342"]]);function W(...o){return o.flat(1/0).filter(Boolean).join(" ")}const fe="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",be={default:"bg-primary text-white shadow-xs hover:bg-primary/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-white shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},ge={default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"};function ke(o={}){const k=o.variant??"default",t=o.size??"default";return[fe,be[k],ge[t]].join(" ")}const ye=["type","disabled"],q=e.defineComponent({__name:"Button",props:{type:{default:"button"},variant:{default:"default"},size:{default:"default"},class:{type:[Boolean,null,String,Object,Array]},disabled:{type:Boolean,default:!1}},setup(o){const k=o;return(t,b)=>(e.openBlock(),e.createElementBlock("button",{type:o.type,disabled:o.disabled,"data-slot":"button",class:e.normalizeClass(e.unref(W)(e.unref(ke)({variant:k.variant,size:k.size}),k.class))},[e.renderSlot(t.$slots,"default")],10,ye))}}),L={getBanks:()=>"/api/edoc/banks",initializeConsent:()=>"/api/edoc/consent/initialize",attachAccount:()=>"/api/edoc/consent/attach-account",getTransactions:()=>"/api/edoc/consent/transactions",manualUpload:()=>"/api/edoc/manual-upload"},he={class:"boi-emts-integration space-y-4"},xe={key:0},Be={class:"boi-emts-instructions rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm"},we={class:"list-inside list-decimal space-y-1 text-amber-800"},Ee=["disabled"],Ve={key:1,class:"boi-emts-otp space-y-3 rounded-lg border-2 border-primary bg-primary/5 p-4"},_e={class:"flex flex-wrap items-end gap-3"},Se={class:"min-w-[140px]"},ve=["disabled"],Ne={key:1,class:"text-sm text-red-600"},Ce={key:2,class:"text-sm text-amber-600"},J="inline-flex items-center justify-center rounded-md bg-black px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-neutral-900 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",Q=e.defineComponent({__name:"EmtsIntegration",props:{account:{},edocBanks:{},bankOptions:{},api:{},companyEmail:{},industrialSector:{},applicationId:{},disabled:{type:Boolean,default:!1},integrationBaseUrl:{default:""}},emits:["update:consentId","statement-retrieved","error"],setup(o,{emit:k}){const t=o;function b(r){const s=(t.integrationBaseUrl??"").replace(/\/$/,"");if(!s)return r;const u=r.startsWith("/")?r:`/${r}`;return`${s}${u}`}const c=k,B=e.ref(!1),E=e.ref(!1);function p(r){const s=t.bankOptions.find(u=>u.value===r);return[(s==null?void 0:s.label)??"",...(s==null?void 0:s.searchKeywords)??[]].filter(Boolean)}function x(r,s=!1){if(!r||!t.edocBanks.length)return;const u=p(r);return t.edocBanks.find(g=>{const I=g.bankCode===r||g.code===r,C=u.some(P=>{var O;return(O=g.name)==null?void 0:O.toLowerCase().includes(P.toLowerCase())});return(I||C)&&(!s||g.enabled!==!1)})}const v=r=>x(r,!1),_=r=>!!x(r,!0),N=e.computed(()=>{var r,s;return!!((s=(r=v(t.account.bank))==null?void 0:r.bankInstructions)!=null&&s.length)}),h=e.computed(()=>{var s;const r=t.account;return!!r.bank&&((s=r.account_number)==null?void 0:s.length)===10&&!B.value&&!E.value}),w=e.computed(()=>!!t.account.otp&&!E.value),V=r=>{var s,u,g;return((u=(s=r==null?void 0:r.response)==null?void 0:s.data)==null?void 0:u.message)??((g=r==null?void 0:r.data)==null?void 0:g.message)??(r==null?void 0:r.message)??"An unexpected error occurred"},z=r=>({email:r,referenceId:`loan_${t.applicationId??"new"}_${t.account.id}`,firstName:"Company",lastName:"Account",state:"Lagos",fundType:"online portal",statementDuration:"12",redirectionUrl:typeof window<"u"?window.location.origin+"/loan-application":"",industrialSector:t.industrialSector??void 0});async function F(r){var C,P;const s=t.account.email||t.companyEmail||"",u=await t.api.post(b(L.initializeConsent()),z(s)),g=u==null?void 0:u.data;if(!(g!=null&&g.success))throw new Error((g==null?void 0:g.message)??"Failed to initialize consent");const I=(P=(C=g==null?void 0:g.data)==null?void 0:C.data)==null?void 0:P.consentId;if(!I)throw new Error("No consent ID returned");return c("update:consentId",I),await t.api.post(b(L.attachAccount()),{consentId:I,bankId:r.bankId,accountNumber:t.account.account_number,accountType:"Business",statementDuration:"12",monthType:"Period",uploadType:"Digital"}),I}async function y(){var s;const r=v(t.account.bank);if(!t.account.bank)return c("error","Please select a bank");if(((s=t.account.account_number)==null?void 0:s.length)!==10)return c("error","Please provide a valid 10-digit account number");if(!r)return c("error","Selected bank does not support electronic statement retrieval");B.value=!0;try{await F(r)}catch(u){c("error",V(u))}finally{B.value=!1}}async function d(){var r;if(!t.account.otp||!t.account.consent_id)return c("error","Please enter OTP");E.value=!0;try{const s=await t.api.post(b(L.getTransactions()),{consentId:t.account.consent_id,verificationCode:t.account.otp,bankStatementId:t.account.id}),u=s==null?void 0:s.data;if(!(u!=null&&u.success))return c("error",(u==null?void 0:u.message)??"Failed to retrieve transactions");(r=u.data)!=null&&r.statement&&c("statement-retrieved",u.data.statement)}catch(s){c("error",V(s))}finally{E.value=!1}}async function f(){var s,u;const r=v(t.account.bank);if(!t.account.bank||((s=t.account.account_number)==null?void 0:s.length)!==10)return c("error","Please select a bank and provide a valid 10-digit account number");if(!r)return c("error","Selected bank does not support electronic statement retrieval");E.value=!0;try{const g=await F(r),I=await t.api.post(b(L.getTransactions()),{consentId:g,verificationCode:"",bankStatementId:t.account.id}),C=I==null?void 0:I.data;if(!(C!=null&&C.success))return c("error",(C==null?void 0:C.message)??"Failed to retrieve transactions");(u=C.data)!=null&&u.statement&&c("statement-retrieved",C.data.statement)}catch(g){c("error",V(g))}finally{E.value=!1}}return(r,s)=>{var u;return e.openBlock(),e.createElementBlock("div",he,[_(o.account.bank)?(e.openBlock(),e.createElementBlock("div",xe,[N.value&&!o.account.statement_generated?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("div",Be,[s[1]||(s[1]=e.createElementVNode("p",{class:"mb-2 font-semibold text-amber-900"},"Bank-specific instructions",-1)),e.createElementVNode("ol",we,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList((u=v(o.account.bank))==null?void 0:u.bankInstructions,(g,I)=>(e.openBlock(),e.createElementBlock("li",{key:I},e.toDisplayString(g),1))),128))])]),e.createVNode(H,{label:E.value?"Retrieving…":"Retrieve statement",variant:"primary",disabled:!h.value||o.disabled,onClick:f},null,8,["label","disabled"])],64)):!N.value&&!o.account.statement_generated?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[o.account.showOtpInput?(e.openBlock(),e.createElementBlock("div",Ve,[s[3]||(s[3]=e.createElementVNode("p",{class:"text-sm font-medium text-gray-700"},"Enter the OTP sent to your bank-registered email.",-1)),e.createElementVNode("div",_e,[e.createElementVNode("div",Se,[s[2]||(s[2]=e.createElementVNode("label",{class:"mb-1 block text-xs font-medium text-gray-600"},"OTP code",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":s[0]||(s[0]=g=>o.account.otp=g),type:"text",maxlength:"6",placeholder:"6-digit OTP",class:"w-full rounded border border-gray-300 px-3 py-2 text-lg tracking-widest"},null,512),[[e.vModelText,o.account.otp]])]),e.createElementVNode("button",{type:"button",class:e.normalizeClass(J),disabled:!w.value||o.disabled,onClick:d}," Verify OTP ",8,ve)])])):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(J),disabled:!h.value||o.disabled,onClick:y},e.toDisplayString(B.value?"Sending OTP…":"Send OTP"),9,Ee))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),o.account.edoc_status==="failed"?(e.openBlock(),e.createElementBlock("div",Ne,"Statement retrieval failed. Please try again or upload manually.")):e.createCommentVNode("",!0),o.account.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("div",Ce,"Processing…")):e.createCommentVNode("",!0)])}}});function $e(o){if(!o||typeof o!="object")return[];const k=o,t=k.success?k.data:k.data??k;return Array.isArray(t)?t:t&&typeof t=="object"&&Array.isArray(t.data)?t.data:[]}function Y(o,k){return o===void 0?k:typeof o=="function"?o():o}function Z(o){const{get:k,getBanksUrl:t,fallbackBanksUrl:b}=o,c=e.ref([]),B=e.ref([]),E=e.ref(!1),p=e.ref(null);let x=null;return{edocBanks:c,banks:B,loading:E,error:p,loadBanksForStatement:async()=>c.value.length>0?c.value:x||(E.value=!0,p.value=null,x=(async()=>{var N,h;try{const w=await k(Y(t,L.getBanks())),V=$e(w==null?void 0:w.data);if(V.length)return c.value=B.value=V,V}catch{}const _=b!=null?Y(b,""):"";if(_)try{const w=await k(_),V=Array.isArray(w==null?void 0:w.data)?w.data:[];return c.value=B.value=V,V}catch(w){throw p.value=((h=(N=w==null?void 0:w.response)==null?void 0:N.data)==null?void 0:h.message)??"Failed to load banks",w}return[]})().finally(()=>{E.value=!1,x=null}),x),invalidateCache:()=>{c.value=B.value=[],x=null,p.value=null}}}const j=e.ref({});function ee(o){const k=()=>typeof o=="function"&&o.length===0?o():o,t=p=>`${p.bank??""}_${p.account_number??""}`,b=p=>{const x=t(p);return j.value[x]??{isLoading:!1,isSuccess:!1,isError:!1}},c=p=>{p.account_name=""},B=async p=>{const x=p.bank,v=p.account_number,_=t(p),N=k();if(!N||!x||!v||v.length!==10){delete j.value[_],(v==null?void 0:v.length)!==10&&c(p);return}c(p),j.value[_]={isLoading:!0,isSuccess:!1,isError:!1};try{const h=await N(v,x),w=(h==null?void 0:h.account_name)??(h==null?void 0:h.accountName)??"";w?(p.account_name=w,j.value[_]={isLoading:!1,isSuccess:!0,isError:!1}):j.value[_]={isLoading:!1,isSuccess:!1,isError:!0,errorMessage:"Account verification failed"}}catch(h){j.value[_]={isLoading:!1,isSuccess:!1,isError:!0,errorMessage:h instanceof Error?h.message:"Verification failed"}}};return{handleAccountVerification:B,retryVerification:p=>B(p),getVerificationState:b,clearAccountName:c}}const te="/api/loan-applications";function ne(o,k=""){const t=k?`${k.replace(/\/$/,"")}${te}`:te,b=String(o);return{index:`${t}/${b}/bank-statements`,store:`${t}/${b}/bank-statements`,update:c=>`${t}/${b}/bank-statements/${c}`,destroy:c=>`${t}/${b}/bank-statements/${c}`,uploadToEdoc:c=>`${t}/${b}/bank-statements/${c}/upload-to-edoc`}}const ae={urls:ne},oe="",X={upload:()=>`${oe}/api/files/upload`,view:o=>`${oe}/api/files/view?path=${encodeURIComponent(o)}`},Ae=["id","disabled"],De={class:"truncate text-left"},Ie={key:0,class:"absolute z-[1000] mt-1 w-full rounded-lg border border-gray-200 bg-white shadow-lg"},Ue={class:"border-b border-gray-100 p-2"},Te={class:"relative"},Fe={class:"max-h-48 overflow-auto py-1"},Pe=["onClick"],Oe={key:0,class:"px-3 py-2 text-center text-sm italic text-gray-500"},le=e.defineComponent({__name:"BankSelect",props:{modelValue:{},options:{},placeholder:{default:"Select bank"},disabled:{type:Boolean,default:!1},id:{}},emits:["update:modelValue"],setup(o,{emit:k}){const t=o,b=k,c=e.ref(!1),B=e.ref(null),E=e.ref(null),p=e.ref(""),x=e.ref(-1);function v(y,d){if(!d)return!0;const f=[y.label,y.shortName,...y.searchKeywords??[]].filter(s=>s!=null&&String(s).trim()!=="").map(s=>String(s).toLowerCase());if(f.some(s=>s.includes(d)))return!0;const r=d.split(/\s+/).filter(Boolean);return r.length>1?r.every(s=>f.some(u=>u.includes(s))):f.some(s=>s.startsWith(d))}const _=e.computed(()=>{var d;if(!((d=t.options)!=null&&d.length))return[];if(!p.value.trim())return t.options;const y=p.value.toLowerCase().trim();return t.options.filter(f=>v(f,y))}),N=e.computed(()=>{var y;return((y=t.options)==null?void 0:y.find(d=>String(d.value)===String(t.modelValue)))??null}),h=e.computed(()=>{var y;return((y=N.value)==null?void 0:y.label)??t.placeholder});function w(){t.disabled||(c.value=!c.value,c.value&&(p.value="",x.value=_.value.length?0:-1,e.nextTick(()=>{var y;return(y=E.value)==null?void 0:y.focus()})))}function V(y){b("update:modelValue",String(y.value)),c.value=!1,p.value=""}function z(y){if(!c.value)return;const d=_.value;switch(y.key){case"ArrowDown":y.preventDefault(),x.value=Math.min(x.value+1,d.length-1);break;case"ArrowUp":y.preventDefault(),x.value=Math.max(x.value-1,0);break;case"Enter":y.preventDefault(),x.value>=0&&d[x.value]&&V(d[x.value]);break;case"Escape":y.preventDefault(),c.value=!1;break}}function F(y){B.value&&!B.value.contains(y.target)&&(c.value=!1)}return e.watch(p,()=>{x.value=_.value.length?0:-1}),e.onMounted(()=>{typeof document<"u"&&document.addEventListener("click",F)}),e.onUnmounted(()=>{typeof document<"u"&&document.removeEventListener("click",F)}),(y,d)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"selectRef",ref:B,class:"relative"},[e.createElementVNode("button",{type:"button",id:o.id,disabled:o.disabled,class:e.normalizeClass(e.unref(W)("flex h-9 w-full min-w-0 items-center justify-between rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm transition-colors outline-none","focus:border-[var(--boi-primary)] focus:ring-1 focus:ring-[var(--boi-primary)]","disabled:cursor-not-allowed disabled:opacity-50",!N.value&&"text-gray-500")),onClick:w},[e.createElementVNode("span",De,e.toDisplayString(h.value),1),(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(["h-4 w-4 shrink-0 text-gray-400",{"rotate-180":c.value}]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[...d[1]||(d[1]=[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"},null,-1)])],2))],10,Ae),c.value?(e.openBlock(),e.createElementBlock("div",Ie,[e.createElementVNode("div",Ue,[e.createElementVNode("div",Te,[d[2]||(d[2]=e.createElementVNode("svg",{class:"absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),e.withDirectives(e.createElementVNode("input",{ref_key:"searchRef",ref:E,"onUpdate:modelValue":d[0]||(d[0]=f=>p.value=f),type:"text",placeholder:"Type to search...",class:"w-full rounded-md border-0 bg-gray-50 py-2 pl-9 pr-3 text-sm focus:bg-white focus:ring-1 focus:ring-[var(--boi-primary)]",onKeydown:z},null,544),[[e.vModelText,p.value]])])]),e.createElementVNode("div",Fe,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.value,(f,r)=>(e.openBlock(),e.createElementBlock("button",{key:f.value,type:"button",class:e.normalizeClass(e.unref(W)("w-full cursor-pointer px-3 py-2.5 text-left text-sm transition-colors text-gray-900",r===x.value?"bg-gray-100":"hover:bg-gray-50",String(f.value)===String(o.modelValue)&&o.modelValue!==""&&o.modelValue!==void 0&&"font-semibold text-[#016837]")),onClick:s=>V(f)},e.toDisplayString(f.label),11,Pe))),128)),_.value.length===0?(e.openBlock(),e.createElementBlock("p",Oe,' No options found for "'+e.toDisplayString(p.value)+'" ',1)):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)],512))}}),ze={class:"boi-file-input w-full space-y-2"},Me=["accept","disabled","id"],Le={class:"truncate text-sm text-gray-600"},je={key:0,class:"text-sm text-red-600"},Re={key:1,class:"text-xs text-gray-500"},Ke=["href"],se=e.defineComponent({__name:"FileInput",props:{modelValue:{default:""},placeholder:{default:"Choose file"},accept:{default:"*/*"},disabled:{type:Boolean,default:!1},id:{},maxSize:{default:10*1024*1024},allowedTypes:{default:()=>["application/pdf","image/jpeg","image/jpg","image/png","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/plain","text/csv"]},uploadToServer:{type:Boolean,default:!0},showRequirements:{type:Boolean,default:!0},uploadContext:{},afterUpload:{},uploadUrl:{},viewApiBase:{},viewStoragePath:{},post:{}},emits:["update:modelValue","validation-error","validation-success","uploaded"],setup(o,{emit:k}){const t=o,b=k,c=e.ref(),B=e.ref(!1),E=e.ref(""),p=e.ref(""),x={"application/pdf":"PDF","image/jpeg":"JPG","image/jpg":"JPG","image/png":"PNG","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","text/plain":"TXT","text/csv":"CSV"},v={pdf:["application/pdf"],jpg:["image/jpeg","image/jpg"],jpeg:["image/jpeg","image/jpg"],png:["image/png"],doc:["application/msword"],docx:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],xls:["application/vnd.ms-excel"],xlsx:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],txt:["text/plain"],csv:["text/csv"]},_=e.computed(()=>[...new Set(t.allowedTypes.map(f=>{var r;return x[f]||((r=f.split("/")[1])==null?void 0:r.toUpperCase())||f}))].join(", ")),N=e.computed(()=>Math.round(t.maxSize/(1024*1024))),h=e.computed(()=>t.disabled||B.value),w=e.computed(()=>String(t.viewApiBase??"").trim().replace(/\/$/,"")),V=e.computed(()=>{const f=String(t.viewStoragePath??"").trim();return f||String(t.modelValue??"").trim()}),z=e.computed(()=>{const f=V.value;if(!f||!t.uploadToServer)return"#";const r=encodeURIComponent(f),s=w.value;return s?`${s}/api/files/view?path=${r}`:X.view(f)});function F(f){var r;if(p.value="",f.size>t.maxSize){const s=`File size must be less than ${N.value}MB`;return p.value=s,b("validation-error",s),!1}if(t.allowedTypes.length){const s=((r=f.name.split(".").pop())==null?void 0:r.toLowerCase())||"";if(!(t.allowedTypes.includes(f.type)||(v[s]||[]).some(g=>t.allowedTypes.includes(g)))){const g=`Only ${_.value} files are allowed`;return p.value=g,b("validation-error",g),!1}}return!0}async function y(f){var u,g,I,C;p.value="";const r=f.target,s=(u=r.files)==null?void 0:u[0];if(!s){E.value="",b("update:modelValue","");return}if(!F(s)){r.value="",E.value="",b("update:modelValue","");return}if(t.uploadToServer&&t.post){B.value=!0;const P=t.uploadUrl??X.upload(),O=new FormData;O.append("file",s),O.append("folder","documents"),t.uploadContext&&O.append("context",t.uploadContext);try{const U=await t.post(P,O,{headers:{"Content-Type":"multipart/form-data"}}),$=U==null?void 0:U.data;if($!=null&&$.success&&($!=null&&$.path))E.value=s.name,$.url&&console.log("[FileInput] S3 URL:",$.url),b("update:modelValue",$.path),b("validation-success","File uploaded successfully"),b("uploaded",$.path),(g=t.afterUpload)==null||g.call(t,$.path);else{const M=($==null?void 0:$.message)??"Upload failed";p.value=M,b("validation-error",M),r.value="",E.value="",b("update:modelValue","")}}catch(U){const $=((C=(I=U==null?void 0:U.response)==null?void 0:I.data)==null?void 0:C.message)??(U==null?void 0:U.message)??"Upload failed";p.value=$,b("validation-error",$),r.value="",E.value="",b("update:modelValue","")}finally{B.value=!1}}else E.value=s.name,b("update:modelValue",s.name),b("uploaded",s.name)}function d(){!h.value&&c.value&&c.value.click()}return e.watch(()=>t.modelValue,f=>{E.value=(typeof f=="string"&&f?f.split("/").pop():"")||""},{immediate:!0}),(f,r)=>(e.openBlock(),e.createElementBlock("div",ze,[e.createElementVNode("input",{ref_key:"fileInput",ref:c,type:"file",accept:o.accept,disabled:h.value,id:o.id,class:"hidden",onChange:y},null,40,Me),e.createElementVNode("div",{class:e.normalizeClass(["flex w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3 py-2 transition-colors",h.value?"cursor-not-allowed opacity-50":"cursor-pointer hover:bg-gray-50",p.value?"border-red-500":""]),onClick:d},[e.createElementVNode("span",Le,e.toDisplayString(B.value?"Uploading...":E.value||o.placeholder),1),r[0]||(r[0]=e.createElementVNode("span",{class:"text-gray-400"},"📎",-1))],2),p.value?(e.openBlock(),e.createElementBlock("p",je,e.toDisplayString(p.value),1)):e.createCommentVNode("",!0),o.showRequirements?(e.openBlock(),e.createElementBlock("p",Re,"Max "+e.toDisplayString(N.value)+" MB. Allowed: "+e.toDisplayString(_.value)+".",1)):e.createCommentVNode("",!0),V.value&&!B.value&&o.uploadToServer?(e.openBlock(),e.createElementBlock("a",{key:2,href:z.value,target:"_blank",rel:"noopener noreferrer",class:"text-sm text-blue-600 hover:underline"}," View document >>> ",8,Ke)):e.createCommentVNode("",!0)]))}}),Xe=["disabled"],We={class:"px-4 pb-4 md:px-6 md:pb-6"},Ge={class:"mb-6 rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm"},He={class:"text-blue-900"},qe={key:0,class:"mt-3 rounded-md bg-white/80 border border-blue-100 p-3"},Je={class:"list-inside list-disc space-y-0.5 text-xs text-blue-800 columns-2 gap-x-4"},Qe={key:1,class:"mt-2 text-xs text-blue-700"},Ye={key:2,class:"mt-2 text-xs text-red-700"},Ze={key:3,class:"mt-2 text-xs text-blue-700"},et={key:0,class:"flex items-center justify-center py-10"},tt={key:0,class:"flex overflow-x-auto pb-2 gap-1 -mx-1"},nt=["onClick"],at={class:"flex items-center justify-between gap-4"},ot={class:"border-b-2 border-primary pb-1 text-base font-semibold text-slate-900"},lt=["disabled","onClick"],st={class:"grid grid-cols-1 gap-4 md:grid-cols-3"},rt=["onUpdate:modelValue","onBlur"],it=["value"],ct={key:0,class:"mt-1.5 flex flex-wrap items-center gap-2 text-xs"},dt={key:0,class:"text-blue-600"},ut={key:1,class:"text-green-600"},mt={key:2,class:"flex items-center gap-1"},pt={class:"text-red-600"},ft=["onClick"],bt={key:0,class:"boi-emts-wrapper"},gt={key:0,class:"mt-3 text-sm font-medium text-green-800"},kt={key:1,class:"rounded-lg border border-gray-200 bg-white p-4"},yt={class:"rounded-lg py-3"},ht={class:"flex items-center gap-2"},xt={key:0,class:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"},Bt={key:0,class:"mt-1.5 text-sm text-amber-700"},wt={key:1,class:"mt-1.5 text-sm text-red-600"},Et={key:2,class:"rounded-lg border border-red-200 bg-red-50 p-4 flex items-start gap-3"},Vt={class:"flex-1 text-sm text-red-800"},_t={class:"flex justify-center"},St=e.defineComponent({__name:"BankStatementIntegration",props:{applicationId:{},api:{},bankOptions:{},formData:{},industrialSectorOptions:{},baseUrl:{default:""},integrationBaseUrl:{default:""},isFormDisabled:{type:Boolean,default:!1},maxAccounts:{default:5},verifyBankAccount:{type:[Function,null],default:null},blockAutoSave:{},unblockAutoSave:{},pollEdocStatus:{type:Boolean,default:!0}},emits:["error"],setup(o,{emit:k}){const t=o,b=k;function c(n){const a=(t.integrationBaseUrl??"").replace(/\/$/,"");if(!a)return n;const l=n.startsWith("/")?n:`/${n}`;return`${a}${l}`}const{edocBanks:B,loadBanksForStatement:E,loading:p,error:x}=Z({get:t.api.get,getBanksUrl:()=>c(L.getBanks())}),{handleAccountVerification:v,retryVerification:_,getVerificationState:N}=ee(()=>t.verifyBankAccount),h=e.ref(0),w=e.ref(""),V=e.ref(!1),z=e.ref(null);function F(){var n;(n=t.blockAutoSave)==null||n.call(t)}function y(){setTimeout(()=>{var a;const n=z.value;n&&!n.contains(document.activeElement)&&((a=t.unblockAutoSave)==null||a.call(t))},0)}const d=e.ref([]),f=e.ref(!1);let r=null;const s=e.computed(()=>{var n,a;return((n=t.integrationBaseUrl)==null?void 0:n.replace(/\/$/,""))||((a=t.baseUrl)==null?void 0:a.replace(/\/$/,""))||""}),u=e.computed(()=>t.applicationId?ae.urls(t.applicationId,s.value):null),g=e.computed(()=>t.integrationBaseUrl?c(X.upload()):void 0),I=e.computed(()=>(t.integrationBaseUrl??"").trim().replace(/\/$/,"")),C=e.computed(()=>d.value.slice(0,t.maxAccounts)),P=e.computed(()=>d.value.length<t.maxAccounts),O=e.computed(()=>d.value.length>0),U=e.computed(()=>{var n;return((n=t.formData)==null?void 0:n.email)??""});function $(){var l,m;const n=(l=t.formData)==null?void 0:l.industrial_sector_id;if(n==null)return;const a=(m=t.industrialSectorOptions)==null?void 0:m.find(i=>i.value===n||i.id===n||i.value===String(n));return(a==null?void 0:a.label)??(a==null?void 0:a.name)}function M(n){if(n==null||n==="")return!1;const a=n.trim().toLowerCase();return a.includes("edoc/statements/")&&a.endsWith(".csv")}function ie(n){const a=(n??"").trim();return!a||M(a)?"":a}function Nt(n){var m,i;const a=(m=n.uploaded_statement_path)==null?void 0:m.trim();if(a)return a;const l=((i=n.bank_statement)==null?void 0:i.trim())??"";return l&&!M(l)?l:""}function Ct(n,a){n.uploaded_statement_path=a.trim(),K(n)}function ce(n,a){var i;const l=((i=t.bankOptions.find(A=>A.value===n.bank))==null?void 0:i.label)??"",m=n.account_number??"";return l&&m?`${l} (${m})`:l||(m?`Account (${m})`:`Account ${a+1}`)}function $t(n){const a={pending:"bg-gray-100 text-gray-800",processing:"bg-amber-100 text-amber-800",completed:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800"};return a[n]??a.pending}async function At(){if(u.value)try{f.value=!0;const n=await t.api.get(u.value.index),a=n==null?void 0:n.data;a!=null&&a.success&&Array.isArray(a.data)&&(d.value=a.data.map(l=>({...l,otp:"",showOtpInput:!1,uploaded_statement_path:ie(l.bank_statement)})))}catch(n){console.error("Failed to load bank statements",n)}finally{f.value=!1}}async function Dt(){if(u.value)try{const n=await t.api.get(u.value.index),a=n==null?void 0:n.data;if(!(a!=null&&a.success)||!Array.isArray(a.data))return;const l=["edoc_status","consent_id","csv_url","statement_generated"];d.value=d.value.map(m=>{const i=a.data.find(D=>D.id===m.id);if(!i)return m;const A={};for(const D of l)D in i&&(A[D]=i[D]);let T=m.uploaded_statement_path??"";if("bank_statement"in i&&i.bank_statement!==void 0){const D=String(i.bank_statement??"");A.bank_statement=i.bank_statement,D&&!M(D)?T=D:D&&M(D)&&T||D||(T="")}return A.uploaded_statement_path=T,{...m,...A}})}catch(n){console.error("Sync statements failed",n)}}function de(){R(),r=setInterval(()=>{if(!d.value.some(a=>a.edoc_status==="processing")){R();return}Dt()},5e3)}function R(){r&&(clearInterval(r),r=null)}e.watch(()=>d.value.some(n=>n.edoc_status==="processing"),n=>{if(!t.pollEdocStatus){R();return}n?de():R()});async function K(n){if(!(!u.value||n.id<0))try{await t.api.put(u.value.update(n.id),{bank:n.bank,account_number:n.account_number,account_name:n.account_name,account_type:n.account_type,bvn:n.bvn,email:n.email,bank_statement:n.bank_statement})}catch(a){console.error("Failed to save bank statement",a)}}async function It(){if(!u.value||!P.value)return;const n=-Date.now(),a={id:n,loan_application_id:Number(t.applicationId),bank:"",account_number:"",account_name:"",account_type:"",bvn:"",email:U.value,bank_statement:"",csv_url:"",consent_id:"",edoc_status:"pending",statement_generated:!1,otp:"",showOtpInput:!1,uploaded_statement_path:""};d.value.push(a),h.value=d.value.length-1;try{const l=await t.api.post(u.value.store,{email:U.value}),m=l==null?void 0:l.data;if(m!=null&&m.success&&m.data){const i=d.value.findIndex(A=>A.id===n);i!==-1&&(d.value[i]={...m.data,otp:"",showOtpInput:!1,uploaded_statement_path:ie(m.data.bank_statement)})}else d.value=d.value.filter(i=>i.id!==n),h.value=Math.max(0,d.value.length-1)}catch(l){d.value=d.value.filter(m=>m.id!==n),h.value=Math.max(0,d.value.length-1),b("error",(l==null?void 0:l.message)??"Failed to add account")}}async function Ut(n){if(!u.value)return;const a=d.value.findIndex(i=>i.id===n.id),l={...n},m=n.id<0;if(d.value=d.value.filter(i=>i.id!==n.id),h.value=Math.min(h.value,Math.max(0,d.value.length-1)),!m)try{await t.api.delete(u.value.destroy(n.id))}catch(i){d.value=d.value.slice(0,a).concat(l,d.value.slice(a)),b("error",(i==null?void 0:i.message)??"Failed to remove account")}}function Tt(n,a){n.consent_id=a,n.showOtpInput=!0,K(n)}function Ft(n,a){Object.assign(n,a),K(n)}function Pt(n){w.value=n,b("error",n)}function Ot(){w.value=""}function ue(n){return a=>{var i;if(!u.value)return;(i=t.blockAutoSave)==null||i.call(t),n.edoc_status="processing";const l=$(),m=()=>{setTimeout(()=>{var A;return(A=t.unblockAutoSave)==null?void 0:A.call(t)},3e3)};t.api.post(u.value.uploadToEdoc(n.id),{filePath:a,industrialSector:l}).then(A=>{var D;const T=(D=A==null?void 0:A.data)==null?void 0:D.data;if(T){const pe=n.uploaded_statement_path??"";Object.assign(n,T),pe&&T.bank_statement&&M(String(T.bank_statement))&&(n.uploaded_statement_path=pe)}de()}).catch(()=>{n.edoc_status="failed"}).finally(m)}}const me=n=>{if(!n||!B.value.length)return!1;const a=t.bankOptions.find(m=>m.value===n),l=[(a==null?void 0:a.label)??"",...(a==null?void 0:a.searchKeywords)??[]].filter(Boolean);return B.value.some(m=>{const i=m.bankCode===n||m.code===n,A=l.some(T=>{var D;return(D=m.name)==null?void 0:D.toLowerCase().includes(T.toLowerCase())});return(i||A)&&m.enabled!==!1})},G=e.computed(()=>(B.value||[]).filter(n=>n.enabled!==!1).map(n=>n.name||n.bankCode||"Unknown").sort((n,a)=>n.localeCompare(a)));return e.onMounted(async()=>{E(),t.applicationId&&await At()}),e.onUnmounted(()=>{R()}),(n,a)=>(e.openBlock(),e.createElementBlock("fieldset",{ref_key:"rootRef",ref:z,disabled:o.isFormDisabled,class:"boi-bank-statement-integration rounded-xl border border-gray-200 bg-white shadow-sm",onFocusin:F,onFocusout:y},[a[14]||(a[14]=e.createElementVNode("div",{class:"border-b border-gray-100 px-4 py-3 md:px-6 md:py-4"},[e.createElementVNode("h2",{class:"text-lg font-bold text-slate-900"},"Company Bank Statements")],-1)),e.createElementVNode("div",We,[e.createElementVNode("div",Ge,[e.createElementVNode("p",He,[a[1]||(a[1]=e.createTextVNode(" Some banks support ",-1)),a[2]||(a[2]=e.createElementVNode("strong",null,"Electronic Bank Statement Retrieval",-1)),a[3]||(a[3]=e.createTextVNode(", so you may not need to upload a PDF. ",-1)),e.createElementVNode("button",{type:"button",onClick:a[0]||(a[0]=l=>V.value=!V.value),class:"ml-1 font-semibold text-blue-700 underline hover:text-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-300 rounded"},e.toDisplayString(V.value?"Hide":"See"),1),e.createTextVNode(" "+e.toDisplayString(V.value?"":" supported banks."),1)]),V.value&&G.value.length?(e.openBlock(),e.createElementBlock("div",qe,[a[4]||(a[4]=e.createElementVNode("p",{class:"mb-2 text-xs font-semibold text-blue-900"},"Banks that support electronic statement retrieval:",-1)),e.createElementVNode("ul",Je,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(G.value,(l,m)=>(e.openBlock(),e.createElementBlock("li",{key:m},e.toDisplayString(l),1))),128))])])):V.value&&e.unref(p)?(e.openBlock(),e.createElementBlock("p",Qe," Loading supported banks… ")):V.value&&e.unref(x)?(e.openBlock(),e.createElementBlock("p",Ye,[...a[5]||(a[5]=[e.createTextVNode(" Could not load the EDOC bank list. Check boi-api / ",-1),e.createElementVNode("code",{class:"rounded bg-red-50 px-0.5"},"/api/boi-api",-1),e.createTextVNode(" proxy and network errors. ",-1)])])):V.value&&!G.value.length?(e.openBlock(),e.createElementBlock("p",Ze," No banks are returned for electronic retrieval (EDOC list is empty on the API). ")):e.createCommentVNode("",!0)]),f.value?(e.openBlock(),e.createElementBlock("div",et,[...a[6]||(a[6]=[e.createElementVNode("span",{class:"inline-block h-5 w-5 animate-spin rounded-full border-2 border-slate-300 border-t-slate-600 mr-2","aria-hidden":"true"},null,-1),e.createElementVNode("span",{class:"text-sm text-slate-600"},"Loading bank statements…",-1)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[C.value.length?(e.openBlock(),e.createElementBlock("div",tt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,(l,m)=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:e.normalizeClass(["shrink-0 rounded-lg px-4 py-2 text-sm font-medium whitespace-nowrap transition-colors",h.value===m?"bg-primary text-white shadow-sm":"bg-slate-100 text-slate-700 hover:bg-slate-200"]),onClick:i=>h.value=m},e.toDisplayString(ce(l,m)),11,nt))),128))])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,(l,m)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:l.id,class:"mt-6 space-y-6 rounded-xl border border-gray-100 bg-gray-50/50 p-4 md:p-6"},[e.createElementVNode("div",at,[e.createElementVNode("h4",ot,e.toDisplayString(ce(l,m)),1),e.createElementVNode("button",{type:"button",class:"inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 disabled:opacity-50 transition-colors",disabled:!O.value||o.isFormDisabled,onClick:i=>Ut(l)},[...a[7]||(a[7]=[e.createElementVNode("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1),e.createTextVNode(" Remove account ",-1)])],8,lt)]),e.renderSlot(n.$slots,"account-fields",{account:l,bankOptions:o.bankOptions,verificationState:e.unref(N)(l),onVerify:()=>e.unref(v)(l),onRetry:()=>e.unref(_)(l)},()=>[e.createElementVNode("div",st,[e.createElementVNode("div",null,[a[8]||(a[8]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Bank",-1)),e.createVNode(le,{"model-value":l.bank,options:o.bankOptions,placeholder:"Select bank",disabled:!!o.isFormDisabled,"onUpdate:modelValue":i=>{l.bank=i,e.unref(v)(l),K(l)}},null,8,["model-value","options","disabled","onUpdate:modelValue"])]),e.createElementVNode("div",null,[a[9]||(a[9]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Account number",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":i=>l.account_number=i,type:"text",maxlength:"10",inputmode:"numeric",class:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm focus:border-primary focus:ring-1 focus:ring-primary",placeholder:"10 digits",onBlur:i=>{e.unref(v)(l),K(l)}},null,40,rt),[[e.vModelText,l.account_number]])]),e.createElementVNode("div",null,[a[10]||(a[10]=e.createElementVNode("label",{class:"mb-1.5 block text-sm font-medium text-gray-700"},"Account name",-1)),e.createElementVNode("input",{value:l.account_name,type:"text",readonly:"",class:"w-full cursor-default rounded-lg border border-gray-200 bg-gray-50 px-3 py-2.5 text-sm text-gray-700",placeholder:"Enter bank and account number to verify"},null,8,it),o.verifyBankAccount?(e.openBlock(),e.createElementBlock("div",ct,[e.unref(N)(l).isLoading?(e.openBlock(),e.createElementBlock("span",dt,"Verifying…")):e.unref(N)(l).isSuccess?(e.openBlock(),e.createElementBlock("span",ut,"Account verified")):e.unref(N)(l).isError?(e.openBlock(),e.createElementBlock("span",mt,[e.createElementVNode("span",pt,e.toDisplayString(e.unref(N)(l).errorMessage),1),e.createElementVNode("button",{type:"button",class:"rounded px-2 py-0.5 text-gray-600 hover:bg-gray-100",onClick:i=>e.unref(_)(l)},"Retry",8,ft)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])])]),me(l.bank)?(e.openBlock(),e.createElementBlock("div",bt,[e.createVNode(Q,{account:l,"edoc-banks":e.unref(B),"bank-options":o.bankOptions,api:{get:o.api.get,post:o.api.post},"company-email":U.value,"industrial-sector":$(),"application-id":o.applicationId,"integration-base-url":o.integrationBaseUrl,disabled:o.isFormDisabled,"onUpdate:consentId":i=>Tt(l,i),onStatementRetrieved:i=>Ft(l,i),onError:Pt},null,8,["account","edoc-banks","bank-options","api","company-email","industrial-sector","application-id","integration-base-url","disabled","onUpdate:consentId","onStatementRetrieved"]),l.statement_generated||l.edoc_status==="completed"?(e.openBlock(),e.createElementBlock("p",gt," Succeeded. ")):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),me(l.bank)?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",kt,[a[12]||(a[12]=e.createElementVNode("p",{class:"mb-3 text-sm font-medium text-gray-700"},"Upload bank statement (PDF)",-1)),e.renderSlot(n.$slots,"file-upload",{account:l,afterUpload:ue(l)},()=>[e.createVNode(se,{modelValue:l.bank_statement,"onUpdate:modelValue":i=>l.bank_statement=i,"view-storage-path":Nt(l),post:(i,A,T)=>o.api.post(i,A,T),"upload-url":g.value,"view-api-base":I.value||void 0,placeholder:"Choose 12 months bank statement (PDF)",accept:".pdf","max-size":20*1024*1024,"allowed-types":["application/pdf"],"upload-context":"bank_statement","after-upload":ue(l),disabled:o.isFormDisabled,onUploaded:i=>Ct(l,String(i))},null,8,["modelValue","onUpdate:modelValue","view-storage-path","post","upload-url","view-api-base","after-upload","disabled","onUploaded"]),e.createElementVNode("div",yt,[e.createElementVNode("div",ht,[a[11]||(a[11]=e.createElementVNode("span",{class:"text-sm font-medium text-gray-600"},"Bank statement status:",-1)),e.createElementVNode("span",{class:e.normalizeClass([$t(l.edoc_status||"pending"),"inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium capitalize"])},[l.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("span",xt)):e.createCommentVNode("",!0),e.createTextVNode(" "+e.toDisplayString(l.edoc_status||"pending"),1)],2)]),l.edoc_status==="processing"?(e.openBlock(),e.createElementBlock("p",Bt," Processing in progress. Please wait… ")):e.createCommentVNode("",!0),l.edoc_status==="failed"?(e.openBlock(),e.createElementBlock("p",wt," Processing failed. Please re-upload a valid bank statement or try another method. ")):e.createCommentVNode("",!0)])])])),w.value?(e.openBlock(),e.createElementBlock("div",Et,[e.createElementVNode("p",Vt,e.toDisplayString(w.value),1),e.createElementVNode("button",{type:"button",class:"shrink-0 rounded p-1 text-red-600 hover:bg-red-100",onClick:Ot,"aria-label":"Dismiss"},"×")])):e.createCommentVNode("",!0)])),[[e.vShow,h.value===m]])),128)),e.createElementVNode("div",_t,[e.createVNode(q,{type:"button",variant:"default",size:"lg",disabled:!P.value||o.isFormDisabled||!o.applicationId,onClick:It},{default:e.withCtx(()=>[...a[13]||(a[13]=[e.createElementVNode("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),e.createTextVNode(" Add account ",-1)])]),_:1},8,["disabled"])])],64))])],40,Xe))}});function re(o){}const vt={install:re};S.BankSelect=le,S.BankStatementIntegration=St,S.BoiButton=H,S.Button=q,S.EmtsIntegration=Q,S.FileInput=se,S.bankStatementsApi=ae,S.bankStatementsUrls=ne,S.default=vt,S.edocApi=L,S.filesApi=X,S.install=re,S.useAccountVerification=ee,S.useEdocBanks=Z,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
2
2
|
//# sourceMappingURL=boi-ui.umd.cjs.map
|