1import{j as t}from"./jsx-runtime-D_zvdyIk.js";import{r as u}from"./createLucideIcon-CiWnlb16.js";import{dz as K,dA as q,fG as W,d as Y,e as N,p5 as H,p6 as J,p7 as Q,o as X,gE as Z,p8 as ee,p9 as te,pa as k,pb as ae,L as se,pc as re,pd as C,bb as le,pe as O,pf as ne,pg as $,ph as oe,pi as de,pj as ce,pk as ie}from"./loginCallback-DUlVA6A0.js";import{a as A}from"./Select-YNaQnfBW.js";import{u as ue}from"./notistack.esm-h7EINNRQ.js";import{E as f}from"./ErrorMessage-BzkwuuEb.js";import{u as pe,d as F,a as P,D as me}from"./index-C0C2KPEQ.js";import"./config.release-CKeoGYk7.js";import"./CheckCircle-HampXhRV.js";import"./Close-C9FyhMtz.js";import"./DeleteOutline-CMp1eq1T.js";const be=K("plans/create/submit",async(b,w)=>{try{return(await q.post("/readjustments/plans",b.body)).data}catch(o){return W(o,w.rejectWithValue)}}),h={anchorOrigin:{vertical:"top",horizontal:"right"}},v=b=>`block mb-1.5 font-bold text-[#334e68] ${b?"!text-[#e12d39]":""}`;function Ee({mode:b="create",entityId:w,initial:o,onClose:E,onSaved:M}){const[j,T]=u.useState(w),[y,L]=u.useState(j?`/readjustments/plans/${j}/documents`:null),[c,V]=u.useState(b==="edit"),l=Y(),a=N(H),G=N(J),R=N(Q),n=pe(),[D,g]=u.useState(!1),{enqueueSnackbar:x}=ue(),s=e=>re(G,e),p=e=>{s(e)&&l(de(e))},{debtorsGroupByStatus:S}=N(X),U=u.useMemo(()=>{if(console.log(S),S)return Object.entries(S).sort(([e],[r])=>Number(r)-Number(e)).map(([e,r])=>({label:Number(e)===Z.Active?"ÐкÑивнÑе":"ÐавеÑÑеннÑе",options:r.map(d=>({value:d.id,label:d.value}))}))},[S]);u.useEffect(()=>{if(l(ee()),c&&o){const e=te(o.typeId)?.value??k[0]?.value??null;l(ae({debtor:o.debtor,stage:e,typeId:o.typeId,date:o.date})),n.init(o.documents??[])}else n.init([])},[]);const _=async()=>{const{ok:e,errors:r}=ce(a,n.activeCount>0);if(l(ie(r)),!e){x("ÐаполниÑе обÑзаÑелÑнÑе полÑ",{variant:"warning",...h});return}g(!0);try{const d={debtorId:a.debtor?.id??null,typeId:a.typeId,date:a.date};let i;if(c){if(!j){x("ÐÑибка не найден id",{variant:"error",...h}),g(!1);return}i=`/readjustments/plans/${j}/documents`}else{const m=await l(be({body:d})).unwrap();i=`/readjustments/plans/${m}/documents`,L(i),T(m),V(!0)}if(!await n.runSave({uploadOne:(m,B)=>P(i,m,B),deleteOne:m=>F(`${i}/${m}`)})){x("ÐÑибка ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ Ñайлов",{variant:"warning",...h}),g(!1);return}x(c?"Ðлан ÑоÑ
ÑанÑн":"Ðлан добавлен",{variant:"success",...h}),g(!1),M?.(),E?.()}catch{g(!1),x("ÐÑибка ÑоÑ
ÑанениÑ",{variant:"error",...h})}},z=u.useCallback(e=>{if(y)return n.saveOnce({localIndex:e,uploadOne:(r,d)=>P(y,r,d),deleteOne:r=>F(`${y}/${r}`)})},[n,y]);return R?t.jsx(se,{}):t.jsxs("form",{className:"flex flex-col gap-5",onSubmit:e=>e.preventDefault(),children:[t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[2fr_1fr] gap-5",children:[t.jsxs("div",{children:[t.jsx("label",{className:v(s("debtor")),children:"Ðаименование должника *"}),t.jsx(A,{isDisabled:c,isSearchable:!0,isClearable:!0,options:U,value:a.debtor?{value:a.debtor.id,label:a.debtor.value}:null,placeholder:"ÐÑбеÑиÑе должника...",noOptionsMessage:"ÐиÑего не найдено",onChange:e=>{p("debtor"),l(e?C({id:e.value,value:e.label}):C(null))}}),t.jsx(f,{message:s("debtor")})]}),t.jsxs("div",{children:[t.jsx("label",{className:v(s("date")),children:"ÐаÑа *"}),t.jsx(le,{disabled:c,dateFormat:"dd.MM.yyyy",selected:a.date?new Date(a.date):null,maxDate:new Date,onChange:e=>{if(p("date"),e){const r=e.getFullYear(),d=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0"),I=`${r}-${d}-${i}`;l(O(I))}else l(O(null))}}),t.jsx(f,{message:s("date")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:v(s("stage")),children:"Тип плана *"}),t.jsx("div",{className:"flex flex-row flex-wrap items-center gap-x-8 gap-y-2 pt-1.5",children:k.map(e=>t.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer text-sm text-[#334e68]",children:[t.jsx("input",{disabled:c,type:"radio",name:"plan-stage",className:"accent-[#2aa3d0] w-4 h-4",checked:a.stage===e.value,onChange:()=>{p("stage"),p("typeId"),l(ne(e.value))}}),e.label]},e.value))}),t.jsx(f,{message:s("stage")})]}),t.jsxs("div",{children:[t.jsx("label",{className:v(s("typeId")),children:"Ðид плана *"}),t.jsx(A,{isDisabled:c,options:$(a.stage).map(e=>({value:e.value,label:e.label})),value:a.typeId?{value:a.typeId,label:$(a.stage).find(e=>e.value===a.typeId)?.label}:null,placeholder:"ÐÑбеÑиÑе вид плана...",isClearable:!1,onChange:e=>{p("kind"),l(oe(e?e.value:null))}}),t.jsx(f,{message:s("typeId")})]}),t.jsxs("div",{children:[t.jsx("label",{className:v(s("document")),children:"ÐокÑменÑÑ *"}),t.jsx(me,{rows:n.rows,disabled:D,onAddFiles:e=>{p("document"),n.addFiles(e)},onRemoveNew:n.removeNew,onToggleDelete:n.toggleDelete,onTryOnce:z}),t.jsx(f,{message:s("document")})]}),t.jsxs("div",{className:"flex items-center justify-between mt-2",children:[t.jsxs("span",{className:"text-[13px] italic text-[#64748b]",children:["ÐолÑ, оÑмеÑеннÑе знаком ",t.jsx("span",{className:"text-[#e12d39]",children:"*"}),", обÑзаÑелÑÐ½Ñ Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ."]}),t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("button",{type:"button",onClick:E,disabled:D,className:"px-5 py-2 rounded-lg text-sm font-semibold bg-white text-[#334e68] border border-[#c0d1e3] transition-colors hover:bg-[#e1f1fa] cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:"ÐÑмена"}),t.jsx("button",{type:"button",onClick:_,disabled:D,className:"px-5 py-2 rounded-lg text-sm font-semibold bg-[#11b156] text-white border border-[#11b156] transition-colors hover:bg-[#0e9d4c] hover:border-[#0e9d4c] cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:"СоÑ
ÑаниÑÑ"})]})]})]})}export{Ee 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.