1import{j as e}from"./vendor-radix-j51FbGWj.js";import{u as K,r as d}from"./vendor-react-CzwWGMlW.js";import{u as M,z as a,e as p,k as Q,C as V,f as W,g as X,B as j,b as Y,L as v,I as S,A as R,l as U,a as Z}from"./index-CMgi7Nl8.js";import{T as ee,a as se,b as q,c as m,d as ae,e as h}from"./table-DvS7udR6.js";import{R as ne,a1 as te,L as re,aB as ie,a0 as le}from"./vendor-icons-CaDFxAI1.js";import"./vendor-utils-DYobRrOj.js";const pe=()=>{const{user:l,isAuthenticated:f}=M(),k=K(),[A,E]=d.useState([]),[H,L]=d.useState(!0),[g,T]=d.useState(!1),[I,D]=d.useState(!1),[w,_]=d.useState(!1),[t,y]=d.useState({inn:"",name:"",accountCode:""}),[z,F]=d.useState(""),[u,B]=d.useState(!1);d.useEffect(()=>{f&&!(l!=null&&l.isExpert)&&(a.error("У Ð²Ð°Ñ Ð½ÐµÑ Ð´Ð¾ÑÑÑпа к ÑÑой ÑÑÑаниÑе"),k("/dashboard")),f&&(l!=null&&l.isExpert)&&C()},[f,l,k]);const C=async()=>{try{L(!0);const s=await p.get("/api/expert/linked-accounts");E(s.data)}catch(s){console.error("ÐÑибка пÑи загÑÑзке ÑвÑзаннÑÑ
аккаÑнÑов:",s),a.error("Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ ÑпиÑок ÑвÑзаннÑÑ
аккаÑнÑов")}finally{L(!1)}},$=async s=>{try{const n=localStorage.getItem("token"),r=await p.post(`/api/expert/impersonate/${s}`);if(!r.data.token)throw new Error("Токен не полÑÑен Ð¾Ñ ÑеÑвеÑа");localStorage.setItem("expert_token",n),localStorage.setItem("token",r.data.token),a.success("ÐÑ
од вÑполнен ÑÑпеÑно. ТепеÑÑ Ð²Ñ ÑабоÑаеÑе под ÑÑеÑной запиÑÑÑ Ð¿Ð¾Ð»ÑзоваÑелÑ."),window.location.href="/dashboard"}catch(n){console.error("ÐÑибка пÑи вÑ
оде под полÑзоваÑелем:",n),a.error("Ðе ÑдалоÑÑ Ð²Ð¾Ð¹Ñи под ÑÑеÑнÑми даннÑми полÑзоваÑелÑ")}},O=async(s,n)=>{var r,c;if(window.confirm(`ÐÑ Ð´ÐµÐ¹ÑÑвиÑелÑно Ñ
оÑиÑе ÑдалиÑÑ/оÑвÑзаÑÑ ÐºÐ¾Ð¼Ð¿Ð°Ð½Ð¸Ñ "${n||s}"? ÐÑо дейÑÑвие невозможно оÑмениÑÑ.`))try{T(!0);const i=await p.delete(`/api/expert/delete-user/${s}`);E(x=>x.filter(N=>N._id!==s));const o=(i==null?void 0:i.data)||{};o.unlinked?a.success(o.message||"СвÑÐ·Ñ ÑкÑпеÑÑа Ñ ÐºÐ¾Ð¼Ð¿Ð°Ð½Ð¸ÐµÐ¹ Ñдалена"):o.deleted?a.success(o.message||"ÐолÑзоваÑÐµÐ»Ñ ÑÑпеÑно Ñдален"):a.success(o.message||"ÐпеÑаÑÐ¸Ñ Ð²Ñполнена")}catch(i){console.error("ÐÑибка пÑи Ñдалении полÑзоваÑелÑ:",i),a.error(((c=(r=i.response)==null?void 0:r.data)==null?void 0:c.message)||"Ðе ÑдалоÑÑ ÑдалиÑÑ Ð¿Ð¾Ð»ÑзоваÑелÑ")}finally{T(!1)}},G=()=>{D(s=>!s)},b=s=>{const{name:n,value:r}=s.target;if(n==="inn"){const c=r.replace(/[^\d]/g,"").slice(0,12);y(i=>({...i,inn:c}))}else y(c=>({...c,[n]:r}))},J=async s=>{var r,c,i,o;s.preventDefault();const n=String(t.accountCode||"").trim();if(!(t.inn.length===10||t.inn.length===12)){a.error("ÐÐРдолжен ÑодеÑжаÑÑ 10 или 12 ÑиÑÑ");return}try{if(_(!0),B(!1),F(""),n)await p.post("/api/expert/link-existing",{accountCode:n}),a.success("ÐÐ¾Ð¼Ð¿Ð°Ð½Ð¸Ñ Ð¿ÑивÑзана по accountCode");else{if(!t.name){a.error("УкажиÑе название компании");return}await p.post("/api/expert/add-company",{inn:t.inn,name:t.name}),a.success("ÐÐ¾Ð¼Ð¿Ð°Ð½Ð¸Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð°")}y({inn:"",name:"",accountCode:""}),D(!1),await C()}catch(x){console.error("ÐÑибка пÑи обÑабоÑке компании:",x);const N=(c=(r=x.response)==null?void 0:r.data)==null?void 0:c.message,P=(o=(i=x.response)==null?void 0:i.data)==null?void 0:o.existingEmail;P&&(F(P),B(!0)),a.error(N||(n?"Ðе ÑдалоÑÑ Ð¿ÑивÑзаÑÑ ÐºÐ¾Ð¼Ð¿Ð°Ð½Ð¸Ñ":"Ðе ÑдалоÑÑ Ð´Ð¾Ð±Ð°Ð²Ð¸ÑÑ ÐºÐ¾Ð¼Ð¿Ð°Ð½Ð¸Ñ"))}finally{_(!1)}};return H?e.jsx(Q,{}):e.jsx("div",{"data-testid":"expertpanel-page",children:e.jsx("div",{className:"content",children:e.jsxs(V,{className:"rounded-lg",children:[e.jsxs(W,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsx(X,{className:"text-2xl font-semibold",children:"ÐÐ°Ð½ÐµÐ»Ñ ÑкÑпеÑÑа: ÑпÑавление ÑвÑзаннÑми аккаÑнÑами"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:C,disabled:g,children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),"ÐбновиÑÑ"]}),e.jsxs(j,{size:"sm",onClick:G,disabled:w,children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"ÐобавиÑÑ/ÐÑивÑзаÑÑ"]})]})]}),e.jsxs(Y,{children:[I&&e.jsxs("form",{onSubmit:J,className:"mb-6 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-4 items-end",children:[e.jsxs("div",{className:"md:col-span-3",children:[e.jsx(v,{htmlFor:"new-company-inn",children:"ÐÐÐ *"}),e.jsx(S,{type:"text",id:"new-company-inn",name:"inn",placeholder:"ÐÐÐ",value:t.inn,onChange:b,pattern:"\\d{10}|\\d{12}",title:"ÐÐРдолжен ÑодеÑжаÑÑ 10 или 12 ÑиÑÑ",required:!0})]}),e.jsxs("div",{className:u?"md:col-span-5":"md:col-span-7",children:[e.jsx(v,{htmlFor:"new-company-name",children:"Ðазвание компании *"}),e.jsx(S,{type:"text",id:"new-company-name",name:"name",placeholder:"ÐаÐ
1·Ð²Ð°Ð½Ð¸Ðµ компании",value:t.name,onChange:b,required:!u})]}),u&&e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(v,{htmlFor:"new-company-accountcode",children:"Ðод аккаÑнÑа *"}),e.jsx(S,{type:"text",id:"new-company-accountcode",name:"accountCode",placeholder:"accountCode",value:t.accountCode,onChange:b,required:!0})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsx(j,{type:"submit",className:"w-full",disabled:w,children:w?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),t.accountCode?"ÐÑивÑзка...":"Ðобавление..."]}):t.accountCode?"ÐÑивÑзаÑÑ":"ÐобавиÑÑ"})})]}),u&&z&&e.jsx(R,{children:e.jsxs(U,{children:["ÐÑганизаÑÐ¸Ñ Ñ ÑказаннÑм ÐÐÐ Ñже заÑегиÑÑÑиÑована на поÑÑÑ: ",e.jsx("strong",{children:z}),". ÐÐ»Ñ Ð¿ÑивÑзки ÑвÑжиÑеÑÑ Ð¿Ð¾ ÑÑой поÑÑе и запÑоÑиÑе код аккаÑнÑа и введиÑе вÑÑе."]})})]}),A.length===0?e.jsx(R,{children:e.jsx(U,{children:"СвÑзаннÑе аккаÑнÑÑ Ð½Ðµ найденÑ. ÐÐ»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ ÑвÑзей, иÑполÑзÑйÑе один accountCode Ð´Ð»Ñ Ð²ÑеÑ
ÑвÑзаннÑÑ
аккаÑнÑов."})}):e.jsx("div",{className:"rounded-md border",children:e.jsxs(ee,{children:[e.jsx(se,{children:e.jsxs(q,{children:[e.jsx(m,{children:"Ðазвание компании"}),e.jsx(m,{children:"ÐÐÐ"}),e.jsx(m,{children:"Email"}),e.jsx(m,{children:"ТаÑиÑ"}),e.jsx(m,{children:"ÐаÑа оконÑÐ°Ð½Ð¸Ñ ÑаÑиÑа"}),e.jsx(m,{children:"ÐаÑа ÑинÑ
ÑонизаÑии"}),e.jsx(m,{className:"text-center",children:"ÐейÑÑвиÑ"})]})}),e.jsx(ae,{children:A.map(s=>e.jsxs(q,{className:s._id===l._id?"bg-primary/5":"",children:[e.jsx(h,{className:"font-medium",children:s.name||"Ðе Ñказано"}),e.jsx(h,{children:s.inn}),e.jsx(h,{children:s.email}),e.jsx(h,{children:s.tariff||"Ðе ÑÑÑановлен"}),e.jsx(h,{children:s.tariffExpiryDate?new Date(s.tariffExpiryDate).toLocaleDateString():"Ðе ÑÑÑановлено"}),e.jsx(h,{children:s.lastProcessedAt?new Date(s.lastProcessedAt).toLocaleString():"Ðе ÑинÑ
ÑонизиÑовано"}),e.jsx(h,{className:"text-center",children:s._id!==l._id?e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>$(s._id),disabled:g,title:"ÐойÑи как полÑзоваÑелÑ",children:[e.jsx(ie,{className:"w-4 h-4 mr-1"}),"ÐойÑи"]}),e.jsxs(j,{variant:"destructive",size:"sm",onClick:()=>O(s._id,s.name||s.inn),disabled:g,title:"УдалиÑÑ Ð¿Ð¾Ð»ÑзоваÑелÑ",children:[e.jsx(le,{className:"w-4 h-4 mr-1"}),"УдалиÑÑ"]})]}):e.jsx(Z,{children:"ТекÑÑий аккаÑнÑ"})})]},s._id))})]})})]})]})})})};export{pe 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.