import{r as c,b as u,N as C,B as d,j as m,a7 as b,F as A,E as g}from"./index-ktJf6c6X.js";import{C as f}from"./CreateProductMaster-8zBMEBDs.js";import{d as E}from"./ImageOutlined-BQxAPsuF.js";import{c as v,e as I,b as x,A as N}from"./ArtDesignApi-B1-lHZIT.js";function _(e){const[t,r]=c.useState(!1),[a,l]=c.useState(null),s=c.useCallback(o=>{l(o??null),r(!0)},[]),i=c.useCallback(()=>{r(!1),l(null)},[]),n=c.useCallback(async o=>{await e(o,a)},[e,a]),p=c.useCallback(()=>u(f,{close:i,editProductDetails:null,onCreated:n}),[i,n]);return{isCreating:t,context:a,openCreate:s,close:i,renderCreateProduct:p}}const T=e=>(e||[]).map(t=>({src:t.previewUrl||t.publicUrl||"",fileName:t.fileName,status:t.status,publicUrl:t.publicUrl,previewUrl:t.previewUrl})).filter(t=>!!t.src),L=e=>(e||[]).map(t=>({src:t.previewUrl||t.publicUrl||t.filePath||"",fileName:t.fileName,status:t.status,publicUrl:t.publicUrl??t.filePath,previewUrl:t.previewUrl??t.filePath})).filter(t=>!!t.src),D=e=>({productId:e.productId,productName:e.productName||"",productCode:e.productCode,hsnCode:e.hsnCode,variantDisplay:e.variantDisplay,skuId:e.skuId,selectedVariant:e.selectedVariant,quantity:e.quantity,unit:e.unit,images:T(e.images)}),O=e=>({id:e.id,artNumber:e.artNumber,status:e.status,roundNo:e.roundNo,leadId:e.leadId,leadNumber:e.leadNumber,leadName:e.leadName,customerId:e.customerId,customerName:e.customerName,customerCompany:e.customerCompany,customerMobile:e.customerMobile,customerEmail:e.customerEmail,customerGstNumber:e.customerGstNumber,addresses:e.addresses||[],stage:e.stage,costEstimationId:e.costEstimationId,quotationId:e.quotationId,orderId:e.orderId,remarks:e.remarks,products:(e.products||[]).map(D)}),y={APPROVED:"Approved",COST_ESTIMATION_CREATED:"Cost Estimation Created",QUOTATION_CREATED:"Quotation Created",ORDER_CREATED:"Order Created",COMPLETED:"Completed"},P=e=>e&&y[e]||"Approved",S={APPROVED:"success",COST_ESTIMATION_CREATED:"info",QUOTATION_CREATED:"warning",ORDER_CREATED:"primary",COMPLETED:"success"};function M({stage:e,size:t="small"}){const r=e||"APPROVED";return u(g,{label:P(r),color:S[r],size:t,variant:"outlined",sx:{height:20,fontSize:11,fontWeight:600}})}function V(e={}){const{customerId:t,onlyUnused:r,stage:a,size:l=20,skip:s=!1}=e,[i,n]=c.useState(""),p=C(i.trim(),400),{data:o,isFetching:h}=v({search:p||void 0,customerId:t,onlyUnused:r,stage:a,page:0,size:l},{refetchOnMountOrArgChange:!0,skip:s});return{options:(o==null?void 0:o.data)||[],totalElements:(o==null?void 0:o.totalElements)??0,loading:h,inputValue:i,setInputValue:n}}function Q(){const[e,{isFetching:t}]=I();return{loadDetails:c.useCallback(async a=>{if(a==null)return null;try{const l=await e(a).unwrap();return O(l)}catch{return null}},[e]),loading:t}}function j({images:e,caption:t,size:r=40}){const{lightboxProps:a,openAt:l}=x(),s=e||[];if(s.length===0)return u(d,{sx:{width:r,height:r,borderRadius:1,border:"1px dashed",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"center",color:"text.disabled"},children:u(E,{fontSize:"small"})});const i=s.map(n=>({src:n.src,fileName:n.fileName,status:n.status,caption:t}));return m(A,{children:[u(b,{title:s.length>1?`${s.length} images — click to view`:"Click to view",children:m(d,{onClick:()=>l(i,0),sx:{position:"relative",width:r,height:r,cursor:"pointer",flexShrink:0},children:[u(d,{component:"img",src:s[0].src,alt:t||"product artwork",sx:{width:r,height:r,objectFit:"cover",borderRadius:1,border:"1px solid",borderColor:"divider",display:"block",maxWidth:"100%"}}),s.length>1&&u(d,{sx:{position:"absolute",bottom:-4,right:-4,minWidth:16,height:16,px:.5,borderRadius:"8px",bgcolor:"primary.main",color:"primary.contrastText",fontSize:10,lineHeight:"16px",textAlign:"center",fontWeight:600},children:s.length})]})}),u(N,{...a})]})}export{M as A,j as P,_ as a,T as b,Q as c,L as m,V as u};
