1import{aJ as e,aa as a,be as s,E as t,F as i,al as r,ao as l,u as o,at as n,y as d,r as c,h as m,A as u,j as p,G as h,n as x,H as g,c as j,a8 as y,B as f,aU as b,N as S}from"./index.js";import{A as k}from"./Alert.js";import{B as v}from"./Box.js";import{B as A}from"./Breadcrumb.js";import{D as L}from"./DownloadAndMailButtons.js";import{S as N}from"./SendEmailModal.js";import{D as w}from"./DataLoader.js";import{P as z}from"./Page.js";import{M as D}from"./Multiselect.js";import{S as B}from"./Select.js";import{S as M}from"./SortableTable.js";import{u as P}from"./useDebounce.js";import{b as E,g as F}from"./workingDealers2.js";import{s as I}from"./Analysis.module.js";import"./index28.js";import"./init.js";import"./sum.js";const _=e({Status:"L"}),K=(e,a,s=!1)=>{const{Status:r="L",dealerIds:o=[],downloadLimit:n}=e;return t({queryKey:["dealers/paged-limits-and-risks",r,o,n],queryFn:async({queryKey:[e]})=>new Promise(((s,t)=>i.post("".concat(e),{pageIndex:1,pageSize:2147483647,Status:r,dealerIds:"all"===o?[]:"string"==typeof o?[o]:o},{responseType:"blob",headers:{"Content-Type":"application/json",Accept:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",...a?{"X-Mail-To":a}:{}}}).then((e=>{a||l("Bayi Limit & Risk İzleme",e.data,"xlsx"),s(e)})).catch((e=>t(e))))),enabled:s})},C=()=>{var e;const{t:t}=o(),l=n(b),C=(null==(e=null==l?void 0:l.emails)?void 0:e.map((e=>({name:e.email,value:e.email,label:e.email}))))||[],T=d(S),[q,G]=c.useState(),[R,V]=a(_),J=P(R.dealerSearchKey,100),{refetch:H,error:O}=K(R,void 0,!1),{setModal:U}=m(),{data:W,isLoading:X,isFetchingNextPage:Q,fetchNextPage:Y,isFetching:Z,isError:$,error:ee}=(()=>{const[{Status:e="L",dealerIds:t=[]},l]=a(_);return s({queryKey:["dealers/paged-limits-and-risks",e,t],queryFn:async({queryKey:[a],pageParam:s=1})=>new Promise(((o,n)=>{i.post("/".concat(a),{pageSize:20,pageIndex:s,Status:e,dealerIds:"all"===t?void 0:"string"==typeof t?[t]:t}).then((e=>{const a=Number(r("x-bone-count",e.headers));l((e=>({...e,downloadLimit:20*s}))),20*s>=a&&o({nextCursor:void 0,page:{data:e.data,hasMore:!1}}),o({nextCursor:s+1,page:{data:e.data,hasMore:20*s<a}})})).catch((e=>{n(e)}))})),cacheTime:0,keepPreviousData:!0,getNextPageParam:e=>e.nextCursor})})(),{data:ae,isLoading:se,isError:te}=E({searchKeyword:J});c.useState("");const ie=u(["error","response","data","errorMessage"],ee)||t("text.error_occured");c.useEffect((()=>{if(O){const e=u(["error","response","data"],O)||t("text.error_occured");(async()=>{const a=await(null==e?void 0:e.text());try{const e=JSON.parse(a||"").errorMessage;U({content:e})}catch(s){U({content:t("text.error_occured")})}})()}}),[O]);const{data:re,isLoading:le}=F("Bayi_LimitRisk_Izleme"),oe=(null==ae?void 0:ae.map((e=>({label:e.name,value:e.id}))))||[],ne=Z&&!Q,de=null==re?void 0:re.find((e=>"RaporTipi"===e.name)),ce=null==de?void 0:de.options.map((e=>({label:e.value,value:e.key})));c.useEffect((()=>{X&&se||T(Z)}),[X,Z]);c.useEffect((()=>{W&&G((()=>W.pages.map((({page:e})=>e.data)).flat().map((e=>{const a=R.Status,s={bayi:e.dealer.name,bayiNo:e.dealer.number},t={limitGecerlilikTarihi:e.limitValidityDate,toplamLimit:e.totalLimitAmount,risk:e.risk,taahhutluFatura:e.committedInvoiceAmount,limitBoslugu:e.limitGapAmount};switch(a){case"B":return s;case"S":return{...s,...t,limitBoslugu:e.availableLimit};default:return{...s,...t}}}))))}),[X,W,Q]),c.useEffect((()=>()=>{V({})}),[]);const me=()=>{H()},ue=()=>{U({noIcon:!0,content:p.jsx(N,{items:C||[],filters:R,queryFunc:K})})};return p.jsx(z,{children:p.jsx(h,{children:p.jsx(x,{isLoading:X||le,size:12,children:p.jsx(v,{children:p.jsx(h,{children:p.jsxs(x,{size:12,children:[p.jsxs(h,{className:I.contentSpace,children:[p.jsxs(x,{size:12,xl:8,lg:8,md:6,children:[p.jsx(g,{level:1,children:t("title.dealers_risk")}),p.jsx(A,{})]}),p.jsx(x,{size:4,lg:4,md:6,className:j("d-flex justify-content-end",I.downloadAndMail),children:p.jsx(L,{onDownloadClick:me,onSendEmail:ue,isDisabled:$||y(q)})})]}),p.jsx(h,{className:I.contentSpace,children:p.jsx(x,{size:12,children:p.jsx("p",{className:I.contentDetail,children:t("text.dealers_risk")})})}),p.jsxs(h,{className:I.formContainer,children:[p.jsx(x,{size:12,className:"mb-3",children:p.jsx(D,{name:"dealer",label:"label.select_dealer",items:oe,onClose:e=>{V((a=>({...a,dealerIds:Array.isArray(e)?e.map(String):e})))},onSearch:e=>{const a=e.target.value;V((e=>({...e,dealerSearchKey:a})))},defaultValue:R.dealerIds,search:R.dealerSearchKey,maxAllowed:100,tooltip:t("text.select_dealer")})}),p.jsx(x,{size:12,lg:12,children:p.jsx(B,{label:t("label.dealer_limit"),name:"supplier",items:ce||[],defaultValue:"".concat(R.Status||"L"),onChange:e=>{V({Status:"".concat(e.value)})}})}),p.jsx(x,{size:12,className:j("d-flex justify-content-end mt-4",I.downloadAndMailMobile),children:p.jsx(L,{onDownloadClick:me,onSendEmail:ue,isDisabled:$||y(q)})})]}),p.jsx(h,{children:p.jsx(x,{size:12,isLoading:ne,children:p.jsxs("div",{className:I.tableWrapper,children:[$&&p.jsx(k,{appearance:f.DANGER,icon:"i",direction:"horizontal",children:ie}),!$&&q&&p.jsxs(p.Fragment,{children:[p.jsx(M,{hasNextPage:!0,getNextPage:()=>{Q||Y()},priceFormattedKeys:[{key:"toplamLimit"},{key:"taahhutluFatura"},{key:"limitBoslugu"},{key:"kullanilabilirLimit"},{key:"risk"}],dateKeys:["limitGecerlilikTarihi"],data:q,classes:{bayiNo:I.rightAligned,limitBoslugu:I.rightAligned,limitGecerlilikTarihi:I.rightAligned,risk:I.rightAligned,taahhutluFatura:I.rightAligned,toplamLimit:I.rightAligned,kullanilabilirLimit:I.rightAligned}}),p.jsx("p",{className:I.tableLabel,children:t("text.live_data")})]}),Q&&p.jsx(w,{})]})})})]})})})})})})};export{C as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.