import{bS as u,bT as m,ar as p,al as L,j as A,b as o,S as I,q as S,o as d,a7 as l,cf as D,B as j,g as y,D as z}from"./index-ktJf6c6X.js";import{d as T}from"./OpenInNew-DQmbuv5q.js";import{d as $}from"./fileDownload-B8aBwWD0.js";var h={},O=u;Object.defineProperty(h,"__esModule",{value:!0});var P=h.default=void 0,B=O(m()),C=p;P=h.default=(0,B.default)((0,C.jsx)("path",{d:"M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 14H8V4h12zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4zm12 6V9c0-.55-.45-1-1-1h-2v5h2c.55 0 1-.45 1-1m-2-3h1v3h-1zm4 2h1v-1h-1V9h1V8h-2v5h1zm-8 0h1c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1H9v5h1zm0-2h1v1h-1z"}),"PictureAsPdfOutlined");var f={},b=u;Object.defineProperty(f,"__esModule",{value:!0});var F=f.default=void 0,G=b(m()),q=p;F=f.default=(0,G.default)((0,q.jsx)("path",{d:"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8zM6 20V4h7v5h5v11z"}),"InsertDriveFileOutlined");const H=L.injectEndpoints({endpoints:e=>({saveLeadAttachment:e.mutation({query:({file:t,leadId:a,followUpId:n,category:i})=>{const r=new FormData;return r.append("file",t),a!=null&&r.append("leadId",String(a)),n!=null&&r.append("followUpId",String(n)),i&&r.append("category",i),{url:"lead/attachment",method:"POST",body:r}}}),getAttachmentsByLeadId:e.query({query:t=>`lead/attachment/by-lead/${t}`}),deleteLeadAttachment:e.mutation({query:t=>({url:`lead/attachment/${t}`,method:"DELETE"}),invalidatesTags:["LeadAttachment"]}),getAttachmentsByFollowUpId:e.query({query:t=>`lead/attachment/by-follow-up/${t}`,providesTags:["LeadAttachment"]}),downloadAttachment:e.query({query:t=>({url:`lead/attachment/${t}/download`,responseHandler:a=>a.blob()})}),saveLeadAttachmentS3:e.mutation({query:t=>({url:"lead/attachment/save-s3",method:"POST",body:t}),invalidatesTags:["LeadAttachment"]})}),overrideExisting:!1}),{useSaveLeadAttachmentMutation:ee,useGetAttachmentsByLeadIdQuery:te,useDeleteLeadAttachmentMutation:ae,useGetAttachmentsByFollowUpIdQuery:ne,useLazyDownloadAttachmentQuery:oe,useSaveLeadAttachmentS3Mutation:re}=H,c=["jpg","jpeg","png","webp"],_=["image/jpeg","image/jpg","image/png","image/webp"],W=["pdf"],N=["application/pdf"],v=5,V=v*1024*1024,ie=".jpg,.jpeg,.png,.webp,.pdf,image/jpeg,image/png,image/webp,application/pdf",se=".jpg,.jpeg,.png,.webp,image/jpeg,image/png,image/webp",de=`Allowed: JPG, JPEG, PNG, WEBP, PDF · Max ${v} MB per file`,le=`Allowed: JPG, JPEG, PNG, WEBP · Max ${v} MB`;function s(e){if(!e)return"";const t=e.split(/[?#]/)[0],a=t.lastIndexOf(".");return a>-1?t.slice(a+1).toLowerCase():""}function J(e){return!e||e<=0?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(2)} MB`}function ce(e,t){if((e??"").toLowerCase().startsWith("image/"))return!0;const n=s(t)||s(e);return c.includes(n)||n==="gif"||n==="svg"}function ue(e,t){return(e??"").toLowerCase().includes("pdf")?!0:s(t)==="pdf"||s(e)==="pdf"}function R(e){return e?"JPG, JPEG, PNG, WEBP or PDF":"JPG, JPEG, PNG or WEBP"}function k(e,t={}){const{allowPdf:a=!0,maxSizeBytes:n=V}=t,i=a?[...c,...W]:[...c],r=a?[..._,...N]:[..._],w=s(e.name),E=(e.type||"").toLowerCase();if(!i.includes(w)||E!==""&&!r.includes(E))return`"${e.name}" is not a supported file type. Allowed formats: ${R(a)}.`;if(e.size===0)return`"${e.name}" is empty and cannot be uploaded.`;if(e.size>n){const x=Math.round(n/1048576);return`"${e.name}" is ${J(e.size)}. Maximum allowed size is ${x} MB.`}return null}function me(e,t={}){const a=[],n=[];return Array.from(e).forEach(i=>{const r=k(i,t);r?n.push(r):a.push(i)}),{validFiles:a,errors:n}}var g={},Y=u;Object.defineProperty(g,"__esModule",{value:!0});var M=g.default=void 0,U=Y(m()),X=p;M=g.default=(0,U.default)((0,X.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7zm-8 2V5h2v6h1.17L12 13.17 9.83 11zm-6 7h14v2H5z"}),"DownloadOutlined");function pe({open:e,url:t,fileName:a,onClose:n}){return t?A(z,{open:e,onClose:n,maxWidth:"md",fullWidth:!0,children:[A(I,{direction:"row",alignItems:"center",gap:1,sx:{px:2,py:1,borderBottom:"1px solid",borderColor:"divider"},children:[o(P,{color:"error",fontSize:"small"}),o(S,{variant:"subtitle2",fontWeight:700,noWrap:!0,sx:{flex:1,minWidth:0},children:a||"Document.pdf"}),o(l,{title:"Download",children:o(d,{size:"small",onClick:()=>$(t,a||"document.pdf"),children:o(M,{fontSize:"small"})})}),o(l,{title:"Open in new tab",children:o(d,{size:"small",onClick:()=>window.open(t,"_blank","noopener,noreferrer"),children:o(T,{fontSize:"small"})})}),o(l,{title:"Close",children:o(d,{size:"small",onClick:n,children:o(D,{fontSize:"small"})})})]}),o(y,{sx:{p:0,bgcolor:"action.hover"},children:o(j,{component:"iframe",src:t,title:a||"PDF preview",sx:{width:"100%",height:{xs:"70vh",md:"78vh"},border:0,display:"block"}})})]}):null}export{ie as A,se as I,pe as P,de as a,k as b,F as c,P as d,ue as e,J as f,M as g,ae as h,ce as i,le as j,re as u,me as v};
