import{a as oe,r as i,j as e,A as Gn,T as R,S as Ge,R as Un,L as se,F as Ie,E as be,u as _t,b as Jt,I as J,c as St,B as $,d as wt,e as Ct,f as kt,g as Je,C as it,h as Ft,i as X,k as me,l as Rt,W as Vn,m as en,n as Kn,D as tn,o as nn,p as Zn,q as Yn,s as Qn,N as Xn,O as Jn,t as lt,v as fe,w as Be,x as at,y as sn,M as Te,z as rn,G as Xe,H as ve,J as es,Q as ts,K as ke,P as ns,U as Ee,V as Le,X as $e,Y as ss,Z as rs,_ as is,$ as ln,a0 as an,a1 as on,a2 as mt,a3 as We,a4 as Me,a5 as cn,a6 as dn,a7 as un,a8 as ls,a9 as yt,aa as Et,ab as as,ac as pn,ad as os,ae as Dt,af as cs,ag as st,ah as hn,ai as fn,aj as ds,ak as us,al as ps,am as hs}from"./vendor-qQyAgEX_.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const a of l)if(a.type==="childList")for(const d of a.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&r(d)}).observe(document,{childList:!0,subtree:!0});function s(l){const a={};return l.integrity&&(a.integrity=l.integrity),l.referrerPolicy&&(a.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?a.credentials="include":l.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(l){if(l.ep)return;l.ep=!0;const a=s(l);fetch(l.href,a)}})();const et="/api",ot=`${et}/v2`,It=`${ot}/campaign`;function xn(){const t=document.cookie.match(/csrftoken=([^ ;]+)/);if(t)return t[1]}function le(t,n){return oe.get(`${et}/${t}`,n)}function he(t,n,s){const r={"X-CSRFToken":xn(),...(s==null?void 0:s.headers)||{}},l={withCredentials:!0,...s,headers:r};return oe.post(`${et}/${t}`,n,l)}function fs(t,n){const s={"X-CSRFToken":xn()},r={withCredentials:!0,...n,headers:s};return oe.delete(`${et}/${t}`,r)}function V(t,n){return le(`v2/${t}/`,n)}function Y(t,n,s){return he(`v2/${t}/`,n,s)}function xs(t,n){return fs(`v2/${t}/`,n)}function ct(t){var s;const n=(s=t.response)==null?void 0:s.data;return n!=null&&n.detail?n.detail:n!=null&&n.error?n.error:t.message}const x={bluePale:{300:"#80BDFD",500:"#007BFB"},blue:{500:"#0002F3"},cyan:{500:"#00A2E8"},green:{200:"#ADE5D2",500:"#00B774"},primary:{50:"#FFFBF3",200:"#FFE3AB",300:"#FCD586",500:"#F9AB0D"},orange:{500:"#FC8816"},red:{500:"#FF3F3F"},redPale:{400:"#FD7967"},greyF:{50:"#F7F8FA",100:"#EFF1F5",600:"#9AA0AC",700:"#6E7788"},greyS:{200:"#D1D1D6"},dark:{500:"#383540"}},gs={token:{colorPrimary:"#F9AB0D",colorError:"#FF3F3F",colorText:"#383540",colorTextSecondary:"#6E7788",colorTextDisabled:"#C3C3C3",colorBgLayout:"#F7F8FA",borderRadius:6}},ms=[],ys=(t,n)=>{switch(n.type){case"ADD":return[n.payload,...t];case"REMOVE":return t.filter(s=>s.id!==n.payload);default:return t}},gn=i.createContext(ms),B=()=>i.useContext(gn);function js({children:t}){const[n,s]=i.useReducer(ys,[]),r=(o,f)=>{const p=Math.round(Math.random()*1e9);s({type:"ADD",payload:{id:p,severity:"info",text:o,...f}}),setTimeout(()=>{l(p)},5e3)},l=o=>{s({type:"REMOVE",payload:o})},a=(o,f={})=>{r(o,{...f,severity:"error"})},h={showMessage:r,showError:a,showRequestError:o=>{a(ct(o))}};return e.jsxs(gn.Provider,{value:h,children:[t,e.jsx("div",{style:{position:"fixed",left:0,bottom:0,zIndex:2e3,display:"flex",flexDirection:"column",gap:4,padding:4},children:n.map(o=>e.jsx(Gn,{type:o.severity==="error"?"error":"info",title:o.text,closable:!0,onClose:()=>l(o.id),showIcon:!0},o.id))})]})}const nt="Панель";function Ze({current:t,prev:n}){if(t==null||n==null)return"—";const s=t-n,r=n?(s/n*100).toFixed(1):0,l=s>=0,a=l?x.green[500]:x.red[500],d=l?Ct:kt;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2},children:[e.jsx("span",{style:{fontWeight:500},children:t.toLocaleString("ru-RU")}),e.jsxs("span",{style:{fontSize:12,color:a,display:"flex",alignItems:"center",gap:2},children:[e.jsx(d,{style:{fontSize:10}}),Math.abs(s).toLocaleString("ru-RU")," (",l?"+":"",r,"%)"]})]})}function Lt({placeholder:t,onSearch:n,options:s,onSelect:r,notFoundText:l}){const[a,d]=i.useState(""),[h,o]=_t("",300);i.useEffect(()=>{n(h)},[h]);const f=c=>{d(c),o(c)},p=(c,u)=>{r(c,u),d(""),o("")};return e.jsx(Jt,{value:a,options:a.length>=2?s:[],onSelect:p,onChange:f,style:{width:"100%"},notFoundContent:a.length<2?null:e.jsx(be,{image:be.PRESENTED_IMAGE_SIMPLE,description:l||"Ничего не найдено"}),children:e.jsx(J,{placeholder:t,prefix:e.jsx(St,{style:{color:x.greyF[500]}}),allowClear:!0})})}function vs(t){return[{title:"Предмет",dataIndex:"subject_name",key:"name",render:(n,s)=>e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:n}),e.jsx("div",{style:{fontSize:12,color:x.greyF[700]},children:s.category_name})]})},{title:"Продавцы",key:"sellers",align:"right",render:(n,s)=>e.jsx(Ze,{current:s.sellers,prev:s.sellers_prev})},{title:"Карточки",key:"cards",align:"right",render:(n,s)=>e.jsx(Ze,{current:s.cards,prev:s.cards_prev})},{title:"Заказы",key:"orders",align:"right",render:(n,s)=>e.jsx(Ze,{current:s.orders,prev:s.orders_prev})},{title:"",key:"actions",width:40,render:(n,s)=>e.jsx($,{type:"text",size:"small",icon:e.jsx(wt,{style:{fontSize:10,color:x.greyF[500]}}),onClick:r=>{r.stopPropagation(),t(s.key)}})}]}function bs(t){return[{title:"Запрос",dataIndex:"text",key:"text",render:n=>e.jsx("span",{style:{fontWeight:500},children:n})},{title:"Вчера",key:"day",align:"right",render:(n,s)=>e.jsx(Ze,{current:s.day,prev:s.day_prev})},{title:"Неделя",key:"week",align:"right",render:(n,s)=>e.jsx(Ze,{current:s.week,prev:s.week_prev})},{title:"",key:"actions",width:40,render:(n,s)=>e.jsx($,{type:"text",size:"small",icon:e.jsx(wt,{style:{fontSize:10,color:x.greyF[500]}}),onClick:r=>{r.stopPropagation(),t(s.record_id)}})}]}function _s(){const{showRequestError:t}=B(),[n,s]=i.useState(!0),[r,l]=i.useState(!1),[a,d]=i.useState([]),[h,o]=i.useState([]),[f,p]=i.useState([]),[c,u]=i.useState([]),m=i.useRef(null),y=i.useRef(null),[j,b]=i.useState([]),[k,_]=i.useState([]);i.useEffect(()=>{const g=sessionStorage.getItem("wb_key");g&&(sessionStorage.removeItem("wb_key"),Y("user/key-check",{key:g}))},[]),i.useEffect(()=>{S()},[]);const w=i.useCallback(g=>{if(g.length<2){b([]);return}le("wbstat/subjects/search/",{params:{query:g}}).then(v=>{b(v.data||[])})},[]),C=i.useCallback(g=>{if(g.length<2){_([]);return}le("wbstat/phrases/search/",{params:{query:g}}).then(v=>{_(v.data||[])})},[]);async function S(){var g,v;s(!0);try{const[F,M]=await Promise.all([le("wbstat/dashboard/phrase-groups/"),le("wbstat/dashboard/subject-groups/")]),z=(F.data||[]).find(ue=>ue.name===nt),P=(M.data||[]).find(ue=>ue.name===nt);m.current=z||null,y.current=P||null;const[G,de]=await Promise.all([z?le(`wbstat/dashboard/phrase-groups/${z.id}/phrases/`):Promise.resolve({data:{phrases:[]}}),P?le(`wbstat/dashboard/subject-groups/${P.id}/subjects/`):Promise.resolve({data:{subjects:[]}})]),ye=((g=G.data)==null?void 0:g.phrases)||[],O=((v=de.data)==null?void 0:v.subjects)||[];o(ye),d(O),await L(O,ye)}catch(F){t(F)}finally{s(!1)}}async function L(g=a,v=h){var z,P;const F=g.map(G=>G.subject_id),M=v.map(G=>G.text);if(F.length===0&&M.length===0){p([]),u([]);return}l(!0);try{const G=await he("wbstat/dashboard/tables/",{subject_ids:F,queries:M});p(((z=G.data)==null?void 0:z.subjects)||[]),u(((P=G.data)==null?void 0:P.queries)||[])}catch(G){t(G)}finally{l(!1)}}async function I(){if(m.current)return m.current;const g=await he("wbstat/dashboard/phrase-groups/",{name:nt,description:"Dashboard panel"});return m.current=g.data,g.data}async function N(){if(y.current)return y.current;const g=await he("wbstat/dashboard/subject-groups/",{name:nt,description:"Dashboard panel"});return y.current=g.data,g.data}async function Q(g){var F;const v=Number(g);if(!(!v||a.some(M=>M.subject_id===v)))try{const M=await N(),P=((F=(await he(`wbstat/dashboard/subject-groups/${M.id}/add/`,{subjects:[v]})).data)==null?void 0:F.subjects)||[];d(P),await L(P,h)}catch(M){t(M)}}async function te(g){var F;const v=a.find(M=>M.subject_id===g);if(v)try{const M=y.current,P=((F=(await he(`wbstat/dashboard/subject-groups/${M.id}/remove/`,{ids:[v.id]})).data)==null?void 0:F.subjects)||[];d(P),await L(P,h)}catch(M){t(M)}}async function E(g){var v;if(!(!g||h.some(F=>F.text===g)))try{const F=await I(),z=((v=(await he(`wbstat/dashboard/phrase-groups/${F.id}/add/`,{phrases:[g]})).data)==null?void 0:v.phrases)||[];o(z),await L(a,z)}catch(F){t(F)}}async function K(g){var v;try{const F=m.current,z=((v=(await he(`wbstat/dashboard/phrase-groups/${F.id}/remove/`,{ids:[g]})).data)==null?void 0:v.phrases)||[];o(z),await L(a,z)}catch(F){t(F)}}const Z=new Set(a.map(g=>g.subject_id)),ce=j.filter(g=>!Z.has(g.id)).map(g=>{var v;return{value:String(g.id),label:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:g.name}),e.jsx(R.Text,{type:"secondary",style:{fontSize:12},children:(v=g.category)==null?void 0:v.name})]})}}),T=new Set(h.map(g=>g.text)),W=k.filter(g=>!T.has(g.text)).map(g=>{var v;return{value:g.text,label:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:g.text}),e.jsxs(R.Text,{type:"secondary",style:{fontSize:12},children:[g.subject&&e.jsxs(e.Fragment,{children:[g.subject," · "]}),(v=g.count)==null?void 0:v.toLocaleString("ru-RU")]})]})}}),A=f.map(g=>({key:g.subject_id,subject_name:g.subject_name,category_name:g.category_name,sellers:g.suppliers_with_sells,sellers_prev:g.suppliers_with_sells_prev,cards:g.cards_with_orders_count,cards_prev:g.cards_with_orders_count_prev,orders:g.orders_qty,orders_prev:g.orders_qty_prev})),D=c.map(g=>{const v=h.find(F=>F.text===g.text);return{key:g.text,record_id:v==null?void 0:v.id,text:g.text,day:g.yesterday_count,day_prev:g.yesterday_prev_count,week:g.week_count,week_prev:g.week_prev_count}}),H=vs(te),q=bs(K);return n?e.jsx("div",{style:{display:"flex",justifyContent:"center",paddingTop:100},children:e.jsx(Ge,{indicator:e.jsx(Un,{style:{fontSize:32},spin:!0})})}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:32,maxWidth:720},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:12},children:[e.jsx(R.Title,{level:4,style:{margin:0},children:"Предметы"}),e.jsx(se,{to:"/external-analytics/niche-analysis",style:{textDecoration:"none",color:x.primary[500],fontWeight:600,fontSize:13},children:"Смотреть все"})]}),e.jsx(Lt,{placeholder:"Найти предмет...",onSearch:w,options:ce,onSelect:Q,notFoundText:"Предмет не найден"}),a.length>0?e.jsx(Ie,{dataSource:A,columns:H,pagination:!1,size:"small",bordered:!1,loading:r,locale:{emptyText:e.jsx(be,{description:"Нет данных",image:be.PRESENTED_IMAGE_SIMPLE})}}):e.jsx(R.Text,{type:"secondary",style:{padding:"8px 0"},children:"Добавьте предметы для отслеживания"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:12},children:[e.jsx(R.Title,{level:4,style:{margin:0},children:"Запросы"}),e.jsx(se,{to:"/search-queries",style:{textDecoration:"none",color:x.primary[500],fontWeight:600,fontSize:13},children:"Смотреть все"})]}),e.jsx(Lt,{placeholder:"Найти запрос...",onSearch:C,options:W,onSelect:E,notFoundText:"Запрос не найден"}),h.length>0?e.jsx(Ie,{dataSource:D,columns:q,pagination:!1,size:"small",bordered:!1,loading:r,locale:{emptyText:e.jsx(be,{description:"Нет данных",image:be.PRESENTED_IMAGE_SIMPLE})}}):e.jsx(R.Text,{type:"secondary",style:{padding:"8px 0"},children:"Добавьте запросы для отслеживания"})]})]})}const tt=[{id:6,name:"Поиск"},{id:5,name:"Карточки"}],Ss=[{id:0,name:"Все"},{id:1,name:"Активные"},{id:2,name:"Остановлены"},{id:3,name:"Неактивные"},{id:4,name:"Без биддера"}],mn=[{id:7,name:"Завершена"},{id:9,name:"Активна"},{id:11,name:"Приостановлена"}],ws=[{id:0,name:"Все"},...mn],Cs=t=>{const n=mn.find(s=>s.id===t);return n?n.name:""},ks=[{title:"Кампания",dataIndex:"id",key:"id"},{title:"Параметры",key:"name",render:(t,n)=>{var s,r;return n.name||((s=n.bidder)==null?void 0:s.query)||((r=n.bidder)==null?void 0:r.name)}},{title:"Статус",key:"status",render:(t,n)=>Cs(n.status)},{title:"Текущая ставка",key:"bet",align:"right",render:(t,n)=>{var s;return(s=n.bidder)==null?void 0:s.bet}},{title:"Позиция",key:"place",align:"right",render:(t,n)=>{var s;return(s=n.bidder)==null?void 0:s.place}},{title:"Биддер",key:"active",render:(t,n)=>{var s;return e.jsx(it,{checked:((s=n.bidder)==null?void 0:s.active)||!1})}},{title:"Макс ставка",key:"maxbet",align:"right",render:(t,n)=>{var s;return(s=n.bidder)==null?void 0:s.maxbet}},{title:"Макс позиция",key:"top_place",align:"right",render:(t,n)=>{var s;return(s=n.bidder)==null?void 0:s.top_place}},{title:"Мин позиция",key:"low_place",align:"right",render:(t,n)=>{var s;return(s=n.bidder)==null?void 0:s.low_place}}];function Fs({rows:t}){const n=Je();return e.jsx(Ie,{columns:ks,dataSource:t||[],rowKey:(s,r)=>r,size:"small",pagination:!1,scroll:{x:900},onRow:s=>({onClick:()=>{const r=s.bidder?`/campaigns/${s.bidder.id}/bidder`:`/campaigns/${s.id}`;n(r)},style:{cursor:"pointer"}})})}function Rs({options:t,value:n,onChange:s}){function r(a){return t.findIndex(d=>d.id===a)}const l=t.map((a,d)=>({key:String(d),label:a.name}));return e.jsxs("div",{children:[e.jsx("h4",{children:"Типы кампаний"}),e.jsx(Ft,{tabPosition:"left",activeKey:String(r(n)),onChange:a=>{s&&s(t[parseInt(a)].id)},items:l})]})}function Ds({options:t,value:n,onChange:s}){const r=t.map((l,a)=>({key:String(a),label:l.name}));return e.jsxs("div",{children:[e.jsx("h4",{children:"Магазины"}),e.jsx(Ft,{tabPosition:"left",activeKey:String(n),onChange:l=>{s&&s(parseInt(l))},items:r})]})}function _e({count:t=4}){return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[...Array(t)].map((n,s)=>e.jsx(X.Input,{active:!0,block:!0,style:{height:32,width:"100%"}},s))})}function Is({status:t,bidder:n,onChange:s}){return e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:8},children:[e.jsx(me,{style:{flex:1},size:"small",value:t||0,onChange:r=>s&&s("status",r),options:ws.map(r=>({value:r.id,label:r.name})),placeholder:"Статус"}),e.jsx(me,{style:{flex:1},size:"small",value:n||0,onChange:r=>s&&s("bidder",r),options:Ss.map(r=>({value:r.id,label:r.name})),placeholder:"Биддер"})]})}const Ts=`${ot}/supplier/`,Es=(t,n,s)=>{const r=new URLSearchParams({...s,advert_type:t,supplier_id:n});return`${It}/?${r.toString()}`};function Ls(){const[t,n]=Rt(),[s,r]=i.useState(!0),[l,a]=i.useState([]),[d,h]=i.useState([]),[o,f]=i.useState(void 0),p=parseInt(t.get("type")||6),c=parseInt(t.get("supplier")||0),u=parseInt(t.get("status")||0),m=parseInt(t.get("bidder")||0),y=(j,b)=>{const k=new URLSearchParams(t);k.set(j,b),n(k)};return i.useEffect(()=>(l.length===0&&(r(!0),oe.get(Ts).then(j=>{a(j.data)}).finally(()=>r(!1))),()=>{}),[]),i.useEffect(()=>{var j;if(l.length>0){const b=Es(p,(j=l[c])==null?void 0:j.id,{status:u,bidder:m});r(!0),oe.get(b).then(k=>{h(k.data)}).finally(()=>r(!1))}},[l,t]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(R.Title,{level:4,style:{margin:0},children:"Кампании"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"240px 1fr",gap:"16px"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx(Rs,{options:tt,value:p,onChange:j=>y("type",j)}),e.jsx(Ds,{options:l,value:c,onChange:j=>y("supplier",j)})]}),e.jsxs("div",{style:{flexGrow:1},children:[e.jsx(Is,{status:u,bidder:m,onChange:(j,b)=>y(j,b)}),s?e.jsx(_e,{count:5}):e.jsx(Fs,{rows:d})]})]})]})}const $s="ooo_mkeeper_web",qe=new Vn({clientId:$s,redirectUri:`${window.location.protocol}//${window.location.host}/wb-id-sdk/callback`,scope:"openid phone"}),yn="data:image/svg+xml,%3csvg%20width='128'%20height='128'%20viewBox='0%200%20128%20128'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='128'%20height='128'%20rx='64'%20fill='url(%23paint0_linear_0_1)'/%3e%3cpath%20d='M21.8564%2045.3936H27.9404V50.5889C29.3988%2048.7887%2030.7204%2047.4785%2031.9053%2046.6582C33.9333%2045.2682%2036.2347%2044.5732%2038.8096%2044.5732C41.7262%2044.5732%2044.0732%2045.291%2045.8506%2046.7266C46.8532%2047.5469%2047.7646%2048.7546%2048.585%2050.3496C49.9521%2048.39%2051.5586%2046.943%2053.4043%2046.0088C55.25%2045.0518%2057.3236%2044.5732%2059.625%2044.5732C64.5469%2044.5732%2067.8965%2046.3506%2069.6738%2049.9053C70.6309%2051.8193%2071.1094%2054.3942%2071.1094%2057.6299V82H64.7178V56.5703C64.7178%2054.1322%2064.1025%2052.4574%2062.8721%2051.5459C61.6644%2050.6344%2060.1833%2050.1787%2058.4287%2050.1787C56.0133%2050.1787%2053.9284%2050.9876%2052.1738%2052.6055C50.4421%2054.2233%2049.5762%2056.9235%2049.5762%2060.7061V82H43.3213V58.1084C43.3213%2055.6247%2043.0251%2053.8132%2042.4326%2052.6738C41.4984%2050.9648%2039.7552%2050.1104%2037.2031%2050.1104C34.8789%2050.1104%2032.7598%2051.0104%2030.8457%2052.8105C28.9544%2054.6107%2028.0088%2057.8691%2028.0088%2062.5859V82H21.8564V45.3936ZM80.0303%2031.79H85.9434V60.9453L101.734%2045.3936H109.596L95.582%2059.0996L110.382%2082H102.521L91.1045%2063.543L85.9434%2068.2598V82H80.0303V31.79Z'%20fill='black'/%3e%3cdefs%3e%3clinearGradient%20id='paint0_linear_0_1'%20x1='64'%20y1='32'%20x2='64'%20y2='82'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F27420'/%3e%3cstop%20offset='1'%20stop-color='%23F9AB0D'/%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e",Ms="auth_redirect",dt=()=>{const[t,n]=i.useState(!1),s=en(),r=()=>{var a;const l=(a=s.state)==null?void 0:a.from;l&&l!=="/auth/login"&&localStorage.setItem(Ms,l),qe.login()};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"calc(100vh - 200px)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:32},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("img",{src:yn,style:{width:48,height:48,borderRadius:24},alt:"mkeeper"}),e.jsx("span",{style:{fontSize:28,fontFamily:"Tahoma, Verdana, Segoe, sans-serif",color:x.dark[500]},children:"mkeeper"})]}),e.jsxs("button",{type:"button",onClick:()=>{n(!0),r()},disabled:t,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:320,height:52,padding:"0 24px",background:"#F6F6F9",border:"none",borderRadius:20,cursor:"pointer",fontSize:16,color:"#242429",transition:"background-color 0.2s"},onMouseEnter:l=>l.currentTarget.style.backgroundColor="#EDEDF0",onMouseLeave:l=>l.currentTarget.style.backgroundColor="#F6F6F9",children:[e.jsx("span",{children:"Войти с"}),e.jsxs("svg",{width:"40",height:"20",viewBox:"0 0 40 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M9.585 20C7.007 20 5.451 20 3.917 19.214C2.558 18.518 1.474 17.428 0.782 16.062C0 14.519 0 12.954 0 10.362V9.638C0 7.046 0 5.481 0.782 3.938C1.474 2.572 2.558 1.482 3.917 0.786C5.451 0 7.007 0 9.585 0H30.415C32.993 0 34.549 0 36.083 0.786C37.442 1.482 38.526 2.572 39.218 3.938C40 5.481 40 7.046 40 9.638V10.362C40 12.954 40 14.519 39.218 16.062C38.526 17.428 37.442 18.518 36.083 19.214C34.549 20 32.993 20 30.415 20H9.585Z",fill:"#242429"}),e.jsx("path",{d:"M17.271 6.879C16.552 6.879 15.902 7.098 15.348 7.472V4.052H13.815V10.36C13.815 12.279 15.365 13.824 17.261 13.824C19.158 13.824 20.725 12.289 20.725 10.342C20.725 8.396 19.192 6.879 17.27 6.879ZM10.313 10.806L8.91 7.124H7.836L6.425 10.806L5.014 7.124H3.341L5.81 13.598H6.883L8.364 9.742L9.854 13.598H10.927L13.387 7.124H11.724L10.313 10.806ZM17.262 12.28C16.223 12.28 15.348 11.443 15.348 10.352C15.348 9.261 16.171 8.433 17.271 8.433C18.37 8.433 19.193 9.296 19.193 10.352C19.193 11.407 18.318 12.28 17.262 12.28Z",fill:"#F6F6F9"}),e.jsx("path",{d:"M31.068 7.76H30.071V12.242H31.068C32.242 12.242 33.247 11.346 33.247 10.012C33.247 8.649 32.242 7.76 31.068 7.76Z",fill:"#F6F6F9"}),e.jsx("path",{d:"M36.408 5.378C36.023 4.618 35.408 3.999 34.652 3.612C33.792 3.171 32.666 3.171 30.415 3.171H29.648C27.397 3.171 26.272 3.171 25.412 3.612C24.656 3.999 24.041 4.618 23.656 5.378C23.218 6.242 23.218 7.374 23.218 9.637V10.362C23.218 12.625 23.218 13.757 23.656 14.621C24.041 15.382 24.656 16 25.412 16.387C26.272 16.828 27.397 16.828 29.648 16.828H30.415C32.666 16.828 33.792 16.828 34.652 16.387C35.408 16 36.023 15.382 36.408 14.621C36.846 13.757 36.846 12.625 36.846 10.362V9.637C36.846 7.374 36.846 6.242 36.408 5.378ZM27.425 13.713H25.892V6.286H27.425V13.713ZM31.046 13.713H28.54V6.286H31.046C33.308 6.286 34.781 7.917 34.781 10.01C34.781 12.082 33.308 13.713 31.046 13.713Z",fill:"#F6F6F9"})]})]})]})})},jt={},jn=i.createContext(jt);function zs({children:t}){const[n,s]=i.useState(jt),r=i.useRef(null),l=i.useRef(0),a=i.useRef(new Map),d=i.useCallback(()=>{const c=++l.current;return V("user/profile").then(u=>{c===l.current&&s({...u.data})})},[]),h=()=>{s({...jt,auth:!1})},o=i.useCallback((c,u)=>{a.current.set(c,u)},[]),f=i.useCallback(c=>{a.current.delete(c)},[]);i.useEffect(()=>{d()},[]),i.useEffect(()=>{if(!n.auth)return;const c=new Kn([{transport:"websocket",endpoint:"/api/centrifugo/connection/websocket"}],{getToken:()=>V("user/centrifugo-token").then(u=>u.data.token)});return c.on("publication",u=>{var m;((m=u.data)==null?void 0:m.op)==="getProfile"&&d(),a.current.forEach(y=>y(u))}),c.connect(),r.current=c,()=>{c.disconnect(),r.current=null}},[n.auth,d]);const p={profile:n,getProfile:d,clearProfile:h,addPublicationHandler:o,removePublicationHandler:f};return e.jsx(jn.Provider,{value:p,children:t})}const xe=()=>i.useContext(jn);function Ps(){const t=Je(),{clearProfile:n,profile:s}=xe(),r=()=>{qe.logout().then(()=>{}).catch(a=>console.log("wb logout error:",a)),he("user/logout").then(()=>{n(),t("/")}).catch(a=>{})};if(!s.auth)return e.jsx(se,{to:"/auth/login",style:{color:"inherit",textDecoration:"none"},children:e.jsx($,{type:"text",children:"Войти"})});const l=[{key:"profile",label:e.jsx(se,{to:"/profile",style:{color:"inherit",textDecoration:"none"},children:"Профиль"})},{key:"logout",label:"Выйти",onClick:r}];return e.jsx(tn,{menu:{items:l},trigger:["click"],children:e.jsx($,{type:"text",icon:e.jsx(nn,{}),style:{fontSize:"20px"}})})}const Ws=[{key:"niche-analysis",label:e.jsx(se,{to:"/external-analytics/niche-analysis",style:{color:"inherit",textDecoration:"none"},children:"Анализ ниш"})},{key:"category-analysis",label:e.jsx(se,{to:"/external-analytics/category-analysis",style:{color:"inherit",textDecoration:"none"},children:"Анализ категорий"})},{key:"category-matrix",label:e.jsx(se,{to:"/external-analytics/category-matrix",style:{color:"inherit",textDecoration:"none"},children:"Матрица категорий"})},{key:"subject-matrix",label:e.jsx(se,{to:"/external-analytics/subject-matrix",style:{color:"inherit",textDecoration:"none"},children:"Матрица предметов"})},{key:"search-queries",label:e.jsx(se,{to:"/search-queries",style:{color:"inherit",textDecoration:"none"},children:"Запросы"})}];function As(){const{profile:t}=xe(),n=t.auth===!0;return e.jsxs("header",{style:{position:"fixed",top:0,left:0,right:0,zIndex:1001,background:"#fff",boxShadow:"0 2px 8px rgba(0,0,0,0.06)",height:"56px",display:"flex",alignItems:"center",padding:"0 24px",justifyContent:"space-between",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs(se,{to:"/",style:{display:"flex",alignItems:"center",fontWeight:700,textDecoration:"none",fontSize:"18px",color:x.dark[500],marginRight:"16px"},children:[e.jsx("span",{style:{marginRight:"8px",height:"32px"},children:e.jsx("img",{src:yn,style:{width:"32px",height:"32px",borderRadius:"16px"}})}),e.jsx("span",{style:{color:x.dark[500],fontWeight:400,fontFamily:"Tahoma, Verdana, Segoe, sans-serif",lineHeight:1},children:"mkeeper"})]}),n&&e.jsx(tn,{menu:{items:Ws},trigger:["hover"],children:e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"6px 12px",borderRadius:"8px",cursor:"pointer",fontSize:"14px",fontWeight:500,color:x.dark[500],background:"#f5f5f5"},children:["Внешняя аналитика",e.jsx("span",{style:{fontSize:"10px",fontWeight:400,lineHeight:1,padding:"2px 5px",borderRadius:"4px",background:x.primary[500],color:x.dark[500],letterSpacing:"0.02em"},children:"BETA"}),e.jsx(Zn,{style:{fontSize:"10px"}})]})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[n&&e.jsx(se,{to:"/helpdesk",children:e.jsx($,{type:"text",icon:e.jsx(Yn,{}),style:{fontSize:"20px"}})}),n&&e.jsx(se,{to:"/wishes",children:e.jsx($,{type:"text",icon:e.jsx(Qn,{}),style:{fontSize:"20px"}})}),e.jsx(Ps,{})]})]})}function $t(){return e.jsx("div",{children:e.jsx(As,{})})}const Hs="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20style='margin:%20auto;%20background:%20none;%20display:%20block;%20shape-rendering:%20auto;'%20width='200px'%20height='200px'%20viewBox='0%200%20100%20100'%20preserveAspectRatio='xMidYMid'%3e%3cg%20transform='translate(80,50)'%3e%3cg%20transform='rotate(0)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='1'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.875s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.875s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(71.21320343559643,71.21320343559643)'%3e%3cg%20transform='rotate(45)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.875'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.75s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.75s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(50,80)'%3e%3cg%20transform='rotate(90)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.75'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.625s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.625s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(28.786796564403577,71.21320343559643)'%3e%3cg%20transform='rotate(135)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.625'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.5s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.5s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(20,50.00000000000001)'%3e%3cg%20transform='rotate(180)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.5'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.375s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.375s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(28.78679656440357,28.786796564403577)'%3e%3cg%20transform='rotate(225)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.375'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.25s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.25s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(49.99999999999999,20)'%3e%3cg%20transform='rotate(270)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.25'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='-0.125s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='-0.125s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3cg%20transform='translate(71.21320343559643,28.78679656440357)'%3e%3cg%20transform='rotate(315)'%3e%3ccircle%20cx='0'%20cy='0'%20r='6'%20fill='%23d8ebf9'%20fill-opacity='0.125'%3e%3canimateTransform%20attributeName='transform'%20type='scale'%20begin='0s'%20values='1.5%201.5;1%201'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%3e%3c/animateTransform%3e%3canimate%20attributeName='fill-opacity'%20keyTimes='0;1'%20dur='1s'%20repeatCount='indefinite'%20values='1;0'%20begin='0s'%3e%3c/animate%3e%3c/circle%3e%3c/g%3e%3c/g%3e%3c!--%20[ldio]%20generated%20by%20https://loading.io/%20--%3e%3c/svg%3e";function we(){const[t,n]=i.useState(0);return i.useEffect(()=>(n(1),()=>{n(0)}),[]),e.jsx("div",{className:"spinner-wrapper",children:e.jsx("img",{src:Hs,className:"spinner-img",style:{opacity:t}})})}const Mt="cookie_banner_dismissed";function Ns(){const[t,n]=i.useState(()=>!localStorage.getItem(Mt));if(!t)return null;const s=()=>{localStorage.setItem(Mt,"1"),n(!1)};return e.jsxs("div",{style:{position:"fixed",bottom:24,right:24,zIndex:2e3,background:"#fff",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",borderRadius:12,padding:"14px 18px",maxWidth:320,display:"flex",flexDirection:"column",gap:10,fontSize:13,color:x.dark[500]},children:[e.jsx("span",{children:"Мы используем файлы куки для корректной работы сервиса и аналитики. Продолжая использовать сайт, вы соглашаетесь с их использованием."}),e.jsx("button",{onClick:s,style:{alignSelf:"flex-end",background:x.primary[500],border:"none",borderRadius:8,padding:"6px 16px",fontSize:13,fontWeight:600,color:"#fff",cursor:"pointer"},children:"Закрыть"})]})}const Os=["/auth/login","/auth/logout","/auth/ext-auth","/wb-id-sdk/callback","/auth/wblogin"];function Bs(){const{profile:t}=xe(),n=en(),s=Os.includes(n.pathname);return t.auth===void 0?e.jsxs("div",{style:{display:"flex"},children:[e.jsx($t,{}),e.jsxs("main",{style:{flexGrow:1,minWidth:0,overflowX:"hidden",padding:"0 24px 24px 24px"},children:[e.jsx("div",{style:{height:"72px"}}),e.jsx(we,{})]})]}):t.auth===!1&&!s?e.jsx(Xn,{to:"/auth/login",replace:!0,state:{from:n.pathname+n.search+n.hash}}):e.jsxs("div",{style:{display:"flex"},children:[e.jsx($t,{}),e.jsxs("main",{style:{flexGrow:1,minWidth:0,overflowX:"hidden",padding:"0 24px 24px 24px"},children:[e.jsx("div",{style:{height:"72px"}}),e.jsx(Jn,{})]}),e.jsx(Ns,{})]})}const vn=({label:t,headers:n,rows:s})=>e.jsxs("div",{children:[t&&e.jsx(R.Title,{level:4,style:{padding:"16px"},children:t}),e.jsx(Ie,{columns:n,dataSource:s||[],rowKey:(r,l)=>l,size:"small",pagination:!1,scroll:{x:900},locale:{emptyText:"Empty..."}})]}),qs=()=>{let{subjectId:t}=lt();const[n,s]=i.useState(!0),[r,l]=i.useState([]),a="Запросы по категории",d=[{title:"ПОИСКОВЫЙ ЗАПРОС",key:"text",dataIndex:"text"},{title:"ПРИОРИТЕТ",key:"priority",dataIndex:"priority",align:"right"},{title:"ПОКАЗОВ В МЕСЯЦ",key:"requestCount",dataIndex:"requestCount",align:"right"}];return i.useEffect(()=>{s(!0),V("wbstat/priority-subjects",{params:{id:t}}).then(o=>{var f;l(((f=o.data)==null?void 0:f.results)||[])}).finally(()=>s(!1))},[]),n?e.jsx(Ge,{}):e.jsx("div",{children:e.jsx(vn,{label:a,headers:d,rows:r})})},Gs=()=>e.jsxs("div",{style:{background:"#fff",borderRadius:4,padding:16,marginBottom:8,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:[e.jsxs(fe.Group,{style:{marginBottom:8},children:[e.jsx(fe,{value:"isByWord",children:"По словам"}),e.jsx(fe,{value:"isBySearch",children:"История запросов"}),e.jsx(fe,{value:"isByCategory",children:"По категории"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(J,{placeholder:"Поисковый запрос",size:"small",style:{flex:1}}),e.jsx($,{type:"primary",style:{padding:"0 25px",fontSize:12,fontWeight:700},children:"Подобрать"})]})]}),Us=()=>{const t=[{title:"СТАТИСТИКА ПО СЛОВАМ",align:"left"},{title:"ПОКАЗОВ В МЕСЯЦ",align:"left"}];return e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx(Gs,{}),e.jsx(vn,{headers:t})]})};function Vs({options:t,onChange:n,value:s}){return e.jsx(Be,{dataSource:t||[],renderItem:(r,l)=>{var a;return e.jsx(Be.Item,{onClick:()=>{n(r)},style:{cursor:"pointer",background:(r==null?void 0:r.id)===(s==null?void 0:s.id)?"#FFFBF3":"transparent",padding:"8px 16px"},children:e.jsx(Be.Item.Meta,{title:r.name,description:(a=r.category)==null?void 0:a.name})},l)}})}function pe(t){return t.toLocaleString()}const Ks=[{title:"Фраза",dataIndex:"text",key:"text"},{title:"Приоритет",dataIndex:"priority",key:"priority"},{title:"Запросов за неделю",key:"weekRequestCount",render:(t,n)=>pe(n.weekRequestCount)},{title:"Запросов за месяц",key:"monthRequestCount",render:(t,n)=>pe(n.monthRequestCount)},{title:"Запросов за 3 месяца",key:"quarterRequestCount",render:(t,n)=>pe(n.quarterRequestCount)}];function bn({rows:t}){return t!=null&&t.length?e.jsx(Ie,{columns:Ks,dataSource:t||[],rowKey:(n,s)=>s,size:"small",pagination:!1,scroll:{x:900}}):null}function Zs(){const[t,n]=i.useState(!1),[s,r]=i.useState([]),[l,a]=i.useState(""),[d,h]=i.useState([]),[o,f]=i.useState([]),[p,c]=i.useState(void 0),[u,m]=_t("",300);i.useEffect(()=>{p&&(n(!0),V(`wbstat/subjects/phrases/${p.id}`).then(b=>{var k,_;h(((k=b.data)==null?void 0:k.results)||[]),f(((_=b.data)==null?void 0:_.count)||0)}).finally(()=>n(!1)))},[p]),i.useEffect(()=>{if(l.length<3){r([]);return}V("wbstat/subjects/search",{params:{query:l}}).then(k=>{var _;r(((_=k.data)==null?void 0:_.results)||[])}).finally(()=>n(!1))},[u]);const y=b=>{a(b),m(b)},j=()=>{window.location.href=`/api/wbstat/subjects/phrases/${p.id}/xlsx/${p.name}.xlsx`};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(R.Title,{level:4,style:{margin:0},children:"Фразы по категориям"}),e.jsx("div",{children:e.jsx(J,{onChange:b=>{y(b.target.value)},value:l,placeholder:"Введите текст для поиска категории",size:"large"})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"240px 1fr",gap:"20px"},children:[e.jsx("div",{children:e.jsx(Vs,{options:s,onChange:c,value:p})}),e.jsxs("div",{style:{flexGrow:1},children:[t?e.jsx(_e,{count:1}):e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:!!(d!=null&&d.length)&&e.jsxs($,{onClick:j,icon:e.jsx(at,{}),children:["Скачать ",o," фраз в xlsx"]})}),t?e.jsx(_e,{count:5}):e.jsx(bn,{rows:d})]})]})]})}function Ys(){const{subjectId:t}=lt(),[n,s]=i.useState(!1),[r,l]=i.useState([]),[a,d]=i.useState(0),[h,o]=i.useState(void 0);i.useEffect(()=>{V("wbstat/subjects/search",{params:{id:t}}).then(c=>{var u,m,y;o(((m=(u=c.data)==null?void 0:u.results)==null?void 0:m.length)>0?(y=c.data)==null?void 0:y.results[0]:void 0)}).finally(()=>s(!1))},[]),i.useEffect(()=>{h&&(s(!0),V(`wbstat/subjects/phrases/${t}`).then(p=>{var c,u;l(((c=p.data)==null?void 0:c.results)||[]),d(((u=p.data)==null?void 0:u.count)||0)}).finally(()=>s(!1)))},[h]);const f=()=>{window.location.href=`/api/wbstat/subjects/phrases/${t}/xlsx/${h.name}.xlsx`};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs(R.Title,{level:4,style:{margin:0},children:["Приоритетные фразы по категории ",h==null?void 0:h.name]}),e.jsxs("div",{style:{flexGrow:1},children:[n?e.jsx(_e,{count:1}):e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsxs($,{onClick:f,icon:e.jsx(at,{}),children:["Скачать ",a," фраз в xlsx"]})}),n?e.jsx(_e,{count:5}):e.jsx(bn,{rows:r})]})]})}const Qs=t=>`/campaigns/${t}`,Xs=t=>`/campaigns/${t}/bidder`;function Js({instance:t,campaignId:n}){var s,r,l;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",columnGap:8,alignItems:"center",justifyContent:"space-between"},children:["Актуальная ставка: 0",e.jsx("a",{href:Qs(n),children:e.jsx($,{type:"link",children:"Изменить параметры"})})]}),e.jsx(R.Title,{level:5,style:{margin:0},children:"Параметры биддера"}),e.jsx(J,{id:"max-cpm",placeholder:"Максимальная ставка",value:((s=t.bidder)==null?void 0:s.maxbet)??"",size:"small"}),e.jsx(J,{id:"top-place",placeholder:"Верхняя позиция",value:((r=t.bidder)==null?void 0:r.top_place)??"",size:"small"}),e.jsx(J,{id:"low-place",placeholder:"Нижняя позиция",value:((l=t.bidder)==null?void 0:l.low_place)??"",size:"small"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx($,{type:"primary",children:"Сохранить изменения"}),e.jsx($,{children:"Запустить биддер"})]})]})}const er=[{title:"Позиция",dataIndex:"place",key:"place"},{title:"Бренд",key:"brand",render:(t,n)=>`${n.brand} (${n.advert_id})`},{title:"Ставка",dataIndex:"cpm",key:"cpm",align:"right"}];function _n({data:t,place:n,campaignId:s}){const r=t==null?void 0:t.filter(l=>!n&&l.place<=20||l.place<4||l.place>t.length-3||0<=n-l.place&&n-l.place<10||0<=l.place-n&&l.place-n<5);return e.jsx(Ie,{columns:er,dataSource:r||[],rowKey:"place",size:"small",pagination:!1,rowClassName:l=>l.advert_id===s?"ant-table-row-bold":""})}function tr({instance:t}){const n=t.updated_at?new Date(t.updated_at):void 0,s=[{label:"Статус",value:t.active?"Активна":"Не активна"},{label:"Актуальная ставка",value:t.bet},{label:"Ожидаемое место",value:t.place},{label:"Обновлено",value:n==null?void 0:n.toLocaleString()}];return e.jsxs("div",{children:[e.jsx(R.Title,{level:5,style:{margin:0},children:"Состояние"}),e.jsx(Be,{dataSource:s,renderItem:r=>e.jsx(Be.Item,{children:e.jsx(Be.Item.Meta,{title:r.value,description:r.label})})})]})}const nr=(t,n)=>(tt.find(s=>s.id===t),`${It}/${n}`),sr=t=>`${ot}/auction/${t}/`;function rr(){var f,p;const{campaignId:t}=lt(),[n,s]=i.useState(!0),[r,l]=i.useState([]),[a,d]=i.useState([]),[h,o]=i.useState(void 0);return i.useEffect(()=>{s(!0),oe.get(nr(6,t)).then(c=>{l(c.data)}).finally(()=>s(!1)),oe.get(sr(t)).then(c=>{var u,m;(m=(u=c.data)==null?void 0:u.data)==null||m.forEach((y,j)=>{y.place=j+1}),d(c.data)})},[t]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx(sn,{items:[{title:e.jsx("a",{href:"/campaigns",children:"Мои кампании"})},{title:t}]}),e.jsxs(R.Title,{level:5,style:{margin:0},children:[(f=tt.find(c=>c.id===r.advert_type))==null?void 0:f.name,": ",r.name]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"20px"},children:[e.jsx(Js,{instance:r,campaignId:t}),e.jsx("div",{children:e.jsx(tr,{instance:r.bidder||{}})}),e.jsx("div",{children:e.jsx(_n,{...a,campaignId:t,place:(p=r.bidder)==null?void 0:p.place})})]})]})}function ir({supplierId:t}){const[n,s]=i.useState(!1),r=()=>{s(!0)},l=()=>{s(!1)},a=()=>"Ключ API";return e.jsxs(e.Fragment,{children:[e.jsx($,{onClick:r,type:"link",children:"Добавить"}),e.jsxs(Te,{open:n,onCancel:l,title:`Добавить ${a()} API`,onOk:l,okText:"Сохранить",cancelText:"Отмена",children:[e.jsx("p",{children:"Добавьте ключ API в кабинете поставщика и вставьте его сюда"}),e.jsx(J,{autoFocus:!0,id:"api_key",placeholder:a()})]})]})}function lr({item:t}){return e.jsxs("div",{style:{border:"solid thin #ccc",borderRadius:"8px",padding:4},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[e.jsx(R.Title,{level:5,style:{margin:0},children:t.name}),e.jsx($,{type:"text",children:"Удалить"})]}),e.jsxs("div",{children:["Ключ API: ",t!=null&&t.api_key?"Есть":e.jsx(ir,{supplierId:t.id,keyType:"uni"})]})]})}function ar(){const[t,n]=i.useState(!1),s=()=>{n(!0)},r=()=>{n(!1)};return e.jsxs(e.Fragment,{children:[e.jsx($,{onClick:s,type:"primary",children:"Добавить поставщика"}),e.jsxs(Te,{open:t,onCancel:r,title:"Добавить поставщика",onOk:r,okText:"Сохранить",cancelText:"Отмена",children:[e.jsx("p",{children:"Добавьте ключ API в кабинете поставщика и вставьте его сюда"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx(J,{autoFocus:!0,id:"name",placeholder:"Наименование"}),e.jsx(J,{id:"api_key",placeholder:"Ключ API"})]})]})]})}const Ce=({children:t,...n})=>{const{variant:s,color:r,sx:l,size:a,type:d,disabled:h,onClick:o,component:f,href:p,target:c,...u}=n;let m="default",y=!1;s==="contained"?m="primary":s==="outlined"&&(m="default"),r==="error"&&(y=!0);const j={fontSize:"16px",lineHeight:"26px",fontWeight:500,padding:"8px 20px",height:"auto",...l||{}};return f==="a"||p?e.jsx("a",{href:p,target:c,style:{textDecoration:"none"},children:e.jsx($,{type:m,danger:y,disabled:h,onClick:o,style:j,htmlType:d,children:t})}):e.jsx($,{type:m,danger:y,disabled:h,onClick:o,style:j,htmlType:d,children:t})},Sn=()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("rect",{width:"24",height:"24",rx:"12",fill:"#F7F8FA"}),e.jsx("path",{d:"M7 6.99988L17 16.9999",stroke:"#6E7788","stroke-width":"1.3","stroke-linecap":"square","stroke-linejoin":"round"}),e.jsx("path",{d:"M17 6.99988L7 16.9999",stroke:"#6E7788","stroke-width":"1.3","stroke-linecap":"square","stroke-linejoin":"round"})]}),or=[{label:"1 месяц (30 дней)",value:1},{label:"3 месяца (90 дней)",value:3},{label:"6 месяцев (180 дней)",value:6},{label:"1 год (365 дней)",value:12}],cr=[{value:"russia",label:"Российская Федерация",icon:"🇷🇺"},{value:"foreign",label:"Иностранная карта",icon:"🌐"}];function dr({method:t,selected:n,onClick:s}){return e.jsxs("div",{onClick:s,style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:8,padding:"16px 12px",border:`1px solid ${n?x.primary[500]:x.greyS[200]}`,borderRadius:8,background:n?x.primary[50]:"#fff",cursor:"pointer",transition:"border-color 0.2s, background 0.2s"},children:[e.jsx("span",{style:{fontSize:32,lineHeight:1},children:t.icon}),e.jsx(R.Text,{style:{fontSize:13,textAlign:"center"},children:t.label})]})}function Ye({children:t,disabled:n,variant:s="contained",licenseKey:r}){const[l,a]=rn.useState(!1),[d,h]=i.useState([]),[o,f]=i.useState(!0),[p,c]=i.useState(!1),[u,m]=i.useState(null),[y,j]=i.useState(1),[b,k]=i.useState("russia"),[_,w]=i.useState(!1),[C,S]=i.useState(null),{showRequestError:L}=B(),I=()=>{f(!0),Promise.all([V("user/tariff"),V("user/tariff/current").catch(()=>null)]).then(([g,v])=>{const F=g.data??[],M=v==null?void 0:v.data,z=M?[M,...F.filter(P=>P.id!==M.id)]:F;z.length&&(h(z),m(z[0].id))}).catch(g=>{L(g)}).finally(()=>f(!1))};i.useEffect(()=>{l&&I()},[l]);const N=()=>{c(!0);const g=b!=="foreign"&&_?"cloudpayments2":"cloudpayments";he("billing/get_payment_link",{tariff:u,months:y,payment_method:b,source:"site",subscription:b==="russia"?_:!1,...g?{agent:g}:{},...r?{key:r}:{},...(E==null?void 0:E.devices)>0?{devices:C}:{}}).then(v=>{v.data.url?(window.open(v.data.url,"_blank").focus(),te()):L("Ошибка при создании платежа")}).catch(v=>{L(`Ошибка при создании платежа: ${ct(v)}`)}).finally(()=>c(!1))},Q=()=>a(!0),te=()=>a(!1),E=d.find(g=>g.id===u);i.useEffect(()=>{(E==null?void 0:E.devices)>0?S(g=>g===null||gv===3?g.price3??0:v===6?g.price6??0:v===12?g.price12??0:g.price??0,Z=(g,v)=>v===3?g.device_price3??0:v===6?g.device_price6??0:v===12?g.device_price12??0:g.device_price??0,ce=(g,v,F=0)=>{if(!g||v===1)return null;const M=(g.price??0)+F*(g.device_price??0);if(!M)return null;const z=K(g,v)+F*Z(g,v),P=v*M,G=Math.floor((1-z/P)*100);return G>0?G:null},T=(E==null?void 0:E.devices)>0&&C>E.devices?C-E.devices:0,W=E?Z(E,y):0,A=E?K(E,y):null,D=A!==null?A+T*W:null,H=ce(E,y,T),q=or.map(g=>{if(g.value===1||!E)return g;const v=ce(E,g.value);return v?{...g,label:`${g.label} — скидка ${v}%`}:g});return e.jsxs(e.Fragment,{children:[e.jsx(Ce,{disabled:n,variant:s,onClick:Q,color:"primary",children:t}),e.jsx(Te,{open:!!l,onCancel:te,title:"Покупка тарифа",footer:null,closeIcon:e.jsx(Sn,{}),width:500,children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16,paddingTop:8},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx(R.Text,{style:{color:x.greyF[700]},children:"Тариф:"}),e.jsx(me,{style:{width:"100%"},loading:o,value:u,onChange:m,options:d.map(g=>({label:g.name,value:g.id}))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx(R.Text,{style:{color:x.greyF[700]},children:"Срок оплаты:"}),e.jsx(me,{style:{width:"100%"},value:y,onChange:j,options:q})]}),(E==null?void 0:E.devices)>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx(R.Text,{style:{color:x.greyF[700]},children:"Количество устройств:"}),e.jsx(Xe,{style:{width:"100%"},min:E.devices,value:C,onChange:g=>S(g)}),T>0&&e.jsxs(R.Text,{style:{fontSize:12,color:x.greyF[700]},children:["+",T," доп. ",T===1?"устройство":T<5?"устройства":"устройств"," × ",W.toLocaleString("ru-RU")," ₽"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx(R.Text,{style:{color:x.greyF[700]},children:"Способ оплаты:"}),e.jsx("div",{style:{display:"flex",gap:8},children:cr.map(g=>e.jsx(dr,{method:g,selected:b===g.value,onClick:()=>k(g.value)},g.value))})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[e.jsx(it,{checked:_&&b==="russia",onChange:g=>w(g.target.checked),disabled:b==="foreign",className:"checkbox-large",style:{fontSize:16,fontWeight:500},children:"Подключить автоплатёж"}),_&&b==="russia"&&e.jsxs(R.Text,{style:{fontSize:12,color:x.greyF[700],paddingLeft:24},children:["Условия автоплатежа",e.jsx("br",{}),"Автоматическое списание будет производиться каждые 30 дней"]}),b==="foreign"&&e.jsx(R.Text,{style:{fontSize:12,color:x.greyF[700]},children:"При оплате методом «Иностранная карта» нет возможности подключить автоплатёж."})]}),e.jsx(ve,{style:{margin:0}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",background:x.primary[50],border:`1px solid ${x.primary[200]}`,borderRadius:8,padding:"12px 16px"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx(R.Text,{style:{color:x.greyF[700],fontSize:13},children:"Итого:"}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[e.jsx(R.Text,{strong:!0,style:{fontSize:22},children:D!==null?`${D.toLocaleString("ru-RU")} ₽`:"—"}),H&&D!==null&&E&&e.jsxs(R.Text,{style:{fontSize:14,color:x.greyF[400],textDecoration:"line-through"},children:[(y*((E.price??0)+T*(E.device_price??0))).toLocaleString("ru-RU")," ₽"]})]})]}),e.jsx(Ce,{variant:"contained",color:"primary",onClick:N,disabled:!u||p,loading:p,children:"Оплатить"})]}),e.jsxs(R.Text,{style:{textAlign:"center",color:x.greyF[700],fontSize:13},children:["По вопросам с оплатой — ",e.jsx(R.Link,{href:"https://t.me/adm_mkeeper",target:"_blank",children:"@adm_mkeeper"})]})]})})]})}function ur(){var p;const[t,n]=i.useState(!1),[s,r]=i.useState(void 0),{showRequestError:l,showError:a}=B();i.useEffect(()=>{n(!0),V("user/license").then(c=>{r(c.data)}).catch(c=>l(c)).finally(()=>n(!1))},[]);const d=()=>{he("billing/get_payment_link",{}).then(c=>{c.data.url?window.open(c.data.url,"_blank").focus():a("Ошибка при создании платежа")}).catch(c=>{l(`Ошибка при создании платежа: ${ct(c)}`)})};if(t)return e.jsx(_e,{count:3});let h=!1;if(!(s!=null&&s.length))h=!0;else{const c=s[0];new Date(c.action_date).getFullYear()<2020&&(h=!0)}if(h)return e.jsxs("div",{style:{display:"flex",columnGap:12,alignItems:"center"},children:[e.jsx(R.Text,{children:"Отстутствует лицензия"}),e.jsx(Ye,{children:"Активировать подписку"})]});const o=s[0],f=new Date(o.action_date);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs(R.Text,{style:{lineHeight:1.4},children:["Номер лицензии: ",o.key]}),e.jsxs(R.Text,{style:{lineHeight:1.4},children:["Тариф ",(p=o.tariff)==null?void 0:p.name]}),o.is_active?e.jsxs(R.Text,{style:{lineHeight:1.4},children:["Подписка активна до ",f.toLocaleDateString()]}):e.jsxs(R.Text,{style:{lineHeight:1.4},children:["Подписка закончилась ",f.toLocaleDateString()]})]}),e.jsx("div",{style:{marginTop:8,display:"flex",gap:8},children:o.tariff===void 0?e.jsx(Ye,{children:"Выбрать тариф"}):e.jsx(e.Fragment,{children:e.jsx(Ce,{variant:"contained",onClick:d,children:"Продлить подписку"})})})]})}const pr="user/suppliers";function hr(){const[t,n]=i.useState(!0),[s,r]=i.useState([]);return i.useEffect(()=>{n(!0),V(pr).then(l=>{r(l.data)}).finally(()=>n(!1))},[]),t?e.jsx("div",{children:"Загрузка..."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",columnGap:12,alignItems:"center"},children:[e.jsx(ar,{}),e.jsx(ur,{}),e.jsx(se,{to:"/devices",children:e.jsx($,{children:"Расширение Chrome"})})]}),s.map((l,a)=>e.jsx(lr,{item:l},a))]})}const fr=`${et}/cabinet/supplier_full/`;function xr(){const[t,n]=i.useState([]),[s,r]=i.useState(!0);return i.useEffect(()=>{t.length===0&&(r(!0),oe.get(fr).then(l=>{n(l.data)}).finally(()=>r(!1)))},[]),e.jsxs("div",{children:[e.jsx("h1",{children:"Поставщики и ключи API"}),e.jsx(hr,{suppliers:t})]})}function gr({instance:t,campaignId:n}){return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx(J,{id:"name",placeholder:"Наименование кампании",value:t.name??"",size:"small"}),e.jsx(J,{id:"cpm",placeholder:"Ставка",value:t.bet??"",size:"small",type:"number"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",columnGap:8},children:[e.jsx($,{type:"primary",children:"Сохранить изменения"}),e.jsx("a",{href:Xs(n),children:e.jsx($,{type:"link",children:"Запустить биддер"})})]})]})}const mr=(t,n)=>(tt.find(s=>s.id===t),`${It}/${n}`),yr=t=>`${ot}/auction/${t}/`;function jr(){var f;const{campaignId:t}=lt(),[n,s]=i.useState(!0),[r,l]=i.useState([]),[a,d]=i.useState([]),[h,o]=i.useState(void 0);return i.useEffect(()=>{s(!0),oe.get(mr(6,t)).then(p=>{l(p.data)}).finally(()=>s(!1)),oe.get(yr(t)).then(p=>{var c,u;(u=(c=p.data)==null?void 0:c.data)==null||u.forEach((m,y)=>{m.place=y+1}),d(p.data)})},[t]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx(sn,{items:[{title:e.jsx("a",{href:"/campaigns",children:"Мои кампании"})},{title:t}]}),e.jsxs(R.Title,{level:5,style:{margin:0},children:["Изменение: ",(f=tt.find(p=>p.id===r.advert_type))==null?void 0:f.name,": ",r.name]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"20px"},children:[n?e.jsx("div",{style:{width:"100%"},children:e.jsx(_e,{})}):e.jsx(gr,{instance:r,campaignId:t}),e.jsx("div",{}),e.jsx(_n,{...a,campaignId:t})]})]})}const vr="&appType=1&curr=rub&dest=-1257786®ions=80,38,83,4,64,33,68,70,30,40,86,75,69,22,1,31,66,110,48,71,114&spp=0",br=async t=>{let{data:n}=await oe.get(`https://catalog-ads.wildberries.ru/api/v5/search?keyword=${t}`);if(!n.adverts)return null;const s=[];n.adverts.forEach(h=>s.push(h.id));let r=localStorage.getItem("geoData")||vr;const{data:l}=await oe.get(`/api/wp/clist/?${r}&nm=${s.join(";")}`);if(!l)return null;const a=l.data.products.map(h=>(h.deliveryHours=h.time1+h.time2,h.nmId=h.id,h));return{advData:n,advGoods:a}};async function _r(t){const{data:n}=await oe.get("https://static-basket-01.wb.ru/vol0/data/subject-base.json");let s=[];const r=(l,a)=>{l.forEach(d=>{if(d.id==a){const h={id:d.id,subj_name:d.name};s.push(h)}else d.childs&&r(d.childs,a)})};return t.forEach(l=>r(n,l)),s}const Sr=function(t,n,s){const{advData:r}=t;r.pages.sort((a,d)=>a.page-d.page);const l={};return s=Cr(s,r),r.pages.forEach(a=>{let d=s.splice(0,a.positions.length);d.forEach((h,o)=>{const f=r.adverts.find(p=>p.id===h.nmId);wr(h,f,a.positions[o],a.page)}),a.page===1&&(d=n.concat(d)),d.sort((h,o)=>h.advStatFields.position-o.advStatFields.position),l[a.page]=d}),l},wr=function(t,n,s,r=1){var l,a,d,h;t.advStatFields={advertId:n.advertId,position:s,cpm:(l=(a=t.advStatFields)===null||a===void 0?void 0:a.cpm)!==null&&l!==void 0?l:n.cpm,subjectId:t.subjectId,brandId:t.brandCod,kindId:t.kindId,page:r,mk_cpmweight:(d=(h=t.advStatFields)===null||h===void 0?void 0:h.mk_cpmweight)!==null&&d!==void 0?d:0,mk_deliveryweight:(d=(h=t.advStatFields)===null||h===void 0?void 0:h.mk_deliveryweight)!==null&&d!==void 0?d:0,totalWeight:(d=(h=t.advStatFields)===null||h===void 0?void 0:h.totalWeight)!==null&&d!==void 0?d:0,cpmRatio:t.advStatFields.cpmRatio,deliveryRatio:t.advStatFields.deliveryRatio}},Cr=function(t,n){var s,r;if((s=n.adverts)===null||s===void 0||!s.length||t==null||!t.length)return[];const l=n.adverts.reduce((d,h)=>d.set(h.id,h),new Map);if((r=n.prioritySubjects)!==null&&r!==void 0&&r.length)return kr(t,n,l);const a=wn(t,n.adverts.length);return Cn(a,n,l)},wn=function(t,n){return{advertsCount:n??0,products:t??[]}},kr=function(t,n,s){const r=t.reduce((d,h)=>d.set(h.nmId,h),new Map),l=n.adverts.reduce((d,h)=>{var o;const f=h.subject,p=r.get(h.id),c=(o=d.get(f))!==null&&o!==void 0?o:wn();return c.advertsCount++,p&&c.products.push(p),d.set(f,c)},new Map),a=[];for(let d=0;do.advStatFields.totalWeight==f.advStatFields.totalWeight&&f.advStatFields.cpm!=o.advStatFields.cpm?f.advStatFields.cpm-o.advStatFields.cpm:f.advStatFields.totalWeight-o.advStatFields.totalWeight),r},Fr=function(t,n,s){const{cpms:r,deliveries:l}=t.reduce((o,f)=>{if(!f)return;const p=n.get(f.nmId);return o.deliveries.add(f.deliveryHours),o.cpms.add(p.cpm),o},{cpms:new Set,deliveries:new Set}),a=1/s.advertsCount;function d(o){let f=1;return o.reduce((p,c)=>p.has(c)?p:(p.size>0&&(f-=a),p.set(c,f)),new Map)}function h(o,f){const p=Array.from(o);return p.sort(f),p}return{weightMapCpm:d(h(r,(o,f)=>f-o)),weightMapDelivery:d(h(l,(o,f)=>o-f))}},Rr=function(t){var n,s;let r=.6666666666666666,l=1/3;if(t!=null&&(n=t.sortWeights)!==null&&n!==void 0&&n.cpm&&t!=null&&(s=t.sortWeights)!==null&&s!==void 0&&s.delivery){const a=t.sortWeights.cpm+t.sortWeights.delivery;a&&(r=t.sortWeights.cpm/a,l=t.sortWeights.delivery/a)}return{cpmRatio:r,deliveryRatio:l}};function Dr(t,n){const s=new Map;t.advData.adverts.forEach(f=>{s.has(f.id)||s.set(f.id,f)});const r=Sr(t,[],t.advGoods),l=[];let a=0,d=0,h=0;Object.entries(r).forEach((f,p)=>{f[1].forEach(c=>{const u=++a;let m;n&&(m=n.find(j=>j.id===c.advStatFields.subjectId)),d||(d=c.advStatFields.cpmRatio),h||(h=c.advStatFields.deliveryRatio);const y={brand:c.brand,deliveryHours:c.deliveryHours,id:c.cod1S||c.id,n:u,page:c.advStatFields.page,pl:a,position:c.advStatFields.position,subj_name:m?m.subj_name:"",cpm:c.advStatFields.cpm,cpmWeight:c.advStatFields.mk_cpmweight.toFixed(3),deliveryWeight:c.advStatFields.mk_deliveryweight.toFixed(3),totalWeight:c.advStatFields.totalWeight.toFixed(3),subject:"",name:c.name};l.push(y)})});const o={cpm:"",delivery:"",cpmPercentages:null,deliveryPercentages:null};return t.advData.sortWeights&&(o.cpm=`${t.advData.sortWeights.cpm}/${t.advData.sortWeights.cpm+t.advData.sortWeights.delivery}`,o.delivery=`${t.advData.sortWeights.delivery}/${t.advData.sortWeights.cpm+t.advData.sortWeights.delivery}`),o.cpmPercentages=d*100,o.deliveryPercentages=h*100,{data:l,ratio:o}}async function Ir(t){const n=await br(t);if(n===null)return new Promise((l,a)=>l([]));const s=await _r(n.advData.prioritySubjects),r=Dr(n,s);return new Promise((l,a)=>l(r.data))}var je=(t=>(t[t.Small=360]="Small",t[t.Mobile=414]="Mobile",t[t.Tablet=768]="Tablet",t[t.Medium=1280]="Medium",t[t.Laptop=1366]="Laptop",t[t.Large=1920]="Large",t))(je||{});const Ue=i.createContext({resolution:1920}),zt=()=>document.body.clientWidth<=360?360:document.body.clientWidth<=414?414:document.body.clientWidth<=768?768:document.body.clientWidth<=1280?1280:document.body.clientWidth<=1366?1366:1920;function Tr({children:t}){const[n,s]=i.useState(document.body.clientWidth);return i.useEffect(()=>{window.addEventListener("resize",()=>s(zt())),s(zt())},[]),e.jsx(Ue.Provider,{value:{resolution:n},children:t})}function kn(t,n=246,s=328){return`//basket-${Er(Math.floor(t/1e5))}.wb.ru/vol${Math.floor(t/1e5)}/part${Math.floor(t/1e3)}/${t}/images/c${n}x${s}/1.jpg`}function Er(t){return t>=0&&t<=143?"01":t>=144&&t<=287?"02":t>=288&&t<=431?"03":t>=432&&t<=719?"04":t>=720&&t<=1007?"05":t>=1008&&t<=1061?"06":t>=1062&&t<=1115?"07":t>=1116&&t<=1169?"08":t>=1170&&t<=1313?"09":t>=1314&&t<=1601?"10":t>=1602&&t<=1655?"11":"12"}function Lr({rows:t,skeleton:n}){return n?e.jsx("div",{children:[...Array(5)].map((s,r)=>e.jsxs("div",{style:{border:"1px solid #d5d5d5",padding:"8px",borderRadius:"10px",marginTop:r>0?"15px":0},children:[e.jsx(X.Input,{active:!0,block:!0,style:{height:15,width:"100%"}}),e.jsxs("div",{style:{display:"flex",marginTop:"4px",width:"100%"},children:[e.jsx(X.Image,{active:!0,style:{height:80,width:60,marginRight:"4px"}}),e.jsxs("div",{style:{width:"100%"},children:[e.jsx(X.Input,{active:!0,block:!0,style:{height:15,width:"100%"}}),e.jsx(X.Input,{active:!0,block:!0,style:{height:15,width:"100%",marginTop:"4px"}}),e.jsx(X.Input,{active:!0,block:!0,style:{height:15,width:"100%",marginTop:"4px"}})]})]})]},r))}):t.length?e.jsx("div",{children:t.map(s=>e.jsxs("div",{style:{border:"1px solid #d5d5d5",padding:"8px",borderRadius:"10px",marginTop:"15px"},children:[e.jsxs("div",{style:{display:"flex"},children:[e.jsx("span",{style:{marginRight:"5px",fontSize:"12px"},children:s.n}),e.jsx("span",{style:{fontSize:"12px"},children:s.name})]}),e.jsxs("div",{style:{display:"flex",width:"100%",marginTop:"4px"},children:[e.jsx("a",{href:`https://www.wildberries.ru/catalog/${s.id}/detail.aspx`,target:"_blank",style:{height:"80px",marginRight:"5px"},children:e.jsx("img",{height:"80px",src:`${kn(s.id)}`,style:{borderRadius:"5px"}})}),e.jsxs("div",{style:{marginRight:"16px",flexGrow:1},children:[e.jsxs("div",{style:{fontSize:"12px"},children:["Артикул: ",s.id]}),e.jsxs("div",{style:{fontSize:"12px"},children:["Бренд: ",s.brand]}),e.jsxs("div",{style:{fontSize:"12px"},children:["Категория: ",s.subj_name]})]}),e.jsxs("div",{style:{minWidth:"90px"},children:[e.jsxs("div",{style:{fontSize:"12px"},children:["Ставка: ",s.cpm," ₽"]}),e.jsxs("div",{style:{fontSize:"12px"},children:["Доставка: ",s.deliveryHours," ч."]})]})]})]},s.id))}):e.jsx("div",{style:{width:"100%",textAlign:"center"},children:"Пусто..."})}const $r=[{title:"№",dataIndex:"n",key:"n",align:"center",render:t=>pe(t)},{title:"",key:"img",align:"center",render:(t,n)=>e.jsx("a",{href:`https://www.wildberries.ru/catalog/${n.id}/detail.aspx`,target:"_blank",children:e.jsx("img",{height:"22px",src:`${kn(n.id)}`})})},{title:"Артикул",key:"id",align:"center",render:(t,n)=>e.jsx("a",{href:`https://www.wildberries.ru/catalog/${n.id}/detail.aspx`,target:"_blank",children:n.id})},{title:"Бренд",dataIndex:"brand",key:"brand",align:"center"},{title:"Категория",dataIndex:"subj_name",key:"subj_name",align:"center"},{title:"Ставка",key:"cpm",align:"center",render:(t,n)=>`${pe(n.cpm)} ₽`},{title:"Вес ставки",key:"cpmWeight",align:"center",render:(t,n)=>pe(n.cpmWeight)},{title:"Доставка",key:"deliveryHours",align:"center",render:(t,n)=>`${pe(n.deliveryHours)} ч.`},{title:"Вес доставки",key:"deliveryWeight",align:"center",render:(t,n)=>pe(n.deliveryWeight)},{title:"Общий вес",key:"totalWeight",align:"center",render:(t,n)=>pe(n.totalWeight)},{title:"Место",key:"pl",align:"center",render:(t,n)=>pe(n.pl)},{title:"Страница",key:"page",align:"center",render:(t,n)=>pe(n.page)},{title:"Позиция",key:"position",align:"center",render:(t,n)=>pe(n.position)}];function Mr({rows:t,skeleton:n}){return n?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[...Array(8)].map((s,r)=>e.jsx(X.Input,{active:!0,block:!0,style:{height:32,width:"100%"}},r))}):e.jsx(Ie,{columns:$r,dataSource:t||[],rowKey:"id",size:"small",pagination:!1,locale:{emptyText:"Пусто..."}})}function zr({rows:t,skeleton:n}){const{resolution:s}=i.useContext(Ue);return e.jsx(e.Fragment,{children:s<=je.Mobile?e.jsx(Lr,{skeleton:n,rows:t}):e.jsx(Mr,{skeleton:n,rows:t})})}const Pr=async t=>{const{data:n}=await oe.get(`https://search.wb.ru/suggests/api/v3/hint?query=${t}&gender=common&locale=ru&lang=ru`);let s=[];return n.forEach(r=>{r.type==="suggest"&&s.push({label:r.name})}),new Promise((r,l)=>r(s))};function Wr(){const[t,n]=i.useState(""),[s,r]=i.useState(!1),[l,a]=_t("",300),[d,h]=i.useState([]),[o,f]=i.useState([]),p=u=>{n(u),u&&(a(u),r(!0))};i.useEffect(()=>{if(!t){h([]),f([]),r(!1);return}Ir(t).then(u=>{h(u),r(!1)}),Pr(t).then(u=>{Array.isArray(u)&&f(u)})},[l]);const c=o.map(u=>({value:u.label,label:u.label}));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(R.Title,{level:4,style:{margin:0},children:"Аукцион поиска"}),e.jsx("div",{children:e.jsx(Jt,{style:{width:"100%"},options:c,value:t,onSelect:u=>p(u),onSearch:u=>p(u),children:e.jsx(J.Search,{placeholder:"Введите текст для поиска",size:"large"})})}),e.jsx("div",{children:e.jsx(zr,{rows:d,skeleton:s})})]})}const Ar="mkeeper_direct_bot";function Hr(){const{profile:t}=xe(),[n,s]=i.useState(null),[r,l]=i.useState(!1);if(i.useEffect(()=>{t.tg_id||(l(!0),Y("user/tg-link-code").then(d=>{s(d.data.code)}).finally(()=>{l(!1)}))},[t.tg_id]),r||!n)return e.jsx(we,{});const a=`https://t.me/${Ar}?start=tg_mk_${n}`;return e.jsxs("div",{children:[e.jsx(R.Text,{type:"secondary",style:{display:"block",marginBottom:16},children:"Отсканируйте QR-код или перейдите по ссылке для привязки аккаунта"}),e.jsxs(es,{align:"center",gap:24,wrap:"wrap",children:[e.jsx(ts,{value:a,size:160,fgColor:x.text,level:"M"}),e.jsx(R.Link,{href:a,target:"_blank",children:a})]})]})}function Nr({onConfirm:t,title:n,button:s,children:r}){const[l,a]=i.useState(!1),d=()=>{a(!0)},h=()=>{a(!1)},o=()=>{t&&t(),a(!1)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:d,className:"hoverable-icon",children:s}),e.jsxs(Te,{open:l,onCancel:h,title:n,footer:null,closeIcon:e.jsx(Sn,{}),width:455,styles:{body:{padding:"16px 16px 0"}},children:[r&&e.jsx("div",{style:{marginBottom:16},children:r}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(Ce,{onClick:o,variant:"outlined",color:"error",sx:{width:"100%"},children:"Подтвердить"}),e.jsx(Ce,{onClick:h,variant:"outlined",color:"secondary",sx:{width:"100%"},children:"Отмена"})]})]})]})}const Or=30,ze=44,Br=30,Pe=40,qr="_textCell_j8spt_1",Pt={textCell:qr},ae=({value:t,textAlignment:n="left",link:s,routerLink:r,afterIcon:l})=>{let a=t;return r?a=e.jsx(se,{to:r,children:t}):s&&(a=e.jsx("a",{href:s,target:"_blank",children:t})),e.jsxs("div",{className:Pt.textCell,style:{textAlign:n},children:[e.jsx("span",{className:Pt.text,style:{fontSize:"16px",lineHeight:1.4,color:"#383540"},children:a}),l||""]})},Gr="_headerContainer_1o3pk_1",Ur="_customHeaderLabel_1o3pk_19",Wt={headerContainer:Gr,customHeaderLabel:Ur},Vr=({size:t=16,color:n,direction:s="right"})=>{const r={up:"0deg",right:"90deg",down:"180deg"},l=n||x.dark[500];return e.jsx("svg",{style:{transform:`rotate(${r[s]})`},xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 16 16",fill:"none",children:e.jsx("path",{d:"M8.61193 13.5L7.39003 13.5L7.40317 5.84127L7.16667 6.06614L4.36813 8.89683L3.50098 8.05026L7.99441 3.5L12.501 8.03704L11.6338 8.89682L8.59879 5.82804L8.61193 13.5Z",fill:l})})},Fe=t=>{const[n,s]=i.useState(!1),[r,l]=i.useState(!1),a=()=>{const h=t.column.getSort();s(h==="asc"),l(h==="desc")},d=h=>{const o=n?"desc":"asc";t.setSort(o,h.shiftKey)};return i.useEffect(()=>{t.column.addEventListener("sortChanged",a),a()},[]),e.jsxs("div",{className:Wt.headerContainer,onClick:d,onTouchEnd:d,style:t.enableSorting?{cursor:"pointer"}:{},children:[e.jsx("span",{className:Wt.customHeaderLabel,style:{fontSize:"16px",lineHeight:1.4,color:x.greyF[700],...t.wrapText?{whiteSpace:"normal"}:{}},children:t.displayName}),t.enableSorting?e.jsx("span",{style:{minWidth:"16px",maxWidth:"16px",minHeight:"16px",maxHeight:"16px"},children:e.jsx(Vr,{direction:r?"down":"up",color:n||r?x.blue[500]:x.greyF[700]})}):""]})},Kr=()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[e.jsxs("g",{clipPath:"url(#clip0_7578_23038)",children:[e.jsx("mask",{id:"mask0_7578_23038",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"24",height:"24",children:e.jsx("rect",{width:"24",height:"24",fill:"#D9D9D9"})}),e.jsx("g",{mask:"url(#mask0_7578_23038)",children:e.jsx("path",{d:"M7 21C6.45 21 5.97917 20.8042 5.5875 20.4125C5.19583 20.0208 5 19.55 5 19V6H4V4H9V3H15V4H20V6H19V19C19 19.55 18.8042 20.0208 18.4125 20.4125C18.0208 20.8042 17.55 21 17 21H7ZM9 17H11V8H9V17ZM13 17H15V8H13V17Z",fill:x.redPale[400]})})]}),e.jsx("defs",{children:e.jsx("clipPath",{id:"clip0_7578_23038",children:e.jsx("rect",{width:"24",height:"24",fill:"white"})})})]}),Re=({message:t})=>e.jsx("div",{style:{padding:"20px",color:"#666666",fontSize:"16px",pointerEvents:"all",lineHeight:"1.5",display:"block"},children:e.jsx("span",{children:t||"Нет данных"})}),At="user/device";function Zr(){const[t,n]=i.useState(!0),[s,r]=i.useState([]),{showRequestError:l}=B(),a=()=>{n(!0),V(At).then(f=>{r(f.data)}).catch(f=>{l(f)}).finally(()=>n(!1))};i.useEffect(()=>{a()},[]);const d=f=>f?new Date(f).toLocaleString("ru-RU",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"—",h=f=>{xs(`${At}/${f}`).then(p=>{a()})};if(t)return e.jsx(_e,{count:2});const o=[{headerName:"Ключ активации",field:"key",cellRenderer:f=>e.jsx(ae,{value:f.value})},{headerName:"User Agent",field:"user_agent",cellRenderer:f=>e.jsx(ae,{value:f.value})},{headerName:"Дата использования",field:"last_check",cellRenderer:f=>e.jsx(ae,{value:d(f.value)})},{headerName:"Дата активации",field:"activation_date",cellRenderer:f=>e.jsx(ae,{value:d(f.value),afterIcon:e.jsx("div",{style:{height:"24px",marginLeft:"auto"},children:e.jsx(Nr,{button:e.jsx(Kr,{}),title:"Деактивировать устройство?",onConfirm:()=>h(f.data.dev_num)})})})}];return e.jsx(e.Fragment,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Br,headerHeight:Or,rowData:s,columnDefs:o,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!1,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe},onFirstDataRendered:f=>f.api.sizeColumnsToFit(),noRowsOverlayComponent:Re})})})})}function Fn(){const{profile:t}=xe();return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:24},children:[e.jsx(R.Title,{level:5,style:{margin:0},children:"Устройства"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:16},children:e.jsx(Zr,{})})]})}function Rn({hidden:t}){const n=Je(),{profile:s}=xe(),{showRequestError:r,showError:l}=B(),[a,d]=i.useState("");return i.useEffect(()=>{s.auth?Y("user/device/new").then(h=>{var o;(o=h.data)!=null&&o.key?d(h.data.key):(l("Нет свободных активаций. Отвяжите одно устройство или повысьте тариф"),n("/"))}).catch(h=>{}):n("/auth/login")},[]),e.jsxs("div",{children:[!t&&e.jsx(we,{}),e.jsx("input",{type:"hidden",id:"new-device-key",value:a})]})}function Se({label:t,value:n}){return e.jsxs("div",{style:{display:"flex",gap:16,paddingBlock:10},children:[e.jsx(R.Text,{style:{minWidth:180,color:"#888"},children:t}),e.jsx(R.Text,{children:n})]})}function ht({children:t}){return e.jsx(R.Title,{level:5,style:{margin:0},children:t})}function Yr({onDevicesClick:t}){var y;const{profile:n}=xe(),[s,r]=i.useState(void 0),[l,a]=i.useState(!0),[d,h]=i.useState(!1),{showRequestError:o,showError:f,showMessage:p}=B();if(i.useEffect(()=>{n.tg_id&&h(!1)},[n.tg_id]),i.useEffect(()=>{a(!0),V("user/license").then(j=>{r(j.data)}).catch(j=>o(j)).finally(()=>a(!1))},[]),l)return e.jsx(_e,{count:4});const c=s==null?void 0:s[0],u=c&&new Date(c.action_date).getFullYear()>=2020,m=u?new Date(c.action_date).toLocaleDateString("ru-RU"):null;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",maxWidth:560},children:[e.jsx(ht,{children:"Общая информация"}),e.jsx(ve,{style:{marginTop:8,marginBottom:0}}),n.wb_id&&e.jsx(Se,{label:"WB ID:",value:n.wb_id}),e.jsx(Se,{label:"Telegram:",value:n.tg_id?e.jsx(R.Text,{children:n.tg_username?`${n.tg_username} (${n.tg_id})`:n.tg_id}):e.jsx(R.Link,{onClick:()=>h(!0),children:"Привязать"})}),e.jsx(Te,{open:d,onCancel:()=>h(!1),title:"Привязка Telegram",footer:null,width:480,children:e.jsx("div",{style:{paddingTop:8},children:e.jsx(Hr,{})})}),e.jsxs("div",{style:{marginTop:24},children:[e.jsx(ht,{children:"Информация о тарифе"}),e.jsx(ve,{style:{marginTop:8,marginBottom:0}}),u?e.jsxs(e.Fragment,{children:[e.jsx(Se,{label:"Тариф:",value:((y=c.tariff)==null?void 0:y.name)??"—"}),e.jsx(Se,{label:"Лицензионный ключ:",value:c.key}),e.jsx(Se,{label:"Действует до:",value:e.jsx(R.Text,{style:new Date(c.action_date)0&&e.jsx(Se,{label:"Подключено устройств:",value:e.jsxs(R.Link,{onClick:t,children:[c.devices_used??0," из ",c.devices]})}),e.jsxs("div",{style:{marginTop:16,display:"flex",gap:8},children:[e.jsx(Ye,{variant:"contained",licenseKey:c.key,children:"Продлить тариф"}),e.jsx(Ye,{disabled:!0,variant:"outlined",licenseKey:c.key,children:"Сменить тариф"}),e.jsx(Ce,{disabled:!0,variant:"outlined",children:"История оплат"})]})]}):e.jsx("div",{style:{paddingTop:12},children:e.jsx(Ye,{children:"Активировать подписку"})})]}),u&&c.autopay&&e.jsxs("div",{style:{marginTop:24},children:[e.jsx(ht,{children:"Автоплатёж"}),e.jsx(ve,{style:{marginTop:8,marginBottom:0}}),c.next_pay_at&&e.jsx(Se,{label:"Следующее списание:",value:new Date(c.next_pay_at).toLocaleDateString("ru-RU")}),c.next_pay_amount!=null&&e.jsx(Se,{label:"Сумма списания:",value:`${c.next_pay_amount.toLocaleString("ru-RU")} ₽`}),c.autopay&&e.jsxs("div",{style:{paddingTop:10},children:[e.jsx(R.Text,{children:"Автоплатёж подключён. Вы можете "}),e.jsx(ns,{title:"Отключить автоплатёж?",description:"Автоплатёж будет отключён. Текущий период останется активным.",okText:"Отключить",cancelText:"Назад",okButtonProps:{danger:!0},onConfirm:()=>{Y("user/cancel-payment",{}).then(j=>{var b;(b=j.data)!=null&&b.message&&p(j.data.message),r(k=>k.map((_,w)=>w===0?{..._,autopay:!1,next_pay_at:null}:_))}).catch(j=>{var b,k;f(((k=(b=j.response)==null?void 0:b.data)==null?void 0:k.error)??ct(j))})},children:e.jsx(R.Link,{children:"Отключить автоплатёж"})})]})]})]})}function Qr(){const{profile:t}=xe(),[n]=Rt(),[s,r]=i.useState("general"),l=n.get("auth")==="success";if(t.auth===void 0)return e.jsx(we,{});if(t.auth===!1)return e.jsx(dt,{});const a=[{key:"general",label:"Общее",children:e.jsx(Yr,{onDevicesClick:()=>r("devices")})},{key:"devices",label:"Устройства",children:e.jsx(Fn,{})},{key:"shops",label:"Магазины",children:null},{key:"employees",label:"Сотрудники",children:null},{key:"referral",label:"Партнёрская программа",children:null}];return e.jsxs("div",{style:{maxWidth:900},children:[e.jsx(R.Title,{level:4,style:{margin:0,marginBottom:24},children:"Профиль"}),e.jsx(Ft,{items:a,activeKey:s,onChange:r}),l&&e.jsx(Rn,{hidden:!0})]})}const Xr=()=>{const{clearProfile:t}=xe(),n=Je(),s=()=>{qe.logout().then(()=>{}).catch(r=>console.log("wb logout error:",r)),he("user/logout").then(()=>{t(),n("/")}).catch(r=>{})};return i.useEffect(()=>{s()},[s]),e.jsx("div",{className:"auth-page",children:"Выход..."})},Jr="_numberCell_1xqpf_1",ei="_number_1xqpf_1",ti="_tag_1xqpf_17",Ae={numberCell:Jr,number:ei,tag:ti},U=({value:t,digits:n,cellStyle:s,textAlignment:r="end",tag:l=!1,icon:a=!1,prefix:d=!1,suffix:h=!1})=>{const o=f=>isNaN(f)||!isFinite(f)?"--":n!==void 0?f.toLocaleString("ru-RU",{minimumFractionDigits:n,maximumFractionDigits:n}):f.toLocaleString("ru-RU");return e.jsxs("div",{className:Ae.numberCell,style:{...s,justifyContent:r},children:[l&&e.jsx("div",{className:Ae.tag,children:l}),a&&e.jsx("div",{className:Ae.icon,children:a}),e.jsxs("span",{className:Ae.number,style:{fontSize:"16px",lineHeight:1.4,color:"#383540"},children:[d&&t!=null&&e.jsx("div",{className:Ae.prefix,children:d}),o(Number(t)),h&&t!=null&&e.jsx("div",{className:Ae.suffix,children:h})]})]})},ni="_container_10jp5_1",si="_input_10jp5_10",ft={container:ni,input:si},ri=500,De=i.forwardRef((t,n)=>{const[s,r]=i.useState(""),[l,a]=i.useState(""),d=i.useRef(null);i.useImperativeHandle(n,()=>({onParentModelChanged(c){c||(r(""),a(""))}}));const h=(c,u)=>{const m=c?Number(c):null,y=u?Number(u):null;m!=null&&y!=null?t.onModelChange({type:"inRange",filter:m,filterTo:y}):m!=null?t.onModelChange({type:"greaterThanOrEqual",filter:m}):y!=null?t.onModelChange({type:"lessThanOrEqual",filter:y}):t.onModelChange(null)},o=(c,u)=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{h(c,u)},ri)},f=c=>{const u=c.target.value;r(u),o(u,l)},p=c=>{const u=c.target.value;a(u),o(s,u)};return e.jsxs("div",{className:ft.container,children:[e.jsx("input",{className:ft.input,type:"number",placeholder:"От",value:s,onChange:f}),e.jsx("input",{className:ft.input,type:"number",placeholder:"До",value:l,onChange:p})]})});De.displayName="RangeFloatingFilter";Ee.setLicenseKey("key");Le.registerModules([$e]);const ii=64,li=10,ai=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),Qe=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(ai,{}):t(n)},oi={category_name:{text:"category"},subject_name:{text:"subject_name"},revenue:{min:"revenue_min",max:"revenue_max"},revenue_change_pc:{min:"revenue_change_pc_min",max:"revenue_change_pc_max"},cards_count:{min:"cards_count_min",max:"cards_count_max"},cards_count_change_pc:{min:"cards_count_change_pc_min",max:"cards_count_change_pc_max"},cards_with_orders_count:{min:"cards_with_orders_count_min",max:"cards_with_orders_count_max"},cards_with_orders_count_change_pc:{min:"cards_with_orders_count_change_pc_min",max:"cards_with_orders_count_change_pc_max"},suppliers:{min:"suppliers_min",max:"suppliers_max"},suppliers_change_pc:{min:"suppliers_change_pc_min",max:"suppliers_change_pc_max"},suppliers_with_sells:{min:"suppliers_with_sells_min",max:"suppliers_with_sells_max"},suppliers_with_sells_change_pc:{min:"suppliers_with_sells_change_pc_min",max:"suppliers_with_sells_change_pc_max"},redemption_pc:{min:"redemption_pc_min",max:"redemption_pc_max"},redemption_pc_change_pc:{min:"redemption_pc_change_pc_min",max:"redemption_pc_change_pc_max"},buyouts_qty:{min:"buyouts_qty_min",max:"buyouts_qty_max"},buyouts_qty_change_pc:{min:"buyouts_qty_change_pc_min",max:"buyouts_qty_change_pc_max"},orders_qty:{min:"orders_qty_min",max:"orders_qty_max"},orders_qty_change_pc:{min:"orders_qty_change_pc_min",max:"orders_qty_change_pc_max"},orders_rub:{min:"orders_rub_min",max:"orders_rub_max"},orders_rub_change_pc:{min:"orders_rub_change_pc_min",max:"orders_rub_change_pc_max"},buyouts_rub:{min:"buyouts_rub_min",max:"buyouts_rub_max"},buyouts_rub_change_pc:{min:"buyouts_rub_change_pc_min",max:"buyouts_rub_change_pc_max"},avg_check:{min:"avg_check_min",max:"avg_check_max"},avg_check_change_pc:{min:"avg_check_change_pc_min",max:"avg_check_change_pc_max"},weekly_turnover_days:{min:"weekly_turnover_days_min",max:"weekly_turnover_days_max"},weekly_turnover_days_change_pc:{min:"weekly_turnover_days_change_pc_min",max:"weekly_turnover_days_change_pc_max"},monopolization_pc:{min:"monopolization_pc_min",max:"monopolization_pc_max"},monopolization_pc_change_pc:{min:"monopolization_pc_change_pc_min",max:"monopolization_pc_change_pc_max"},remaining_count:{min:"remaining_count_min",max:"remaining_count_max"},remaining_count_change_pc:{min:"remaining_count_change_pc_min",max:"remaining_count_change_pc_max"},avg_rating:{min:"avg_rating_min",max:"avg_rating_max"},avg_rating_change_pc:{min:"avg_rating_change_pc_min",max:"avg_rating_change_pc_max"}};function ci(t){const n={};for(const[s,r]of Object.entries(t)){const l=oi[s];l&&("text"in l?r.filter&&(n[l.text]=r.filter):r.type==="inRange"?(r.filter!=null&&(n[l.min]=String(r.filter)),r.filterTo!=null&&(n[l.max]=String(r.filterTo))):r.type==="greaterThanOrEqual"?r.filter!=null&&(n[l.min]=String(r.filter)):r.type==="lessThanOrEqual"&&r.filter!=null&&(n[l.max]=String(r.filter)))}return n}const ie=(t,n,s={})=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:130,cellRenderer:Qe(r=>e.jsx(U,{value:r.value,...s}))}),di=t=>t==null||isNaN(t)||!isFinite(t)?"--":t.toLocaleString("ru-RU"),re=(t,n)=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:170,cellRenderer:Qe(s=>{const r=s.value;if(r==null)return e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",width:"100%",height:"100%"},children:"--"});const l=r>=0,a=l?x.green[500]:x.red[500],d=l?Ct:kt;return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:4,width:"100%",height:"100%",color:a,fontSize:16,lineHeight:1.4,whiteSpace:"nowrap"},children:[e.jsx(d,{style:{fontSize:10}}),di(r),"%"]})})}),vt=[{headerName:"Категория",field:"category_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:200,cellRenderer:Qe(t=>e.jsx(ae,{value:t.value}))},{headerName:"Предмет",field:"subject_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:150,cellRenderer:Qe(t=>e.jsx(ae,{value:t.value,routerLink:`/external-analytics/niche-analysis/${t.data.subject}`}))},ie("Выручка","revenue",{suffix:" ₽"}),re("Δ Выручка, %","revenue_change_pc"),ie("Карточек товаров","cards_count"),re("Δ Карточек товаров, %","cards_count_change_pc"),{...ie("Карточек с заказами","cards_with_orders_count"),minWidth:140},{...re("Δ Карточек с заказами, %","cards_with_orders_count_change_pc"),minWidth:160},{...ie("Продавцы","suppliers"),minWidth:110},re("Δ Продавцы, %","suppliers_change_pc"),{...ie("Продавцы с заказами","suppliers_with_sells"),minWidth:140},{...re("Δ Продавцы с заказами, %","suppliers_with_sells_change_pc"),minWidth:160},{...ie("% выкупа","redemption_pc",{suffix:"%"}),minWidth:110},re("Δ % выкупа, %","redemption_pc_change_pc"),ie("Заказы, шт","orders_qty"),re("Δ Заказы шт, %","orders_qty_change_pc"),ie("Заказы, ₽","orders_rub",{suffix:" ₽"}),re("Δ Заказы ₽, %","orders_rub_change_pc"),ie("Выкупы, шт","buyouts_qty"),re("Δ Выкупы шт, %","buyouts_qty_change_pc"),ie("Выкупы, ₽","buyouts_rub",{suffix:" ₽"}),re("Δ Выкупы ₽, %","buyouts_rub_change_pc"),{...ie("Средний чек","avg_check",{suffix:" ₽"}),minWidth:120},re("Δ Средний чек, %","avg_check_change_pc"),ie("Оборачиваемость","weekly_turnover_days"),re("Δ Оборачиваемость, %","weekly_turnover_days_change_pc"),ie("Монополизация","monopolization_pc"),re("Δ Монополизация, %","monopolization_pc_change_pc"),{...ie("Среднее кол-во остатков","remaining_count"),minWidth:160},{...re("Δ Среднее кол-во остатков, %","remaining_count_change_pc"),minWidth:180},{headerName:"Средний рейтинг",field:"avg_rating",filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:130,cellRenderer:Qe(t=>e.jsx(U,{value:t.value,digits:1,icon:e.jsx(ss,{style:{color:x.primary[500],fontSize:14}})}))},re("Δ Средний рейтинг, %","avg_rating_change_pc")],Ht=vt.map(t=>({field:t.field,headerName:t.headerName})),ui=t=>Array.from({length:t},(n,s)=>({_id:s}));function pi({rowData:t,loading:n,onFilterChanged:s,onSortChanged:r,hiddenColumns:l=[]}){const a=i.useRef(li);!n&&t.length&&(a.current=t.length);const d=i.useMemo(()=>n?ui(a.current):t,[n,t]),h=i.useMemo(()=>({loading:n}),[n]),o=i.useMemo(()=>l.length?vt.filter(c=>!l.includes(c.field)):vt,[l]),f=i.useCallback(c=>{if(!s)return;const u=c.api.getFilterModel(),m=ci(u);s(m)},[s]),p=i.useCallback(c=>{if(!r)return;const u=c.api.getColumnState().filter(m=>m.sort).map(m=>m.sort==="desc"?`-${m.colId}`:m.colId);r(u.length?u.join(","):null)},[r]);return e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Pe,headerHeight:ze,floatingFiltersHeight:ii,rowData:d,columnDefs:o,context:h,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!0,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe,headerComponentParams:{enableSorting:!0,wrapText:!0}},onGridReady:c=>{c.api.sizeColumnsToFit()},onGridSizeChanged:c=>{c.api.sizeColumnsToFit()},onFilterChanged:f,onSortChanged:p,noRowsOverlayComponent:Re})})}function Dn(t,n){const[s,r]=i.useState(()=>{try{const p=localStorage.getItem(t);return p?JSON.parse(p):[]}catch{return[]}}),[l,a]=i.useState(!1),d=i.useCallback(()=>a(!0),[]),h=i.useCallback(()=>a(!1),[]),o=i.useCallback((p,c)=>{r(u=>{const m=c?u.filter(y=>y!==p):[...u,p];return localStorage.setItem(t,JSON.stringify(m)),m})},[t]),f=i.useMemo(()=>new Set(n.map(p=>p.field).filter(p=>!s.includes(p))),[n,s]);return{hiddenColumns:s,visibleColumns:f,open:l,openModal:d,closeModal:h,toggleColumn:o}}function In({columns:t,hiddenColumns:n,open:s,onClose:r,onToggle:l}){return e.jsx(Te,{open:s,onCancel:r,title:"Настройка колонок",footer:null,width:420,children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,maxHeight:480,overflowY:"auto"},children:t.map(a=>e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 0"},children:[e.jsx("span",{style:{fontSize:14},children:a.headerName}),e.jsx(rs,{size:"small",checked:!n.includes(a.field),onChange:d=>l(a.field,d)})]},a.field))})})}function Tn({onClick:t}){return e.jsx($,{icon:e.jsx(is,{}),onClick:t,children:"Настроить колонки"})}const{Title:hi}=R,fi="wbstat/external_analytics",xi=[{label:"Неделя",value:"week"},{label:"Месяц",value:"month"},{label:"Квартал",value:"quarter"}];function gi(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState({}),[d,h]=i.useState(null),[o,f]=i.useState("month"),{showRequestError:p}=B(),c=Dn("niche_analysis_columns",Ht),u=i.useCallback(j=>{r(!0),le(`${fi}/`,{params:j}).then(b=>{n(b.data.results)}).catch(b=>{p(b)}).finally(()=>{r(!1)})},[p]);i.useEffect(()=>{const j={...l,period:o,page_size:100};d&&(j.ordering=d),u(j)},[l,d,o]);const m=i.useCallback(j=>{a(j)},[]),y=i.useCallback(j=>{h(j)},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(hi,{level:3,style:{margin:0},children:"Анализ ниш"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap",justifyContent:"space-between"},children:[e.jsx(fe.Group,{options:xi,value:o,onChange:j=>f(j.target.value),optionType:"button",buttonStyle:"solid"}),e.jsx(Tn,{onClick:c.openModal})]}),e.jsx(In,{columns:Ht,hiddenColumns:c.hiddenColumns,open:c.open,onClose:c.closeModal,onToggle:c.toggleColumn}),e.jsx(pi,{rowData:t,loading:s,onFilterChanged:m,onSortChanged:y,hiddenColumns:c.hiddenColumns})]})}const Nt=[{key:"orders_qty",name:"Заказы (шт)",color:x.bluePale[500]},{key:"buyouts_qty",name:"Выкупы (шт)",color:x.green[500]},{key:"orders_rub",name:"Заказы (₽)",color:x.orange[500]},{key:"buyouts_rub",name:"Выкупы (₽)",color:x.cyan[500]},{key:"sellers_with_orders",name:"Продавцы с заказами",color:x.primary[500]},{key:"sellers_with_buyouts",name:"Продавцы с выкупами",color:x.red[500]},{key:"cards_with_orders",name:"Карточки с заказами",color:x.bluePale[300]},{key:"cards_with_buyouts",name:"Карточки с выкупами",color:x.green[200]}],mi=["orders_qty","buyouts_qty","orders_rub","buyouts_rub"];function yi(t){if(t==null)return"";const n=Math.abs(t);return n>=1e9?(t/1e9).toFixed(1).replace(/\.0$/,"")+" млрд":n>=1e6?(t/1e6).toFixed(1).replace(/\.0$/,"")+" млн":n>=1e3?(t/1e3).toFixed(1).replace(/\.0$/,"")+" тыс":String(t)}function ji(t){return t?new Date(t).toLocaleDateString("ru-RU",{day:"2-digit",month:"2-digit"}):""}function vi({data:t}){const[n,s]=i.useState(mi),r=i.useMemo(()=>[...t].sort((o,f)=>new Date(o.period_start)-new Date(f.period_start)),[t]),l=i.useMemo(()=>r.map(o=>ji(o.period_start)),[r]),a=i.useCallback((o,f)=>{s(p=>f?[...p,o]:p.filter(c=>c!==o))},[]),d=i.useMemo(()=>Nt.filter(o=>n.includes(o.key)),[n]),h=i.useMemo(()=>{const o=d.map((p,c)=>({type:"log",name:p.name,nameTextStyle:{color:p.color,fontSize:11},position:c%2===0?"left":"right",offset:Math.floor(c/2)*70,axisLine:{show:!0,lineStyle:{color:p.color}},axisLabel:{fontSize:11,color:p.color,formatter:yi},splitLine:{show:c===0}})),f=d.map((p,c)=>({name:p.name,type:"line",yAxisIndex:c,data:r.map(u=>u[p.key]),smooth:!0,symbol:"none",lineStyle:{width:2,color:p.color},itemStyle:{color:p.color}}));return{tooltip:{trigger:"axis",axisPointer:{type:"cross"}},grid:{left:20+Math.floor(d.filter((p,c)=>c%2===0).length/1)*35,right:20+Math.floor(d.filter((p,c)=>c%2!==0).length/1)*35,top:40,bottom:30,containLabel:!0},xAxis:{type:"category",data:l,axisLabel:{fontSize:11}},yAxis:o.length>0?o:[{type:"log"}],series:f}},[d,r,l]);return e.jsxs("div",{style:{background:"#fff",borderRadius:8,padding:16,border:"1px solid #EFF1F5"},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:12,marginBottom:12},children:Nt.map(o=>e.jsx(it,{checked:n.includes(o.key),onChange:f=>a(o.key,f.target.checked),style:{color:o.color,fontWeight:500},children:e.jsx("span",{style:{color:o.color},children:o.name})},o.key))}),e.jsx(ln,{option:h,style:{height:400},notMerge:!0})]})}Ee.setLicenseKey("key");Le.registerModules([$e]);const bi=10,_i=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),ge=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(_i,{}):t(n)};function Si(t){return t?new Date(t).toLocaleDateString("ru-RU"):""}const wi=[{headerName:"Период",field:"period_start",minWidth:120,cellRenderer:ge(t=>e.jsx(ae,{value:Si(t.value)}))},{headerName:"Брендов с выкупами",field:"brands_with_buyouts",minWidth:140,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Брендов с заказами",field:"brands_with_orders",minWidth:140,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Продавцов с заказами",field:"sellers_with_orders",minWidth:150,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Продавцов с выкупами",field:"sellers_with_buyouts",minWidth:150,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Карточек с выкупами",field:"cards_with_buyouts",minWidth:150,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Карточек с заказами",field:"cards_with_orders",minWidth:150,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Заказы (шт)",field:"orders_qty",minWidth:120,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Заказы (₽)",field:"orders_rub",minWidth:130,cellRenderer:ge(t=>e.jsx(U,{value:t.value,suffix:" ₽"}))},{headerName:"Выкупы (шт)",field:"buyouts_qty",minWidth:120,cellRenderer:ge(t=>e.jsx(U,{value:t.value}))},{headerName:"Выкупы (₽)",field:"buyouts_rub",minWidth:130,cellRenderer:ge(t=>e.jsx(U,{value:t.value,suffix:" ₽"}))}],Ci=t=>Array.from({length:t},(n,s)=>({_id:s}));function ki({rowData:t,loading:n}){const s=i.useRef(bi);!n&&t.length&&(s.current=t.length);const r=i.useMemo(()=>n?Ci(s.current):t,[n,t]),l=i.useMemo(()=>({loading:n}),[n]);return e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Pe,headerHeight:ze,rowData:r,columnDefs:wi,context:l,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!1,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe},onGridReady:a=>{a.api.sizeColumnsToFit()},onGridSizeChanged:a=>{a.api.sizeColumnsToFit()},noRowsOverlayComponent:Re})})}const{Title:Fi}=R,Ri="sales/subject-dynamic",Di=[{label:"День",value:"day"},{label:"Неделя",value:"week"},{label:"Месяц",value:"month"}];async function Ii(t,n){let s=1,r=[];for(;;){const l=await le(`${Ri}/`,{params:{subject_id:t,period:n,page:s}}),{results:a,next:d}=l.data;if(r=r.concat(a),!d)break;s++}return r}function Ti(){const{subjectId:t}=an(),[n,s]=i.useState([]),[r,l]=i.useState(!0),[a,d]=i.useState("month"),{showRequestError:h}=B(),o=i.useCallback(()=>{l(!0),Ii(t,a).then(p=>s(p)).catch(p=>h(p)).finally(()=>l(!1))},[t,a,h]);i.useEffect(()=>{o()},[o]);const f=n.length>0?n[0].subject_name:"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx(se,{to:"/external-analytics/niche-analysis",children:e.jsx(on,{style:{fontSize:20,color:"#383540"}})}),e.jsx(Fi,{level:3,style:{margin:0},children:r&&!f?e.jsx(Ge,{size:"small"}):`Динамика ниши: ${f}`})]}),e.jsx(fe.Group,{options:Di,value:a,onChange:p=>d(p.target.value),optionType:"button",buttonStyle:"solid"}),!r&&n.length>0&&e.jsx(vi,{data:n}),e.jsx(ki,{rowData:n,loading:r})]})}Ee.setLicenseKey("key");Le.registerModules([$e]);const Ei=64,Li=10,$i=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),Tt=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx($i,{}):t(n)},Mi={category__name:{text:"category"},orders_rub:{min:"orders_rub_min",max:"orders_rub_max"},orders_rub_change_pc:{min:"orders_rub_change_pc_min",max:"orders_rub_change_pc_max"},orders_qty:{min:"orders_qty_min",max:"orders_qty_max"},orders_qty_change_pc:{min:"orders_qty_change_pc_min",max:"orders_qty_change_pc_max"},buyouts_rub:{min:"buyouts_rub_min",max:"buyouts_rub_max"},buyouts_rub_change_pc:{min:"buyouts_rub_change_pc_min",max:"buyouts_rub_change_pc_max"},buyouts_qty:{min:"buyouts_qty_min",max:"buyouts_qty_max"},buyouts_qty_change_pc:{min:"buyouts_qty_change_pc_min",max:"buyouts_qty_change_pc_max"},cards_count:{min:"cards_count_min",max:"cards_count_max"},cards_count_change_pc:{min:"cards_count_change_pc_min",max:"cards_count_change_pc_max"},cards_with_orders_count:{min:"cards_with_orders_count_min",max:"cards_with_orders_count_max"},cards_with_orders_count_change_pc:{min:"cards_with_orders_count_change_pc_min",max:"cards_with_orders_count_change_pc_max"}};function zi(t){const n={};for(const[s,r]of Object.entries(t)){const l=Mi[s];l&&("text"in l?r.filter&&(n[l.text]=r.filter):r.type==="inRange"?(r.filter!=null&&(n[l.min]=String(r.filter)),r.filterTo!=null&&(n[l.max]=String(r.filterTo))):r.type==="greaterThanOrEqual"?r.filter!=null&&(n[l.min]=String(r.filter)):r.type==="lessThanOrEqual"&&r.filter!=null&&(n[l.max]=String(r.filter)))}return n}const He=(t,n,s={})=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:130,cellRenderer:Tt(r=>e.jsx(U,{value:r.value,...s}))}),Pi=t=>t==null||isNaN(t)||!isFinite(t)?"--":t.toLocaleString("ru-RU"),Ne=(t,n)=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:170,cellRenderer:Tt(s=>{const r=s.value;if(r==null)return e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",width:"100%",height:"100%"},children:"--"});const l=r>=0,a=l?x.green[500]:x.red[500],d=l?Ct:kt;return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:4,width:"100%",height:"100%",color:a,fontSize:16,lineHeight:1.4,whiteSpace:"nowrap"},children:[e.jsx(d,{style:{fontSize:10}}),Pi(r),"%"]})})}),bt=[{headerName:"Категория",field:"category_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:200,cellRenderer:Tt(t=>e.jsx(ae,{value:t.value}))},He("Заказы, ₽","orders_rub",{suffix:" ₽"}),Ne("Δ Заказы ₽, %","orders_rub_change_pc"),He("Заказы, шт","orders_qty"),Ne("Δ Заказы шт, %","orders_qty_change_pc"),He("Выкупы, ₽","buyouts_rub",{suffix:" ₽"}),Ne("Δ Выкупы ₽, %","buyouts_rub_change_pc"),He("Выкупы, шт","buyouts_qty"),Ne("Δ Выкупы шт, %","buyouts_qty_change_pc"),He("Карточек товаров","cards_count"),Ne("Δ Карточек товаров, %","cards_count_change_pc"),{...He("Карточек с заказами","cards_with_orders_count"),minWidth:140},{...Ne("Δ Карточек с заказами, %","cards_with_orders_count_change_pc"),minWidth:160}],Ot=bt.map(t=>({field:t.field,headerName:t.headerName})),Wi=t=>Array.from({length:t},(n,s)=>({_id:s}));function Ai({rowData:t,loading:n,onFilterChanged:s,onSortChanged:r,hiddenColumns:l=[]}){const a=i.useRef(Li);!n&&t.length&&(a.current=t.length);const d=i.useMemo(()=>n?Wi(a.current):t,[n,t]),h=i.useMemo(()=>({loading:n}),[n]),o=i.useMemo(()=>l.length?bt.filter(c=>!l.includes(c.field)):bt,[l]),f=i.useCallback(c=>{if(!s)return;const u=c.api.getFilterModel(),m=zi(u);s(m)},[s]),p=i.useCallback(c=>{if(!r)return;const u=c.api.getColumnState().filter(m=>m.sort).map(m=>m.sort==="desc"?`-${m.colId}`:m.colId);r(u.length?u.join(","):null)},[r]);return e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Pe,headerHeight:ze,floatingFiltersHeight:Ei,rowData:d,columnDefs:o,context:h,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!0,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe,headerComponentParams:{enableSorting:!0,wrapText:!0}},onGridReady:c=>{c.api.sizeColumnsToFit()},onGridSizeChanged:c=>{c.api.sizeColumnsToFit()},onFilterChanged:f,onSortChanged:p,noRowsOverlayComponent:Re})})}const{Title:Hi}=R,Ni="wbstat/external_analytics_category",Oi=[{label:"Неделя",value:"week"},{label:"Месяц",value:"month"},{label:"Квартал",value:"quarter"}];function Bi(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState({}),[d,h]=i.useState(null),[o,f]=i.useState("month"),{showRequestError:p}=B(),c=Dn("category_analysis_columns",Ot),u=i.useCallback(j=>{r(!0),le(`${Ni}/`,{params:j}).then(b=>{n(b.data.results)}).catch(b=>{p(b)}).finally(()=>{r(!1)})},[p]);i.useEffect(()=>{const j={...l,period:o,page_size:100};d&&(j.ordering=d),u(j)},[l,d,o]);const m=i.useCallback(j=>{a(j)},[]),y=i.useCallback(j=>{h(j)},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Hi,{level:3,style:{margin:0},children:"Анализ категорий"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap",justifyContent:"space-between"},children:[e.jsx(fe.Group,{options:Oi,value:o,onChange:j=>f(j.target.value),optionType:"button",buttonStyle:"solid"}),e.jsx(Tn,{onClick:c.openModal})]}),e.jsx(In,{columns:Ot,hiddenColumns:c.hiddenColumns,open:c.open,onClose:c.closeModal,onToggle:c.toggleColumn}),e.jsx(Ai,{rowData:t,loading:s,onFilterChanged:m,onSortChanged:y,hiddenColumns:c.hiddenColumns})]})}function rt(t,n,s,r,l){if(n===s)return;let a;if(r==="log"){const h=Math.log1p(n),o=Math.log1p(s);a=(Math.log1p(t)-h)/(o-h)}else if(r==="quantile"){if(!l||l.length<2)return;let h=0,o=l.length-1;for(;h>1;l[f]n.date_from.slice(0,7))}function Ln(t){const[n,s]=t.split("-"),l=new Date(Number(n),Number(s)-1,1).toLocaleDateString("ru-RU",{month:"long",year:"numeric"});return l.charAt(0).toUpperCase()+l.slice(1)}function $n(t,n){let s=1/0,r=-1/0;for(const l of t)for(const a of n){const d=l[a];d!=null&&isFinite(d)&&(dr&&(r=d))}return isFinite(s)?{min:s,max:r}:{min:0,max:0}}function Mn(t,n){const s=[];for(const r of t)for(const l of n){const a=r[l];a!=null&&isFinite(a)&&s.push(a)}return s.sort((r,l)=>r-l),s}function zn(t,n){let s=1/0;for(const r of n){const l=t[r];l!=null&&isFinite(l)&&l>0&&lArray.from({length:t},(n,s)=>({_id:s}));Ee.setLicenseKey("key");Le.registerModules([$e]);const qi=10,Gi=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),Bt=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(Gi,{}):t(n)};function Ui(t){return!t||!t.length?[]:t.map(n=>{const s={category_name:n.category_name};return n.values&&n.values.forEach(r=>{const l=r.date_from.slice(0,7);s[l]=r.value}),s})}const Vi={category_name:{text:"category"}};function Ki(t){const n={};for(const[s,r]of Object.entries(t)){const l=Vi[s];l&&"text"in l&&r.filter&&(n[l.text]=r.filter)}return n}function Zi({rowData:t,loading:n,onFilterChanged:s,onSortChanged:r}){const l=i.useRef(null),a=i.useRef(qi),[d,h]=i.useState("linear"),o=i.useMemo(()=>En(t),[t]),f=i.useMemo(()=>Ui(t),[t]),{min:p,max:c}=i.useMemo(()=>$n(f,o),[f,o]),u=i.useMemo(()=>Mn(f,o),[f,o]);!n&&f.length&&(a.current=f.length);const m=i.useMemo(()=>n?Wn(a.current):f,[n,f]),y=i.useMemo(()=>({loading:n}),[n]),j=i.useMemo(()=>{const w=[{headerName:"Категория",field:"category_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:200,pinned:"left",cellRenderer:Bt(C=>e.jsx(ae,{value:C.value}))}];return o.forEach(C=>{w.push({headerName:Ln(C),field:C,filter:"agNumberColumnFilter",minWidth:140,cellRenderer:Bt(S=>e.jsx(U,{value:S.value})),cellStyle:S=>{if(S.value==null||!isFinite(S.value))return;let L;if(d==="dynamics"){const I=zn(S.data,o);L=rt(S.value,I,I*3,"linear")}else L=rt(S.value,p,c,d,u);return L?{backgroundColor:L}:void 0}})}),w},[o,p,c,d,u]),b=i.useCallback(w=>{if(!s)return;const C=w.api.getFilterModel(),S=Ki(C);s(S)},[s]),k=i.useCallback(w=>{if(!r)return;const C=w.api.getColumnState().filter(S=>S.sort).map(S=>S.sort==="desc"?`-${S.colId}`:S.colId);r(C.length?C.join(","):null)},[r]),_=i.useCallback(()=>{var w;(w=l.current)!=null&&w.api&&l.current.api.exportDataAsCsv()},[]);return e.jsxs("div",{style:{width:"100%",height:"calc(100vh - 200px)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:12,marginBottom:8},children:[e.jsx(fe.Group,{options:Pn,value:d,onChange:w=>h(w.target.value),optionType:"button",size:"small"}),e.jsx($,{icon:e.jsx(at,{}),onClick:_,children:"Скачать"})]}),e.jsx(ke,{ref:l,rowHeight:Pe,headerHeight:ze,rowData:m,columnDefs:j,context:y,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!0,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe,headerComponentParams:{enableSorting:!0,wrapText:!0}},onGridReady:()=>{},onGridSizeChanged:()=>{},onFilterChanged:b,onSortChanged:k,noRowsOverlayComponent:Re})]})}const{Title:Yi}=R,Qi="wbstat/category_matrix",Xi=[{label:"Заказы, ₽",value:"orders_rub"},{label:"Заказы, шт",value:"orders_qty"},{label:"Выкупы, ₽",value:"buyouts_rub"},{label:"Выкупы, шт",value:"buyouts_qty"},{label:"Карточек товаров",value:"cards_count"},{label:"Карточек с заказами",value:"cards_with_orders_count"}];function Ji(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState({}),[d,h]=i.useState(null),[o,f]=i.useState("orders_qty"),[p,c]=i.useState(null),[u,m]=i.useState(null),{showRequestError:y}=B(),j=i.useCallback(_=>{r(!0),le(`${Qi}/`,{params:_}).then(w=>{n(w.data.results)}).catch(w=>{y(w)}).finally(()=>{r(!1)})},[y]);i.useEffect(()=>{const _={...l,indicator:o,page_size:100};d&&(_.ordering=d),p!=null&&(_.value_min=p),u!=null&&(_.value_max=u),j(_)},[l,d,o,p,u]);const b=i.useCallback(_=>{a(_)},[]),k=i.useCallback(_=>{h(_)},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(Yi,{level:3,style:{margin:0},children:"Матрица категорий"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsx(me,{options:Xi,value:o,onChange:f,style:{width:260}}),e.jsx(Xe,{placeholder:"От",value:p,onChange:c,style:{width:140}}),e.jsx(Xe,{placeholder:"До",value:u,onChange:m,style:{width:140}})]}),e.jsx(Zi,{rowData:t,loading:s,onFilterChanged:b,onSortChanged:k})]})}Ee.setLicenseKey("key");Le.registerModules([$e]);const el=10,tl=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),xt=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(tl,{}):t(n)};function nl(t){return!t||!t.length?[]:t.map(n=>{const s={category_name:n.category_name,subject_name:n.subject_name};return n.values&&n.values.forEach(r=>{const l=r.date_from.slice(0,7);s[l]=r.value}),s})}const sl={category_name:{text:"category"},subject_name:{text:"subject_name"}};function rl(t){const n={};for(const[s,r]of Object.entries(t)){const l=sl[s];l&&"text"in l&&r.filter&&(n[l.text]=r.filter)}return n}function il({rowData:t,loading:n,onFilterChanged:s,onSortChanged:r}){const l=i.useRef(null),a=i.useRef(el),[d,h]=i.useState("linear"),o=i.useMemo(()=>En(t),[t]),f=i.useMemo(()=>nl(t),[t]),{min:p,max:c}=i.useMemo(()=>$n(f,o),[f,o]),u=i.useMemo(()=>Mn(f,o),[f,o]);!n&&f.length&&(a.current=f.length);const m=i.useMemo(()=>n?Wn(a.current):f,[n,f]),y=i.useMemo(()=>({loading:n}),[n]),j=i.useMemo(()=>{const w=[{headerName:"Категория",field:"category_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:200,pinned:"left",cellRenderer:xt(C=>e.jsx(ae,{value:C.value}))},{headerName:"Предмет",field:"subject_name",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:180,pinned:"left",cellRenderer:xt(C=>e.jsx(ae,{value:C.value}))}];return o.forEach(C=>{w.push({headerName:Ln(C),field:C,filter:"agNumberColumnFilter",minWidth:140,cellRenderer:xt(S=>e.jsx(U,{value:S.value})),cellStyle:S=>{if(S.value==null||!isFinite(S.value))return;let L;if(d==="dynamics"){const I=zn(S.data,o);L=rt(S.value,I,I*3,"linear")}else L=rt(S.value,p,c,d,u);return L?{backgroundColor:L}:void 0}})}),w},[o,p,c,d,u]),b=i.useCallback(w=>{if(!s)return;const C=w.api.getFilterModel(),S=rl(C);s(S)},[s]),k=i.useCallback(w=>{if(!r)return;const C=w.api.getColumnState().filter(S=>S.sort).map(S=>S.sort==="desc"?`-${S.colId}`:S.colId);r(C.length?C.join(","):null)},[r]),_=i.useCallback(()=>{var w;(w=l.current)!=null&&w.api&&l.current.api.exportDataAsCsv()},[]);return e.jsxs("div",{style:{width:"100%",height:"calc(100vh - 200px)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:12,marginBottom:8},children:[e.jsx(fe.Group,{options:Pn,value:d,onChange:w=>h(w.target.value),optionType:"button",size:"small"}),e.jsx($,{icon:e.jsx(at,{}),onClick:_,children:"Скачать"})]}),e.jsx(ke,{ref:l,rowHeight:Pe,headerHeight:ze,rowData:m,columnDefs:j,context:y,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!0,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe,headerComponentParams:{enableSorting:!0,wrapText:!0}},onGridReady:()=>{},onGridSizeChanged:()=>{},onFilterChanged:b,onSortChanged:k,noRowsOverlayComponent:Re})]})}const{Title:ll}=R,al="wbstat/subject_matrix",ol=[{label:"Заказы, шт",value:"orders_qty"},{label:"Заказы, ₽",value:"orders_rub"},{label:"Выкупы, шт",value:"buyouts_qty"},{label:"Выкупы, ₽",value:"buyouts_rub"},{label:"Выручка",value:"revenue"},{label:"Средний чек",value:"avg_check"},{label:"Карточек товаров",value:"cards_count"},{label:"Карточек с заказами",value:"cards_with_orders_count"},{label:"Продавцы",value:"suppliers"},{label:"Продавцы с продажами",value:"suppliers_with_sells"},{label:"Монополизация, %",value:"monopolization_pc"},{label:"Оборачиваемость, дн",value:"weekly_turnover_days"},{label:"Остатки",value:"remaining_count"},{label:"% выкупа",value:"redemption_pc"},{label:"Средний рейтинг",value:"avg_rating"},{label:"Наличие",value:"availability"}];function cl(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState({}),[d,h]=i.useState(null),[o,f]=i.useState("orders_qty"),[p,c]=i.useState(null),[u,m]=i.useState(null),{showRequestError:y}=B(),j=i.useCallback(_=>{r(!0),le(`${al}/`,{params:_}).then(w=>{n(w.data.results)}).catch(w=>{y(w)}).finally(()=>{r(!1)})},[y]);i.useEffect(()=>{const _={...l,indicator:o,page_size:100};d&&(_.ordering=d),p!=null&&(_.value_min=p),u!=null&&(_.value_max=u),j(_)},[l,d,o,p,u]);const b=i.useCallback(_=>{a(_)},[]),k=i.useCallback(_=>{h(_)},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(ll,{level:3,style:{margin:0},children:"Матрица предметов"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsx(me,{options:ol,value:o,onChange:f,style:{width:260}}),e.jsx(Xe,{placeholder:"От",value:p,onChange:c,style:{width:140}}),e.jsx(Xe,{placeholder:"До",value:u,onChange:m,style:{width:140}})]}),e.jsx(il,{rowData:t,loading:s,onFilterChanged:b,onSortChanged:k})]})}Ee.setLicenseKey("key");Le.registerModules([$e]);const dl=64,ul=10,pl=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),ut=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(pl,{}):t(n)},hl={text:{text:"text"},subject:{text:"subject"},count:{min:"count_min",max:"count_max"},prev_count:{min:"prev_count_min",max:"prev_count_max"},views:{min:"views_min",max:"views_max"},added:{min:"added_min",max:"added_max"},added_conv:{min:"added_conv_min",max:"added_conv_max"},orders:{min:"orders_min",max:"orders_max"},orders_conv:{min:"orders_conv_min",max:"orders_conv_max"},subjects:{min:"subjects_min",max:"subjects_max"}};function fl(t){const n={};for(const[s,r]of Object.entries(t)){const l=hl[s];l&&("text"in l?r.filter&&(n[l.text]=r.filter):r.type==="inRange"?(r.filter!=null&&(n[l.min]=String(r.filter)),r.filterTo!=null&&(n[l.max]=String(r.filterTo))):r.type==="greaterThanOrEqual"?r.filter!=null&&(n[l.min]=String(r.filter)):r.type==="lessThanOrEqual"&&r.filter!=null&&(n[l.max]=String(r.filter)))}return n}const xl=(t,n,s={})=>({headerName:t,field:n,filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:200,cellRenderer:ut(r=>e.jsx(ae,{value:r.value})),...s}),Oe=(t,n,s={})=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:130,cellRenderer:ut(r=>e.jsx(U,{value:r.value,...s}))}),qt=(t,n)=>({headerName:t,field:n,filter:"agNumberColumnFilter",floatingFilter:!0,floatingFilterComponent:De,minWidth:130,cellRenderer:ut(s=>s.value==null?null:e.jsx(U,{value:s.value,suffix:"%"}))}),gl=[{headerName:"Запрос",field:"text",filter:"agTextColumnFilter",filterParams:{debounceMs:500},floatingFilter:!0,minWidth:250,cellRenderer:ut(t=>e.jsx(ae,{value:t.value,routerLink:`/search-queries/${encodeURIComponent(t.value)}`}))},Oe("Частота","count"),Oe("Пред. частота","prev_count"),xl("Предмет","subject",{minWidth:160}),Oe("Просмотры","views"),Oe("В корзину","added"),qt("В корзину, %","added_conv"),Oe("Заказы","orders"),qt("Заказы, %","orders_conv"),Oe("Предметов","subjects")],ml=t=>Array.from({length:t},(n,s)=>({_id:s}));function yl({rowData:t,loading:n,onFilterChanged:s,onSortChanged:r}){const l=i.useRef(ul);!n&&t.length&&(l.current=t.length);const a=i.useMemo(()=>n?ml(l.current):t,[n,t]),d=i.useMemo(()=>({loading:n}),[n]),h=i.useCallback(f=>{if(!s)return;const p=f.api.getFilterModel(),c=fl(p);s(c)},[s]),o=i.useCallback(f=>{if(!r)return;const p=f.api.getColumnState().filter(c=>c.sort).map(c=>c.sort==="desc"?`-${c.colId}`:c.colId);r(p.length?p.join(","):null)},[r]);return e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Pe,headerHeight:ze,floatingFiltersHeight:dl,rowData:a,columnDefs:gl,context:d,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!0,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe,headerComponentParams:{enableSorting:!0,wrapText:!0}},onGridReady:f=>{f.api.sizeColumnsToFit()},onGridSizeChanged:f=>{f.api.sizeColumnsToFit()},onFilterChanged:h,onSortChanged:o,noRowsOverlayComponent:Re})})}const{Title:jl}=R,vl="wbstat/queries",bl=[50,100,200],_l=[{label:"День",value:"yesterday"},{label:"Неделя",value:"week"},{label:"Месяц",value:"month"}];function Sl(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState("week"),[d,h]=i.useState({}),[o,f]=i.useState(null),[p,c]=i.useState(1),[u,m]=i.useState(100),[y,j]=i.useState(0),{showRequestError:b}=B(),k=i.useCallback(I=>{r(!0),le(`${vl}/`,{params:I}).then(N=>{n(N.data.results),j(N.data.count)}).catch(N=>{b(N)}).finally(()=>{r(!1)})},[b]);i.useEffect(()=>{const I={...d,period:l,page:p,page_size:u};o&&(I.ordering=o),k(I)},[d,l,o,p,u]);const _=i.useCallback(I=>{a(I.target.value),c(1)},[]),w=i.useCallback(I=>{h(I),c(1)},[]),C=i.useCallback(I=>{f(I),c(1)},[]),S=i.useCallback(I=>{c(I)},[]),L=i.useCallback(I=>{m(I),c(1)},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(jl,{level:3,style:{margin:0},children:"Поисковые запросы"}),e.jsx(fe.Group,{options:_l,value:l,onChange:_,optionType:"button",buttonStyle:"solid"}),e.jsx(yl,{rowData:t,loading:s,onFilterChanged:w,onSortChanged:C}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:12},children:[e.jsx(mt,{current:p,total:y,pageSize:u,onChange:S,showSizeChanger:!1,showTotal:I=>`Всего ${I}`}),e.jsx(me,{value:u,onChange:L,options:bl.map(I=>({value:I,label:`${I} / стр`})),style:{width:110}})]})]})}const Gt=[{key:"queries_week",name:"Запросы (неделя)",color:x.bluePale[500]},{key:"queries_month",name:"Запросы (месяц)",color:x.green[500]},{key:"items_count",name:"Товаров в выдаче",color:x.cyan[500]},{key:"yesterday_count",name:"Запросов вчера",color:x.red[500]}],wl=["queries_week","queries_month"];function Cl(t){if(t==null)return"";const n=Math.abs(t);return n>=1e9?(t/1e9).toFixed(1).replace(/\.0$/,"")+" млрд":n>=1e6?(t/1e6).toFixed(1).replace(/\.0$/,"")+" млн":n>=1e3?(t/1e3).toFixed(1).replace(/\.0$/,"")+" тыс":String(t)}function kl(t){return t?new Date(t).toLocaleDateString("ru-RU",{day:"2-digit",month:"2-digit"}):""}function Fl({data:t}){const[n,s]=i.useState(wl),r=i.useMemo(()=>[...t].sort((o,f)=>new Date(o.period_start)-new Date(f.period_start)),[t]),l=i.useMemo(()=>r.map(o=>kl(o.period_start)),[r]),a=i.useCallback((o,f)=>{s(p=>f?[...p,o]:p.filter(c=>c!==o))},[]),d=i.useMemo(()=>Gt.filter(o=>n.includes(o.key)),[n]),h=i.useMemo(()=>{const o=d.map((p,c)=>({type:"log",name:p.name,nameTextStyle:{color:p.color,fontSize:11},position:c%2===0?"left":"right",offset:Math.floor(c/2)*70,axisLine:{show:!0,lineStyle:{color:p.color}},axisLabel:{fontSize:11,color:p.color,formatter:Cl},splitLine:{show:c===0}})),f=d.map((p,c)=>({name:p.name,type:"line",yAxisIndex:c,data:r.map(u=>u[p.key]||null),smooth:!0,symbol:"none",lineStyle:{width:2,color:p.color},itemStyle:{color:p.color}}));return{tooltip:{trigger:"axis",axisPointer:{type:"cross"}},grid:{left:20+Math.floor(d.filter((p,c)=>c%2===0).length/1)*35,right:20+Math.floor(d.filter((p,c)=>c%2!==0).length/1)*35,top:40,bottom:30,containLabel:!0},xAxis:{type:"category",data:l,axisLabel:{fontSize:11}},yAxis:o.length>0?o:[{type:"log"}],series:f}},[d,r,l]);return e.jsxs("div",{style:{background:"#fff",borderRadius:8,padding:16,border:"1px solid #EFF1F5"},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:12,marginBottom:12},children:Gt.map(o=>e.jsx(it,{checked:n.includes(o.key),onChange:f=>a(o.key,f.target.checked),style:{color:o.color,fontWeight:500},children:e.jsx("span",{style:{color:o.color},children:o.name})},o.key))}),e.jsx(ln,{option:h,style:{height:400},notMerge:!0})]})}Ee.setLicenseKey("key");Le.registerModules([$e]);const Rl=10,Dl=()=>e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 8px",width:"100%",height:"100%"},children:e.jsx(X.Input,{active:!0,size:"small",block:!0,style:{height:20,minWidth:0}})}),Ve=t=>n=>{var s;return(s=n.context)!=null&&s.loading?e.jsx(Dl,{}):t(n)};function Il(t){return t?new Date(t).toLocaleDateString("ru-RU"):""}const Tl=[{headerName:"Период",field:"period_start",minWidth:120,cellRenderer:Ve(t=>e.jsx(ae,{value:Il(t.value)}))},{headerName:"Запросы (неделя)",field:"queries_week",minWidth:140,cellRenderer:Ve(t=>e.jsx(U,{value:t.value}))},{headerName:"Запросы (месяц)",field:"queries_month",minWidth:140,cellRenderer:Ve(t=>e.jsx(U,{value:t.value}))},{headerName:"Товаров в выдаче",field:"items_count",minWidth:140,cellRenderer:Ve(t=>e.jsx(U,{value:t.value}))},{headerName:"Запросов вчера",field:"yesterday_count",minWidth:140,cellRenderer:Ve(t=>e.jsx(U,{value:t.value}))}],El=t=>Array.from({length:t},(n,s)=>({_id:s}));function Ll({rowData:t,loading:n}){const s=i.useRef(Rl);!n&&t.length&&(s.current=t.length);const r=i.useMemo(()=>n?El(s.current):t,[n,t]),l=i.useMemo(()=>({loading:n}),[n]);return e.jsx("div",{style:{width:"100%"},children:e.jsx(ke,{domLayout:"autoHeight",rowHeight:Pe,headerHeight:ze,rowData:r,columnDefs:Tl,context:l,defaultColDef:{suppressHeaderMenuButton:!0,sortable:!1,suppressMovable:!0,resizable:!0,suppressHeaderFilterButton:!0,suppressFloatingFilterButton:!0,headerComponent:Fe},onGridReady:a=>{a.api.sizeColumnsToFit()},onGridSizeChanged:a=>{a.api.sizeColumnsToFit()},noRowsOverlayComponent:Re})})}const{Title:$l}=R,Ml="wbstat/phrase_analysis",zl=[{label:"День",value:"day"},{label:"Неделя",value:"week"},{label:"Месяц",value:"month"}];async function Pl(t,n){let s=1,r=[],l=null;for(;;){const a=await le(`${Ml}/`,{params:{query:t,period:n,page:s,page_size:20}}),{results:d,next:h,cluster_summary:o}=a.data;if(r=r.concat(d),o&&(l=o),!h)break;s++}return{results:r,clusterSummary:l}}function Wl(){var c,u;const{query:t}=an(),[n,s]=i.useState([]),[r,l]=i.useState(null),[a,d]=i.useState(!0),[h,o]=i.useState("week"),{showRequestError:f}=B(),p=i.useCallback(()=>{d(!0),Pl(t,h).then(({results:m,clusterSummary:y})=>{s(m),l(y)}).catch(m=>f(m)).finally(()=>d(!1))},[t,h]);return i.useEffect(()=>{p()},[p]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx(se,{to:"/search-queries",children:e.jsx(on,{style:{fontSize:20,color:"#383540"}})}),e.jsx($l,{level:3,style:{margin:0},children:a&&!n.length?e.jsx(Ge,{size:"small"}):`Анализ фразы: ${t}`})]}),e.jsx(fe.Group,{options:zl,value:h,onChange:m=>o(m.target.value),optionType:"button",buttonStyle:"solid"}),r&&!a&&e.jsx("div",{style:{background:"#fff",borderRadius:8,padding:16,border:"1px solid #EFF1F5"},children:e.jsxs(We,{title:"Кластер",size:"small",column:{xs:1,sm:2,md:3},children:[e.jsx(We.Item,{label:"Фраза",children:r.text}),e.jsx(We.Item,{label:"Норм. фраза",children:r.norm_text}),e.jsx(We.Item,{label:"Запросы (неделя)",children:(c=r.cluster_week_count)==null?void 0:c.toLocaleString("ru-RU")}),e.jsx(We.Item,{label:"Запросы (месяц)",children:(u=r.cluster_month_count)==null?void 0:u.toLocaleString("ru-RU")}),e.jsx(We.Item,{label:"Обновлено",children:r.updated_at})]})}),!a&&n.length>0&&e.jsx(Fl,{data:n}),e.jsx(Ll,{rowData:n,loading:a})]})}function Al(){const t=Je(),{getProfile:n}=xe(),{showRequestError:s}=B();return i.useEffect(()=>{qe.handleCallback().then(()=>{const r=qe.accessToken;return Y("user/wb-login",{access_token:r})}).then(r=>{var l;((l=r.data)==null?void 0:l.is_new)===!0&&ym(107086743,"reachGoal","ym-register")}).then(()=>n()).then(()=>{const r=sessionStorage.getItem("wb_key");if(r)return sessionStorage.removeItem("wb_key"),Y("user/key-check",{key:r}).then(()=>n()).catch(()=>{})}).then(()=>{const r=localStorage.getItem("auth_redirect");r?(localStorage.removeItem("auth_redirect"),t(r,{replace:!0})):t("/profile")}).catch(r=>{console.error("WB ID callback error:",r),s(r),t("/auth/login")})},[]),e.jsx(we,{})}const Hl=()=>{const[t]=Rt();return i.useEffect(()=>{const n=t.get("key");n&&sessionStorage.setItem("wb_key",n),qe.login()},[]),e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"calc(100vh - 200px)"},children:e.jsx(Ge,{size:"large"})})};function Nl(t){return t?new Date(t).toLocaleDateString("ru-RU",{day:"numeric",month:"short",year:"numeric"}):""}function Ol(t){return!!(t!=null&&t.official_response)}function Ut({wishId:t,open:n,onVote:s,onLoad:r,variant:l="sidebar"}){const[a,d]=i.useState(null),[h,o]=i.useState(!1),{showRequestError:f}=B(),{resolution:p}=i.useContext(Ue);i.useEffect(()=>{n&&t?(o(!0),V(`wishes/${t}`).then(k=>{d(k.data),r==null||r(k.data)}).catch(k=>{f(k)}).finally(()=>{o(!1)})):n||d(null)},[n,t]);const c=()=>{a!=null&&a.has_voted||s(t).then(k=>{k!=null&&k.has_voted&&d(_=>_&&{..._,votes_count:k.votes_count,has_voted:!0})}).catch(()=>{})},u=a?Nl(a.created_at):"",m=a?a.votes_count>0||a.has_voted:!1,y=l==="sheet",j=l==="sidebar"&&p>je.Tablet;if(!n)return null;const b={display:"flex",flexDirection:"column",gap:16,...y?{}:j?{maxHeight:"calc(100vh - 96px)",overflowY:"auto",position:"sticky",top:72}:{}};return e.jsx("div",{style:b,children:h?e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:220},children:e.jsx(Ge,{})}):a?e.jsxs(e.Fragment,{children:[e.jsx("h2",{style:{fontSize:y?24:28,fontWeight:400,lineHeight:1.2,margin:0},children:a.title}),e.jsx(Me,{color:x.greyF[700],style:{margin:0,borderRadius:4,alignSelf:"flex-start"},children:a.status}),e.jsx(ve,{style:{margin:0}}),e.jsx("p",{style:{fontSize:14,lineHeight:1.45,margin:0,color:x.dark[500]},children:a.description}),e.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,color:x.dark[500]},children:[e.jsx($,{size:"small",icon:e.jsx(cn,{}),disabled:a.has_voted,onClick:c,style:{background:a.has_voted?x.primary[50]:x.greyF[100],borderColor:a.has_voted?x.primary[500]:"transparent",color:a.has_voted?x.dark[500]:x.greyF[700]},children:m?a.votes_count:null}),Ol(a)?e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"vertical",style:{margin:0}}),e.jsxs("span",{style:{alignItems:"center",color:x.dark[500],display:"inline-flex",fontSize:14,gap:4,lineHeight:1.2},children:[e.jsx(dn,{style:{fontSize:14,color:x.greyF[700]}}),"Есть ответ"]})]}):null,e.jsx(ve,{type:"vertical",style:{margin:0}}),e.jsx("span",{style:{fontSize:14,lineHeight:1.2},children:u})]}),a.official_response&&e.jsxs("div",{style:{borderLeft:`2px solid ${x.primary[500]}`,display:"flex",flexDirection:"column",gap:12,paddingLeft:12},children:[e.jsx("p",{style:{fontSize:14,fontWeight:500,lineHeight:1.2,margin:0},children:"Официальный ответ"}),e.jsx("p",{style:{fontSize:14,lineHeight:1.45,margin:0,color:x.dark[500]},children:a.official_response})]})]}):null})}const{TextArea:Bl}=J,ql=50,Gl=500;function Vt({onClose:t,onSubmit:n,variant:s="inline"}){const[r,l]=i.useState(""),[a,d]=i.useState(""),[h,o]=i.useState(!1),f=()=>{!r.trim()||!a.trim()||h||(o(!0),n({title:r.trim(),description:a.trim()}).then(()=>{l(""),d(""),t()}).catch(()=>{}).finally(()=>{o(!1)}))},p=()=>{h||(l(""),d(""),t())},c=r.trim().length>0&&a.trim().length>0,u=s==="sheet";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,...u?{flex:1,minHeight:0}:{}},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:500},children:"Заголовок"}),e.jsx(J,{placeholder:"Кратко опишите идею",value:r,onChange:m=>l(m.target.value),maxLength:ql,showCount:!0,disabled:h})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx("span",{style:{fontSize:14,fontWeight:500},children:"Описание"}),e.jsx(Bl,{placeholder:"Подробно опишите вашу идею",value:a,onChange:m=>d(m.target.value),maxLength:Gl,showCount:!0,rows:5,disabled:h,style:{resize:"none"}})]})]}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:u?"auto":4,paddingBottom:u?20:0},children:[e.jsxs(Ce,{variant:"contained",onClick:f,disabled:!c||h,sx:{flex:u?1:void 0,minWidth:u?void 0:226,height:40,fontSize:14,padding:"0 20px"},children:[e.jsx(un,{}),h?"Отправка...":"Предложить"]}),e.jsx($,{onClick:p,disabled:h,icon:e.jsx(wt,{}),style:{width:56,height:40},"aria-label":u?"Закрыть форму":"Закрыть форму создания"})]})]})}const{Title:Kt}=R,Zt=[{label:"Все",value:"all"},{label:"Новые",value:"Новое"},{label:"Запланировано",value:"Запланировано"},{label:"Сделано",value:"Сделано"}],Ul=[{label:"Все теги",value:"all"},{label:"Новые",value:"Новое"},{label:"Запланировано",value:"Запланировано"},{label:"Сделано",value:"Сделано"}],Yt=[{label:"Больше голосов",value:"most_votes"},{label:"Меньше голосов",value:"least_votes"},{label:"Сначала новые",value:"newest"},{label:"Сначала старые",value:"oldest"}],Ke=20;function Vl(t){return t?new Date(t).toLocaleDateString("ru-RU",{day:"numeric",month:"short",year:"numeric"}):""}function Kl(t){return!!(t!=null&&t.official_response)}function gt(t,n){return n!=null&&n.id?t.map(s=>s.id===n.id?{...s,...n}:s):t}function Zl(){const[t,n]=i.useState([]),[s,r]=i.useState(!0),[l,a]=i.useState("all"),[d,h]=i.useState("most_votes"),[o,f]=i.useState(1),[p,c]=i.useState(0),[u,m]=i.useState(null),[y,j]=i.useState(!1),{showMessage:b,showRequestError:k}=B(),{resolution:_}=i.useContext(Ue),w=_<=je.Tablet,C=i.useRef(new Map),S=i.useRef(new Set),L=g=>(g!=null&&g.id&&C.current.set(g.id,g),g),I=g=>{const v=C.current.get(g.id);return v?{...g,...v}:g};i.useEffect(()=>{let g=!0;r(!0);const v={ordering:d,page:o,limit:Ke};return l!=="all"&&(v.status=l),V("wishes",{params:v}).then(F=>{if(!g)return;const M=F.data.results.map(I);n(M),c(F.data.count);const z=M.filter(P=>!P.description&&!S.current.has(P.id));z.length!==0&&(z.forEach(P=>{S.current.add(P.id)}),Promise.allSettled(z.map(P=>V(`wishes/${P.id}`))).then(P=>{if(!g)return;const G=P.reduce((de,ye,O)=>{const ue=z[O].id;return S.current.delete(ue),ye.status==="fulfilled"&&de.push(L(ye.value.data)),de},[]);G.length>0&&n(de=>G.reduce((ye,O)=>gt(ye,O),de))}))}).catch(F=>{g&&k(F)}).finally(()=>{g&&r(!1)}),()=>{g=!1}},[l,d,o]),i.useEffect(()=>{if(!u)return;t.some(v=>v.id===u)||m(null)},[u,t]),i.useEffect(()=>{if(w&&(y||u))return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[w,y,u]);const N=g=>{a(g),f(1)},Q=g=>{h(g),f(1)},te=g=>{j(!1),m(v=>v===g.id?null:g.id)},E=g=>Y("wishes",g).then(()=>{j(!1),b("Идея отправлена на модерацию")}).catch(v=>{throw k(v),v}),K=g=>{const v=t.find(F=>F.id===g);return v!=null&&v.has_voted?Promise.resolve({has_voted:!0,votes_count:v.votes_count}):Y(`wishes/${g}/vote`).then(F=>(n(M=>M.map(z=>z.id===g?{...z,votes_count:F.data.votes_count,has_voted:!0}:z)),b("Ваш голос учтён!"),{has_voted:!0,votes_count:F.data.votes_count})).catch(F=>{var M,z,P;if(((M=F.response)==null?void 0:M.status)===400&&((P=(z=F.response)==null?void 0:z.data)!=null&&P.detail)){if(b(F.response.data.detail),F.response.data.has_voted)return n(G=>G.map(de=>de.id===g?{...de,votes_count:F.response.data.votes_count,has_voted:!0}:de)),{has_voted:!0,votes_count:F.response.data.votes_count}}else k(F);throw F})},Z=!!u&&!y&&!w,ce=_<=je.Tablet,T=i.useRef(null),[W,A]=i.useState(!1),D=i.useCallback(g=>{if(T.current=g,!g)return;const v=new ResizeObserver(([F])=>{A(F.contentRect.width<600)});return v.observe(g),()=>v.disconnect()},[]),H=Z?{display:"grid",gap:16,gridTemplateColumns:_>=je.Large?"693px minmax(0, 687px)":_>je.Tablet?"minmax(0, 1fr) minmax(0, 1fr)":"minmax(0, 1fr)",alignItems:"stretch",padding:"16px 20px 24px",height:"calc(100vh - 112px)"}:{maxWidth:693,padding:"16px 20px 24px"},q={alignItems:"flex-start",display:"flex",gap:10,justifyContent:"space-between",..._<=je.Tablet?{flexDirection:"column",alignItems:"stretch"}:{}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{background:"#fff",color:x.dark[500],fontFamily:"'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",margin:"0 -24px -24px",minHeight:"calc(100vh - 72px)"},children:w?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{borderBottom:`1px solid ${x.greyF[100]}`,display:"flex",flexDirection:"column",gap:12,padding:"8px 20px 12px"},children:[e.jsx(Kt,{level:3,style:{margin:0},children:"Пожелания"}),e.jsxs("div",{style:{display:"flex",gap:8,width:"100%"},children:[e.jsx(me,{options:Ul,value:l,onChange:N,variant:"filled",style:{flex:"0 0 146px"}}),e.jsx(me,{options:Yt,value:d,onChange:Q,variant:"filled",style:{flex:"1 1 0",minWidth:0}})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"12px 20px 108px"},children:[e.jsx(Qt,{loading:s,onVote:K,onWishClick:te,selectedWishId:u,wishes:t}),p>Ke?e.jsx("div",{style:{display:"flex",justifyContent:"center",marginTop:4},children:e.jsx(mt,{current:o,total:p,pageSize:Ke,onChange:f,showSizeChanger:!1})}):null]}),e.jsx(ls,{type:"primary",icon:e.jsx(yt,{style:{fontSize:24}}),onClick:()=>{m(null),j(!0)},"aria-label":"Предложить идею",style:{width:64,height:64}})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"12px 20px 0"},children:e.jsx(Kt,{level:3,style:{margin:0},children:"Пожелания"})}),e.jsxs("div",{style:H,children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16,minWidth:0,overflowY:"auto"},children:[e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:y?e.jsx(Vt,{onClose:()=>j(!1),onSubmit:E}):e.jsxs(Ce,{variant:"outlined",onClick:()=>{m(null),j(!0)},sx:{height:36,fontSize:13,padding:"0 16px",alignSelf:"flex-start"},children:[e.jsx(un,{}),"Предложить идею"]})}),e.jsx(ve,{style:{margin:0}}),e.jsxs("div",{ref:D,style:q,children:[W?e.jsx(me,{options:Zt,value:l,onChange:N,variant:"filled",style:{flex:"0 0 146px"}}):e.jsx(fe.Group,{options:Zt,value:l,onChange:g=>N(g.target.value),optionType:"button",buttonStyle:"solid"}),e.jsx(me,{options:Yt,value:d,onChange:Q,variant:"filled",style:{minWidth:180}})]}),e.jsx(Qt,{loading:s,onVote:K,onWishClick:te,selectedWishId:u,wishes:t}),p>Ke?e.jsx("div",{style:{display:"flex",justifyContent:"center",marginTop:4},children:e.jsx(mt,{current:o,total:p,pageSize:Ke,onChange:f,showSizeChanger:!1})}):null]}),Z?e.jsx("div",{style:{alignSelf:"stretch",minWidth:0,overflowY:"auto",...ce?{borderTop:`1px solid ${x.greyF[100]}`,paddingTop:16}:{borderLeft:`1px solid ${x.greyF[100]}`,paddingLeft:16}},children:e.jsx(Ut,{wishId:u,open:Z,onLoad:g=>{L(g),n(v=>gt(v,g))},onVote:K,variant:"sidebar"})}):null]})]})}),e.jsxs("div",{style:{position:"fixed",inset:0,zIndex:1e3,pointerEvents:"none"},children:[e.jsx(Et,{open:w&&y,onClose:()=>j(!1),placement:"bottom",height:"75%",closable:!1,getContainer:!1,rootStyle:{pointerEvents:y?"auto":"none"},styles:{wrapper:{borderRadius:"20px 20px 0 0",overflow:"hidden"},body:{padding:"16px 20px 20px",display:"flex",flexDirection:"column",height:"100%"}},children:e.jsx(Vt,{onClose:()=>j(!1),onSubmit:E,variant:"sheet"})}),e.jsx(Et,{open:w&&!!u,onClose:()=>m(null),placement:"bottom",height:"75%",closable:!1,getContainer:!1,rootStyle:{pointerEvents:u?"auto":"none"},styles:{wrapper:{borderRadius:"20px 20px 0 0",overflow:"hidden"},body:{padding:"16px 20px 20px"}},children:e.jsx(Ut,{wishId:u,open:!!u,onLoad:g=>{L(g),n(v=>gt(v,g))},onVote:K,variant:"sheet"})})]})]})}function Qt({wishes:t,loading:n,selectedWishId:s,onWishClick:r,onVote:l}){return n?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:Array.from({length:5}).map((a,d)=>e.jsx(X,{active:!0,paragraph:{rows:2}},`wish-skeleton-${d}`))}):t.length===0?e.jsx(be,{description:"Нет идей для отображения"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:t.map(a=>e.jsx(Yl,{onClick:()=>r(a),onVote:l,selected:a.id===s,wish:a},a.id))})}function Yl({wish:t,selected:n,onClick:s,onVote:r}){const l=Vl(t.created_at),a=t.votes_count>0||t.has_voted,d=Kl(t);return e.jsxs(as,{hoverable:!0,role:"button",tabIndex:0,onClick:s,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),s())},style:{borderColor:n?x.bluePale[500]:void 0,boxShadow:n?"0 8px 20px rgba(0, 123, 251, 0.08)":void 0},styles:{body:{padding:8,display:"flex",flexDirection:"column",gap:12}},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,minWidth:0},children:[e.jsx("h3",{style:{flex:"1 1 220px",fontSize:16,fontWeight:500,lineHeight:1.2,margin:0,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.title}),e.jsx(Me,{color:x.greyF[700],style:{margin:0,borderRadius:4},children:t.status})]}),e.jsx("p",{style:{color:x.dark[500],display:"-webkit-box",fontSize:14,lineHeight:1.2,margin:0,overflow:"hidden",WebkitBoxOrient:"vertical",WebkitLineClamp:1},children:t.description}),e.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,color:x.greyF[700]},children:[e.jsx($,{size:"small",icon:e.jsx(cn,{}),disabled:t.has_voted,onClick:h=>{h.stopPropagation(),r(t.id)},style:{background:t.has_voted?x.primary[50]:x.greyF[100],borderColor:t.has_voted?x.primary[500]:"transparent",color:t.has_voted?x.dark[500]:x.greyF[700]},children:a?t.votes_count:null}),d?e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"vertical",style:{margin:0}}),e.jsxs("span",{style:{alignItems:"center",color:x.dark[500],display:"inline-flex",fontSize:14,gap:4,lineHeight:1.2},children:[e.jsx(dn,{style:{fontSize:14,color:x.greyF[700]}}),"Есть ответ"]})]}):null,e.jsx(ve,{type:"vertical",style:{margin:0}}),e.jsx("span",{style:{fontSize:14,lineHeight:1.2},children:l})]})]})}const Xt=new Audio("/sounds/notification.mp3");function An(){const t=i.useRef(document.title),[n,s]=i.useState(0),r=i.useRef(document.hidden);return i.useEffect(()=>{const a=()=>{r.current=document.hidden,document.hidden||s(0)};return document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[]),i.useEffect(()=>{const a=t.current;document.title=n>0?`(${n}) ${a}`:a},[n]),i.useEffect(()=>{const a=t.current;return()=>{document.title=a}},[]),{notifyIncoming:i.useCallback(()=>{Xt.currentTime=0,Xt.play().catch(()=>{}),r.current&&s(a=>a+1)},[])}}const{Title:Sa,Text:ne}=R,{TextArea:Hn}=J,Ql=30,Xl=50,Jl=[{label:"Все",value:"all"},{label:"Активные",value:"open"},{label:"Завершенные",value:"closed"}];function Nn(t){if(!t)return"";const n=new Date(t),s=new Date;return n.toDateString()===s.toDateString()?n.toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString("ru-RU",{day:"numeric",month:"short"})}function On(t){const n=t==="open"?"Активный":"Завершенный";return e.jsx(Me,{style:{margin:0,fontSize:11,color:x.greyF[600],background:x.greyF[50],border:"1px solid #EBEBEC"},children:n})}function ea(t){const n={page:1,limit:Ql};return t==="open"?n.status="open":t==="closed"&&(n.status="closed"),n}function ta({chat:t,selected:n,onClick:s}){var a;const r=((a=t.last_message)==null?void 0:a.text)||"",l=r.length>60?r.slice(0,60)+"…":r;return e.jsx("div",{role:"button",tabIndex:0,onClick:s,onKeyDown:d=>(d.key==="Enter"||d.key===" ")&&s(),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:n?x.primary[50]:"#fff",border:n?`1px solid ${x.primary[300]}`:"1px solid #EBEBEC",transition:"background 0.15s, border-color 0.15s"},children:e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:6},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx(ne,{strong:!0,style:{display:"block",fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:t.has_unread?700:500,color:x.dark[500],marginBottom:4},children:t.subject}),l&&e.jsx(ne,{style:{fontSize:12,color:x.greyF[600],display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginBottom:4},children:l}),e.jsx(ne,{style:{fontSize:11,color:x.greyF[500],display:"block"},children:Nn(t.updated_at)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:6,flexShrink:0},children:[On(t.status),t.unread_count>0&&e.jsx(pn,{count:t.unread_count,style:{backgroundColor:x.primary[500],color:x.dark[500],fontWeight:600,fontSize:12,minWidth:22,height:22,lineHeight:"22px",borderRadius:11}})]})]})})}function na({msg:t,read:n}){var r;if(t.kind==="system")return e.jsx("div",{style:{textAlign:"center",margin:"8px 0"},children:e.jsx(ne,{style:{fontSize:12,color:x.greyF[600],background:x.greyF[100],padding:"3px 10px",borderRadius:12},children:t.text})});const s=t.kind==="user";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start",margin:"4px 0"},children:[e.jsx(ne,{style:{fontSize:13,fontWeight:500,color:x.dark[500],marginBottom:2},children:s?"Пользователь":"Поддержка"}),e.jsxs("div",{style:{maxWidth:"70%",background:s?"#DBEDFF":"#EFF1F5",color:x.dark[500],borderRadius:s?"12px 12px 2px 12px":"12px 12px 12px 2px",padding:"8px 12px",fontSize:14},children:[e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t.text}),((r=t.attachments)==null?void 0:r.length)>0&&e.jsx("div",{style:{marginTop:6,display:"flex",flexDirection:"column",gap:3},children:t.attachments.map(l=>e.jsxs("a",{href:l.file_url,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:4,fontSize:12,color:x.bluePale[500]},children:[e.jsx(fn,{}),l.original_name]},l.id))}),e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"flex-start":"flex-end",gap:3,marginTop:4},children:e.jsx(ne,{style:{fontSize:10,color:x.greyF[600]},children:Nn(t.created_at)})})]})]})}function sa({chatId:t,refreshKey:n,showDividerAfterMsgId:s,onMessagesLoaded:r,lastSupportReadMsgId:l}){const[a,d]=i.useState([]),[h,o]=i.useState(!0),{showRequestError:f}=B(),p=i.useRef(null),c=i.useRef(r),u=i.useRef(!0);if(i.useEffect(()=>{c.current=r},[r]),i.useEffect(()=>{u.current=!0,d([])},[t]),i.useEffect(()=>{if(!t)return;let y=!0;return u.current&&(o(!0),u.current=!1),V(`helpdesk/chats/${t}/messages`,{params:{limit:Xl}}).then(j=>{var w;if(!y)return;const k=[...j.data.results??j.data].reverse();d(k);const _=k.reduce((C,S)=>S.id>C?S.id:C,0);(w=c.current)==null||w.call(c,_)}).catch(j=>y&&f(j)).finally(()=>y&&o(!1)),()=>{y=!1}},[t,n]),i.useEffect(()=>{var y;(y=p.current)==null||y.scrollIntoView({behavior:"instant"})},[a]),h)return e.jsx("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:Array.from({length:4}).map((y,j)=>e.jsx(X,{active:!0,paragraph:{rows:1}},j))});if(a.length===0)return e.jsx(be,{description:"Нет сообщений",style:{marginTop:40}});a.filter(y=>y.kind!=="user").reduce((y,j)=>j.id>y?j.id:y,0);const m=[];return a.forEach(y=>{m.push(e.jsx(na,{msg:y,read:!1},y.id)),s&&y.id===s&&m.push(e.jsx("div",{style:{textAlign:"center",margin:"8px 0"},children:e.jsx(ne,{style:{fontSize:12,color:x.greyF[600],background:x.greyF[100],padding:"3px 14px",borderRadius:12},children:"Новые сообщения"})},"new-msg-divider"))}),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column"},children:[m,e.jsx("div",{ref:p})]})}function ra({chatId:t,onSent:n,onBeforeSend:s}){const[r,l]=i.useState(""),[a,d]=i.useState([]),[h,o]=i.useState(!1),{showRequestError:f}=B(),p=()=>{if(!r.trim()&&a.length===0)return;o(!0),s==null||s();let u;if(a.length>0){const m=new FormData;m.append("text",r.trim()),a.forEach(y=>m.append("attachments",y.originFileObj)),u=Y(`helpdesk/chats/${t}/messages`,m,{headers:{"Content-Type":"multipart/form-data"}})}else u=Y(`helpdesk/chats/${t}/messages`,{text:r.trim()});u.then(()=>{l(""),d([]),n()}).catch(m=>f(m)).finally(()=>o(!1))},c=r.trim()||a.length>0;return e.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${x.greyF[100]}`},children:[a.length>0&&e.jsx("div",{style:{marginBottom:8,display:"flex",flexWrap:"wrap",gap:4},children:a.map(u=>e.jsx(Me,{icon:e.jsx(st,{}),closable:!0,onClose:()=>d(m=>m.filter(y=>y.uid!==u.uid)),style:{margin:0},children:u.name},u.uid))}),e.jsxs("div",{style:{display:"flex",alignItems:"center",border:"1px solid #DDDDDE",borderRadius:8,overflow:"hidden",minHeight:80},children:[e.jsx(Hn,{value:r,onChange:u=>l(u.target.value),placeholder:"Сообщение...",autoSize:{minRows:3,maxRows:6},onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),p())},style:{flex:1,resize:"none",border:"none",boxShadow:"none",fontSize:14,padding:"12px 8px 12px 14px"},variant:"borderless"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"0 10px",flexShrink:0},children:[e.jsx(Dt,{fileList:a,onChange:({fileList:u})=>d(u),beforeUpload:()=>!1,showUploadList:!1,multiple:!0,children:e.jsx($,{icon:e.jsx(st,{}),type:"text",style:{color:x.greyF[600],width:44,height:44,fontSize:18}})}),e.jsx($,{shape:"circle",type:"primary",icon:e.jsx(hn,{}),onClick:p,loading:h,disabled:!c,style:{width:44,height:44,flexShrink:0,color:x.dark[500],fontSize:18}})]})]})]})}function ia({chat:t,onChatUpdated:n,externalMsgTrigger:s,lastSupportReadMsgId:r,onMessageSent:l}){const[a,d]=i.useState(0),[h,o]=i.useState(!1),[f,p]=i.useState(null),c=i.useRef(0),u=i.useRef(!1),m=i.useRef(!1),y=i.useRef(t),j=i.useRef(n);i.useEffect(()=>{y.current=t},[t]),i.useEffect(()=>{j.current=n},[n]);const{showMessage:b,showRequestError:k}=B();i.useEffect(()=>{t&&(p(null),c.current=0,u.current=!1,m.current=!1,Y(`helpdesk/chats/${t.id}/mark-read`).then(()=>n()).catch(()=>{}),d(S=>S+1))},[t==null?void 0:t.id]),i.useEffect(()=>{if(s>0){const S=m.current;m.current=!1,!S&&!u.current&&c.current>0&&(p(c.current),u.current=!0),d(I=>I+1);const L=y.current;L&&Y(`helpdesk/chats/${L.id}/mark-read`).then(()=>j.current()).catch(()=>{})}},[s]);const _=(S,L)=>{o(!0),Y(`helpdesk/chats/${t.id}/${S}`).then(()=>{b(L),n()}).catch(I=>k(I)).finally(()=>o(!1))};if(!t)return e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:x.greyF[600],fontSize:14},children:"Выберите диалог или создайте новый"});const w=t.status==="open",C=t.archived;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minHeight:0},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${x.greyF[100]}`,display:"flex",gap:8,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:20,fontWeight:600,color:x.dark[500],lineHeight:1},children:t.subject}),On(t.status),C&&e.jsx(Me,{color:"orange",children:"Архив"})]}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",flexShrink:0},children:w&&e.jsx($,{size:"small",icon:e.jsx(os,{}),onClick:()=>_("close","Чат закрыт"),loading:h,children:"Закрыть"})})]}),e.jsx("div",{style:{flex:1,overflowY:"auto"},children:e.jsx(sa,{chatId:t.id,refreshKey:a,showDividerAfterMsgId:f,onMessagesLoaded:S=>{c.current=S},lastSupportReadMsgId:r})}),w?e.jsx(ra,{chatId:t.id,onBeforeSend:()=>{l==null||l()},onSent:()=>{m.current=!0,p(null),u.current=!1,d(S=>S+1),n()}}):e.jsxs("div",{style:{padding:"24px 16px",borderTop:`1px solid ${x.greyF[100]}`,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx(ne,{style:{color:x.greyF[600],fontSize:14,display:"block"},children:"Этот диалог завершён"}),e.jsx(ne,{style:{color:x.greyF[600],fontSize:14,display:"block"},children:"Вы можете возобновить его"})]}),e.jsx($,{type:"primary",onClick:()=>_("reopen","Чат переоткрыт"),loading:h,style:{height:40,borderRadius:4,padding:"0 24px",fontSize:14,fontWeight:500,color:x.dark[500]},children:"Возобновить диалог"})]})]})}function la({open:t,categories:n,onClose:s,onCreated:r}){const[l,a]=i.useState(""),[d,h]=i.useState(null),[o,f]=i.useState(""),[p,c]=i.useState([]),[u,m]=i.useState(!1),[y,j]=i.useState({}),{showRequestError:b}=B(),k=C=>{y[C]&&j(S=>({...S,[C]:null}))},_=()=>{const C={};if(l.trim()||(C.subject="Укажите тему обращения"),o.trim()||(C.text="Напишите сообщение"),Object.keys(C).length>0){j(C);return}m(!0);const S=new FormData;S.append("subject",l.trim()),d&&S.append("category_id",d),S.append("text",o.trim()),p.forEach(L=>S.append("attachments",L.originFileObj)),Y("helpdesk/chats",S,{headers:{"Content-Type":"multipart/form-data"}}).then(L=>{r(L.data),a(""),h(null),f(""),c([]),j({}),s()}).catch(L=>{var N;const I=(N=L.response)==null?void 0:N.data;if(I&&typeof I=="object"&&!I.detail&&!I.error){const Q={};for(const[te,E]of Object.entries(I))Q[te]=Array.isArray(E)?E[0]:E;j(Q)}else b(L)}).finally(()=>m(!1))},w=()=>{j({}),s()};return e.jsx(Te,{open:t,onCancel:w,title:e.jsx("span",{style:{fontSize:20,fontWeight:600},children:"Новый диалог"}),footer:e.jsx("div",{style:{textAlign:"left",paddingTop:4},children:e.jsx($,{type:"primary",loading:u,onClick:_,style:{height:40,borderRadius:4,padding:"0 24px",fontSize:14,fontWeight:500,color:x.dark[500]},children:"Подтвердить"})}),width:680,centered:!0,children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16,marginTop:20},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:6},children:[e.jsx(ne,{style:{fontSize:14,fontWeight:500,color:x.dark[500]},children:"Тема"}),e.jsxs(ne,{style:{fontSize:13,color:x.greyF[600]},children:[l.length,"/50"]})]}),e.jsx(J,{value:l,onChange:C=>{C.target.value.length<=50&&(a(C.target.value),k("subject"))},placeholder:"Кратко опишите тему обращения",status:y.subject?"error":void 0,maxLength:50,style:{borderRadius:4}}),y.subject&&e.jsx(ne,{style:{fontSize:12,color:"#ff4d4f",marginTop:4,display:"block"},children:y.subject})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:6},children:[e.jsx(ne,{style:{fontSize:14,fontWeight:500,color:x.dark[500]},children:"Описание"}),e.jsxs(ne,{style:{fontSize:13,color:x.greyF[600]},children:[o.length,"/500"]})]}),e.jsx(Hn,{value:o,onChange:C=>{C.target.value.length<=500&&(f(C.target.value),k("text"))},placeholder:"Подробно опишите тему обращения",autoSize:{minRows:5,maxRows:8},status:y.text?"error":void 0,maxLength:500,style:{borderRadius:4}}),y.text&&e.jsx(ne,{style:{fontSize:12,color:"#ff4d4f",marginTop:4,display:"block"},children:y.text})]}),e.jsxs("div",{children:[e.jsx(ne,{style:{fontSize:14,fontWeight:500,color:x.dark[500],marginBottom:6,display:"block"},children:"Вложения"}),e.jsxs(Dt.Dragger,{fileList:p,onChange:({fileList:C})=>c(C),beforeUpload:()=>!1,multiple:!0,style:{borderColor:"#DDDDDE",borderRadius:8,background:"#FAFAFA"},children:[e.jsx("p",{style:{marginBottom:8},children:e.jsx(cs,{style:{fontSize:32,color:x.greyF[500]}})}),e.jsx("p",{style:{fontSize:13,color:x.greyF[600]},children:"Перетащите файлы или нажмите для выбора"})]})]})]})})}function aa(){const{profile:t,addPublicationHandler:n,removePublicationHandler:s}=xe(),{showRequestError:r}=B(),[l,a]=i.useState([]),[d,h]=i.useState(!0),[o,f]=i.useState(null),[p,c]=i.useState("all"),[u,m]=i.useState(""),[y,j]=i.useState(""),[b,k]=i.useState([]),[_,w]=i.useState(!1),[C,S]=i.useState(0),[L,I]=i.useState(0),[N,Q]=i.useState(0),{notifyIncoming:te}=An(),E=i.useRef(!1),K=i.useRef(o);i.useEffect(()=>{K.current=o},[o]),i.useEffect(()=>{const D=H=>{H.key==="Escape"&&K.current&&f(null)};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[]),i.useEffect(()=>{Q(0)},[o]);const Z=i.useRef(!0);if(i.useEffect(()=>{Z.current=!0},[p,u]),i.useEffect(()=>{t.auth&&V("helpdesk/categories").then(D=>k(D.data.results??D.data)).catch(()=>{})},[t.auth]),i.useEffect(()=>{if(!t.auth)return;let D=!0;Z.current&&(h(!0),Z.current=!1);const H=ea(p);return u&&(H.search=u),V("helpdesk/chats",{params:H}).then(q=>{D&&a(q.data.results??q.data)}).catch(q=>{D&&r(q)}).finally(()=>{D&&h(!1)}),()=>{D=!1}},[t.auth,p,u,C]),i.useEffect(()=>{o&&l.length>0&&!l.find(D=>D.id===o)&&f(null)},[l]),i.useEffect(()=>{if(!t.auth)return;const D="helpdesk-user-page";return n(D,H=>{const{type:q,chat_id:g}=H.data??{};if(q){if((q==="chat.created"||q==="chat.updated"||q==="message.created")&&(S(v=>v+1),q==="message.created")){const v=E.current;E.current=!1,v||te(),g===K.current&&I(F=>F+1)}if(q==="chat.read"&&g===K.current){const{read_up_to_message_id:v,reader:F}=H.data;F==="support"&&Q(v)}}}),()=>s(D)},[t.auth,n,s]),t.auth===void 0)return e.jsx(we,{});if(t.auth===!1)return e.jsx(dt,{});const ce=l.find(D=>D.id===o)??null;i.useEffect(()=>{const D=setTimeout(()=>m(y),300);return()=>clearTimeout(D)},[y]);const{resolution:T}=i.useContext(Ue),W=T<=je.Tablet,A=()=>S(D=>D+1);return e.jsxs("div",{style:{margin:"0 -24px -24px",height:"calc(100vh - 72px)",background:"#fff",display:"flex",fontFamily:"'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"},children:[e.jsxs("div",{style:{...W?{display:o?"none":"flex",width:"100%"}:{display:"flex",width:"28%",minWidth:300,maxWidth:460},flexShrink:0,borderRight:W?"none":`1px solid ${x.greyF[100]}`,flexDirection:"column",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"16px 16px 0"},children:[e.jsx("h2",{style:{margin:"0 0 16px",fontSize:32,fontWeight:400,color:x.dark[500],lineHeight:1.2},children:"Поддержка"}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:16},children:[e.jsx(J,{prefix:e.jsx(St,{style:{color:x.greyF[700]}}),placeholder:"Поиск",value:y,onChange:D=>j(D.target.value),allowClear:!0,onClear:()=>j(""),style:{flex:"1 1 160px",height:40,borderColor:"#DDDDDE",borderRadius:4,fontSize:14}}),e.jsx($,{type:"primary",icon:e.jsx(yt,{}),onClick:()=>w(!0),style:{flex:"1 1 auto",height:40,borderRadius:4,padding:"8px 20px",fontSize:14,fontWeight:500,color:x.dark[500],whiteSpace:"nowrap"},children:"Новый диалог"})]}),e.jsx("div",{style:{height:1,background:"#EFF1F5",marginBottom:16}}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",background:"#F7F8FA",border:"1px solid #EFF1F5",borderRadius:4,padding:"4px",gap:"4px",marginBottom:12},children:Jl.map(D=>{const H=p===D.value;return e.jsx("button",{onClick:()=>{c(D.value),f(null)},style:{height:26,border:"none",borderRadius:2,background:H?x.primary[500]:"transparent",color:H?x.dark[500]:x.greyF[700],fontSize:12,fontWeight:H?500:400,cursor:"pointer",whiteSpace:"nowrap",outline:H?`1px solid ${x.primary[500]}`:"none"},children:D.label},D.value)})})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px",display:"flex",flexDirection:"column",gap:6},children:d?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:8},children:Array.from({length:5}).map((D,H)=>e.jsx(X,{active:!0,paragraph:{rows:2}},H))}):l.length===0?e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12},children:[e.jsx("span",{style:{fontSize:16,fontWeight:500,color:x.dark[500]},children:"Нет диалогов по этому запросу"}),e.jsx($,{type:"primary",icon:e.jsx(yt,{}),onClick:()=>w(!0),style:{height:40,borderRadius:4,padding:"8px 20px",fontSize:14,fontWeight:500,color:x.dark[500]},children:"Новый диалог"})]}):l.map(D=>e.jsx(ta,{chat:D,selected:D.id===o,onClick:()=>f(D.id)},D.id))})]}),e.jsxs("div",{style:{...W?{display:o?"flex":"none",width:"100%"}:{display:"flex",flex:1},flexDirection:"column",minWidth:0,height:"calc(100vh - 72px)",overflow:"hidden"},children:[W&&o&&e.jsx("button",{onClick:()=>f(null),style:{display:"flex",alignItems:"center",gap:6,padding:"10px 16px",border:"none",borderBottom:`1px solid ${x.greyF[100]}`,background:"#fff",cursor:"pointer",fontSize:14,color:x.primary[500],fontWeight:500,flexShrink:0},children:"← Назад к диалогам"}),e.jsx(ia,{chat:ce,onChatUpdated:A,externalMsgTrigger:L,lastSupportReadMsgId:N,onMessageSent:()=>{E.current=!0}})]}),e.jsx(la,{open:_,categories:b,onClose:()=>w(!1),onCreated:()=>{A(),c("open")}})]})}const{Text:ee}=R,{TextArea:oa}=J,ca=40,da=50;function Bn(t){if(!t)return"";const n=new Date(t),s=new Date;return n.toDateString()===s.toDateString()?n.toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString("ru-RU",{day:"numeric",month:"short"})}function qn(t){const n=t==="open"?"Активный":"Завершенный";return e.jsx(Me,{style:{margin:0,fontSize:11,color:x.greyF[600],background:x.greyF[50],border:"1px solid #EBEBEC"},children:n})}function ua(t){if(!t)return null;const n=new Date(t);return Number.isNaN(n.getTime())?t:n.toLocaleDateString("ru-RU")}function pa(t,n){const s={limit:ca};return t==="open"?s.status="open":t==="closed"&&(s.status="closed"),n&&(s.search=n),s}function ha({chat:t,selected:n,onClick:s}){var f,p,c,u,m,y;const r=((f=t.last_message)==null?void 0:f.text)||"",l=r.length>60?r.slice(0,60)+"…":r,a=t.user?t.user.tg_username?`@${t.user.tg_username}`:t.user.first_name?`${t.user.first_name} ${t.user.last_name||""}`.trim():"Пользователь":"—",d=((p=t.user)==null?void 0:p.email)||"Email не указан",h=((c=t.assigned_to)==null?void 0:c.first_name)||((u=t.assigned_to)==null?void 0:u.email)||"Не назначено",o=((m=t.category)==null?void 0:m.name)||"Новое обращение";return e.jsx("div",{role:"button",tabIndex:0,onClick:s,onKeyDown:j=>(j.key==="Enter"||j.key===" ")&&s(),style:{padding:"12px",borderRadius:6,cursor:"pointer",background:n?x.primary[50]:"#fff",border:n?`1px solid ${x.primary[300]}`:"1px solid #EBEBEC",transition:"background 0.15s, border-color 0.15s"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,minWidth:0},children:[e.jsx(ee,{style:{fontSize:13,color:x.greyF[700],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1},children:a}),e.jsx(ee,{style:{fontSize:13,color:x.greyF[700],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:d})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:0},children:[e.jsx(nn,{style:{color:x.greyF[600],fontSize:14,flexShrink:0}}),e.jsx(ee,{style:{fontSize:13,color:t.assigned_to?x.greyF[700]:(y=x.red)==null?void 0:y[500],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),e.jsx("span",{style:{width:1,height:24,background:"#E3E6EB",flexShrink:0}}),e.jsx(ee,{style:{fontSize:13,color:x.greyF[700],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o})]})]}),e.jsx("div",{style:{height:1,background:"#EFF1F5"}}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:6},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx(ee,{strong:!0,style:{display:"block",fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:t.has_unread?700:500,color:x.dark[500],marginBottom:4},children:t.subject}),l&&e.jsx(ee,{style:{fontSize:12,color:x.greyF[600],display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginBottom:4},children:l}),e.jsx(ee,{style:{fontSize:11,color:x.greyF[500],display:"block"},children:Bn(t.updated_at)})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:6,flexShrink:0,paddingTop:1},children:[qn(t.status),t.unread_count>0&&e.jsx(pn,{count:t.unread_count,style:{backgroundColor:x.primary[500],color:x.dark[500],fontWeight:600,fontSize:12,minWidth:22,height:22,lineHeight:"22px",borderRadius:11}})]})]})]})})}function fa({msg:t}){var r,l,a,d,h;if(t.kind==="system")return e.jsx("div",{style:{textAlign:"center",margin:"8px 0"},children:e.jsx(ee,{style:{fontSize:12,color:x.greyF[600],background:x.greyF[100],padding:"3px 10px",borderRadius:12},children:t.text})});const n=t.kind==="user",s=n?((r=t.author)==null?void 0:r.first_name)||((l=t.author)==null?void 0:l.email)||"Пользователь":((a=t.author)==null?void 0:a.first_name)||((d=t.author)==null?void 0:d.email)||"Поддержка";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:n?"flex-start":"flex-end",margin:"4px 0"},children:[e.jsx(ee,{style:{fontSize:13,fontWeight:500,color:x.dark[500],marginBottom:2},children:s}),e.jsxs("div",{style:{maxWidth:"70%",background:n?"#EFF1F5":"#DBEDFF",color:x.dark[500],borderRadius:n?"12px 12px 12px 2px":"12px 12px 2px 12px",padding:"8px 12px",fontSize:14},children:[e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t.text}),((h=t.attachments)==null?void 0:h.length)>0&&e.jsx("div",{style:{marginTop:6,display:"flex",flexDirection:"column",gap:3},children:t.attachments.map(o=>e.jsxs("a",{href:o.file_url,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:4,fontSize:12,color:x.bluePale[500]},children:[e.jsx(fn,{}),o.original_name]},o.id))}),e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:n?"flex-end":"flex-start",gap:3,marginTop:4},children:e.jsx(ee,{style:{fontSize:10,color:x.greyF[600]},children:Bn(t.created_at)})})]})]})}function xa({chatId:t,refreshKey:n,showDividerAfterMsgId:s,onMessagesLoaded:r}){const[l,a]=i.useState([]),[d,h]=i.useState(!0),{showRequestError:o}=B(),f=i.useRef(null),p=i.useRef(r),c=i.useRef(!0);if(i.useEffect(()=>{p.current=r},[r]),i.useEffect(()=>{c.current=!0,a([])},[t]),i.useEffect(()=>{if(!t)return;let m=!0;return c.current&&(h(!0),c.current=!1),V(`helpdesk/support/chats/${t}/messages`,{params:{limit:da}}).then(y=>{var _;if(!m)return;const b=[...y.data.results??y.data].reverse();a(b);const k=b.reduce((w,C)=>C.id>w?C.id:w,0);(_=p.current)==null||_.call(p,k)}).catch(y=>m&&o(y)).finally(()=>m&&h(!1)),()=>{m=!1}},[t,n]),i.useEffect(()=>{var m;(m=f.current)==null||m.scrollIntoView({behavior:"instant"})},[l]),d)return e.jsx("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:Array.from({length:4}).map((m,y)=>e.jsx(X,{active:!0,paragraph:{rows:1}},y))});if(l.length===0)return e.jsx(be,{description:"Нет сообщений",style:{marginTop:40}});const u=[];return l.forEach(m=>{u.push(e.jsx(fa,{msg:m},m.id)),s&&m.id===s&&u.push(e.jsx("div",{style:{textAlign:"center",margin:"8px 0"},children:e.jsx(ee,{style:{fontSize:12,color:x.greyF[600],background:x.greyF[100],padding:"3px 14px",borderRadius:12},children:"Новые сообщения"})},"new-msg-divider"))}),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column"},children:[u,e.jsx("div",{ref:f})]})}function ga({chatId:t,onSent:n,onBeforeSend:s}){const[r,l]=i.useState(""),[a,d]=i.useState([]),[h,o]=i.useState(!1),{showRequestError:f}=B(),p=()=>{if(!r.trim()&&a.length===0)return;o(!0),s==null||s();let u;if(a.length>0){const m=new FormData;m.append("text",r.trim()),a.forEach(y=>m.append("attachments",y.originFileObj)),u=Y(`helpdesk/support/chats/${t}/messages`,m,{headers:{"Content-Type":"multipart/form-data"}})}else u=Y(`helpdesk/support/chats/${t}/messages`,{text:r.trim()});u.then(()=>{l(""),d([]),n()}).catch(m=>f(m)).finally(()=>o(!1))},c=r.trim()||a.length>0;return e.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${x.greyF[100]}`},children:[a.length>0&&e.jsx("div",{style:{marginBottom:8,display:"flex",flexWrap:"wrap",gap:4},children:a.map(u=>e.jsx(Me,{icon:e.jsx(st,{}),closable:!0,onClose:()=>d(m=>m.filter(y=>y.uid!==u.uid)),style:{margin:0},children:u.name},u.uid))}),e.jsxs("div",{style:{display:"flex",alignItems:"center",border:"1px solid #DDDDDE",borderRadius:8,overflow:"hidden",minHeight:80},children:[e.jsx(oa,{value:r,onChange:u=>l(u.target.value),placeholder:"Ответ пользователю...",autoSize:{minRows:3,maxRows:6},onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),p())},style:{flex:1,resize:"none",border:"none",boxShadow:"none",fontSize:14,padding:"12px 8px 12px 14px"},variant:"borderless"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"0 10px",flexShrink:0},children:[e.jsx(Dt,{fileList:a,onChange:({fileList:u})=>d(u),beforeUpload:()=>!1,showUploadList:!1,multiple:!0,children:e.jsx($,{icon:e.jsx(st,{}),type:"text",style:{color:x.greyF[600],width:44,height:44,fontSize:18}})}),e.jsx($,{shape:"circle",type:"primary",icon:e.jsx(hn,{}),onClick:p,loading:h,disabled:!c,style:{width:44,height:44,flexShrink:0,color:x.dark[500],fontSize:18}})]})]})]})}function ma({chat:t,onChatUpdated:n,profile:s,externalMsgTrigger:r,onMessageSent:l}){var Z,ce,T,W,A,D,H,q,g,v,F,M,z,P,G,de,ye;const[a,d]=i.useState(0),[h,o]=i.useState(!1),[f,p]=i.useState(null),c=i.useRef(0),u=i.useRef(!1),m=i.useRef(!1),y=i.useRef(t),j=i.useRef(n);i.useEffect(()=>{y.current=t},[t]),i.useEffect(()=>{j.current=n},[n]);const{showMessage:b,showRequestError:k}=B();i.useEffect(()=>{t&&(p(null),c.current=0,u.current=!1,m.current=!1,Y(`helpdesk/support/chats/${t.id}/mark-read`).then(()=>n()).catch(()=>{}),d(O=>O+1))},[t==null?void 0:t.id]),i.useEffect(()=>{if(r>0){const O=m.current;m.current=!1,!O&&!u.current&&c.current>0&&(p(c.current),u.current=!0),d(pt=>pt+1);const ue=y.current;ue&&Y(`helpdesk/support/chats/${ue.id}/mark-read`).then(()=>j.current()).catch(()=>{})}},[r]);const _=(O,ue)=>{o(!0),Y(`helpdesk/support/chats/${t.id}/${O}`).then(()=>{b(ue),n()}).catch(pt=>k(pt)).finally(()=>o(!1))},w=()=>{o(!0),Y(`helpdesk/support/chats/${t.id}/assign`,{assigned_to:s.wb_id}).then(()=>{b("Чат назначен на вас"),n()}).catch(O=>k(O)).finally(()=>o(!1))};if(!t)return e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:x.greyF[600],fontSize:14},children:"Выберите диалог из списка"});const C=t.status==="open",S=(Z=t.user)!=null&&Z.tg_username?`@${t.user.tg_username}`:(ce=t.user)!=null&&ce.first_name?`${t.user.first_name} ${t.user.last_name||""}`.trim():((T=t.user)==null?void 0:T.email)||"—",L=((W=t.user)==null?void 0:W.email)||"Email не указан",I=((A=t.assigned_to)==null?void 0:A.first_name)||((D=t.assigned_to)==null?void 0:D.email)||"Не назначен",N=(H=t.user)==null?void 0:H.wb_id,Q=((q=t.user)==null?void 0:q.license_key)||((g=t.user)==null?void 0:g.key),te=ua(((v=t.user)==null?void 0:v.license_active_to)||((F=t.user)==null?void 0:F.action_date)||((M=t.user)==null?void 0:M.valid_to)||((z=t.user)==null?void 0:z.expires_at)),E=((P=t.user)==null?void 0:P.devices)??((G=t.user)==null?void 0:G.devices_count)??((de=t.user)==null?void 0:de.devices_used),K=[N?{key:"wb_id",label:"WB ID",value:N}:null,Q?{key:"license",label:"Лицензионный ключ",value:Q,href:"/admin/users/license/"}:null,te?{key:"active_to",label:"Действует до",value:te}:null,E!=null?{key:"devices",label:"Устройств",value:E}:null].filter(Boolean);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minHeight:0},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${x.greyF[100]}`},children:[e.jsxs("div",{style:{background:"#F7F8FA",borderRadius:8,padding:"14px 16px",marginBottom:14},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,flexWrap:"wrap",marginBottom:K.length>0?10:16},children:[e.jsx(ee,{style:{fontSize:14,color:x.dark[500]},children:S}),e.jsx(ee,{style:{fontSize:14,color:x.dark[500]},children:L})]}),K.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:12,marginBottom:14},children:K.map((O,ue)=>e.jsxs(ee,{style:{fontSize:13,color:x.dark[500]},children:[ue>0?"| ":"",O.label,":",O.href?e.jsx("a",{href:O.href,target:"_blank",rel:"noopener noreferrer",style:{color:x.dark[500],textDecoration:"underline"},children:O.value}):O.value]},O.key))}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsxs(ee,{style:{fontSize:14,color:x.dark[500]},children:["Назначен: ",e.jsx(ee,{strong:!0,children:I})]}),((ye=t.assigned_to)==null?void 0:ye.wb_id)!==s.wb_id&&e.jsx($,{onClick:w,loading:h,style:{height:40,borderRadius:4,padding:"0 22px"},children:"Назначить себя"}),C?e.jsx($,{onClick:()=>_("close","Чат закрыт"),loading:h,style:{height:40,borderRadius:4,padding:"0 22px"},children:"Завершить диалог"}):e.jsx($,{type:"primary",onClick:()=>_("reopen","Чат переоткрыт"),loading:h,style:{height:40,borderRadius:4,padding:"0 22px",color:x.dark[500]},children:"Возобновить диалог"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",paddingBottom:2},children:[e.jsx("span",{style:{fontSize:20,fontWeight:500,color:x.dark[500],lineHeight:1.2},children:t.subject}),qn(t.status)]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto"},children:e.jsx(xa,{chatId:t.id,refreshKey:a,showDividerAfterMsgId:f,onMessagesLoaded:O=>{c.current=O}})}),C?e.jsx(ga,{chatId:t.id,onBeforeSend:()=>{l==null||l()},onSent:()=>{m.current=!0,p(null),u.current=!1,d(O=>O+1),n()}}):e.jsxs("div",{style:{padding:"24px 16px",borderTop:`1px solid ${x.greyF[100]}`,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx(ee,{style:{color:x.greyF[600],fontSize:14,display:"block"},children:"Этот диалог завершён"}),e.jsx(ee,{style:{color:x.greyF[600],fontSize:14,display:"block"},children:"Вы можете возобновить его"})]}),e.jsx($,{type:"primary",onClick:()=>_("reopen","Чат переоткрыт"),loading:h,style:{height:40,borderRadius:4,padding:"0 24px",fontSize:14,fontWeight:500,color:x.dark[500]},children:"Возобновить диалог"})]})]})}function ya(){const{profile:t,addPublicationHandler:n,removePublicationHandler:s}=xe(),{showRequestError:r}=B(),[l,a]=i.useState([]),[d,h]=i.useState(!0),[o,f]=i.useState(!1),[p,c]=i.useState(null),[u,m]=i.useState("all"),[y,j]=i.useState(""),[b,k]=i.useState(""),[_,w]=i.useState(0),[C,S]=i.useState(0),{notifyIncoming:L}=An(),I=i.useRef(!1),N=i.useRef(p);i.useEffect(()=>{N.current=p},[p]);const Q=i.useRef(!0);if(i.useEffect(()=>{Q.current=!0},[u,y]),i.useEffect(()=>{const T=W=>{W.key==="Escape"&&N.current&&c(null)};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]),i.useEffect(()=>{if(!t.auth)return;let T=!0;Q.current&&(h(!0),Q.current=!1);const W=pa(u,y);return V("helpdesk/support/chats",{params:W}).then(A=>{T&&a(A.data.results??A.data)}).catch(A=>{var D;T&&(((D=A==null?void 0:A.response)==null?void 0:D.status)===403?f(!0):r(A))}).finally(()=>T&&h(!1)),()=>{T=!1}},[t.auth,u,y,_]),i.useEffect(()=>{p&&l.length>0&&!l.find(T=>T.id===p)&&c(null)},[l]),i.useEffect(()=>{if(!t.auth)return;const T="helpdesk-support-page";return n(T,W=>{const{type:A,chat_id:D}=W.data??{};if(A){if((A==="chat.created"||A==="chat.updated"||A==="message.created")&&(w(H=>H+1),A==="message.created")){const H=I.current;I.current=!1,H||L(),D===N.current&&S(q=>q+1)}A==="chat.read"&&N.current}}),()=>s(T)},[t.auth,n,s]),i.useEffect(()=>{const T=setTimeout(()=>j(b),300);return()=>clearTimeout(T)},[b]),t.auth===void 0)return e.jsx(we,{});if(t.auth===!1)return e.jsx(dt,{});if(o)return e.jsx(we,{});const te=l.find(T=>T.id===p)??null,E=()=>w(T=>T+1),{resolution:K}=i.useContext(Ue),Z=K<=je.Tablet,ce=[{value:"all",label:"Все"},{value:"open",label:"Активные"},{value:"closed",label:"Завершенные"}];return e.jsxs("div",{style:{margin:"0 -24px -24px",height:"calc(100vh - 72px)",background:"#fff",display:"flex",fontFamily:"'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"},children:[e.jsxs("div",{style:{...Z?{display:p?"none":"flex",width:"100%"}:{display:"flex",width:"28%",minWidth:320,maxWidth:480},flexShrink:0,borderRight:Z?"none":`1px solid ${x.greyF[100]}`,flexDirection:"column",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"16px 16px 0"},children:[e.jsx("h2",{style:{margin:"0 0 16px",fontSize:32,fontWeight:400,color:x.dark[500],lineHeight:1.2},children:"Поддержка"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:16},children:e.jsx(J,{prefix:e.jsx(St,{style:{color:x.greyF[700]}}),placeholder:"Поиск",value:b,onChange:T=>k(T.target.value),allowClear:!0,onClear:()=>k(""),style:{flex:"1 1 160px",height:40,borderColor:"#DDDDDE",borderRadius:4,fontSize:14}})}),e.jsx("div",{style:{height:1,background:"#EFF1F5",marginBottom:16}}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",background:"#F7F8FA",border:"1px solid #EFF1F5",borderRadius:4,padding:"4px",gap:"4px",marginBottom:12},children:ce.map(T=>{const W=u===T.value;return e.jsx("button",{onClick:()=>{m(T.value),c(null)},style:{height:26,border:"none",borderRadius:2,background:W?x.primary[500]:"transparent",color:W?x.dark[500]:x.greyF[700],fontSize:12,fontWeight:W?500:400,cursor:"pointer",whiteSpace:"nowrap",outline:W?`1px solid ${x.primary[500]}`:"none"},children:T.label},T.value)})})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px",display:"flex",flexDirection:"column",gap:6},children:d?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:8},children:Array.from({length:6}).map((T,W)=>e.jsx(X,{active:!0,paragraph:{rows:2}},W))}):l.length===0?e.jsx("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12},children:e.jsx("span",{style:{fontSize:16,fontWeight:500,color:x.dark[500]},children:"Нет обращений по этому запросу"})}):l.map(T=>e.jsx(ha,{chat:T,selected:T.id===p,onClick:()=>c(T.id)},T.id))})]}),e.jsxs("div",{style:{...Z?{display:p?"flex":"none",width:"100%"}:{display:"flex",flex:1},flexDirection:"column",minWidth:0,height:"calc(100vh - 72px)",overflow:"hidden"},children:[Z&&p&&e.jsx("button",{onClick:()=>c(null),style:{display:"flex",alignItems:"center",gap:6,padding:"10px 16px",border:"none",borderBottom:`1px solid ${x.greyF[100]}`,background:"#fff",cursor:"pointer",fontSize:14,color:x.primary[500],fontWeight:500,flexShrink:0},children:"← Назад к диалогам"}),e.jsx(ma,{chat:te,onChatUpdated:E,profile:t,externalMsgTrigger:C,onMessageSent:()=>{I.current=!0}})]})]})}const ja=ds([{element:e.jsx(Bs,{}),path:"/",children:[{path:"/",index:!0,element:e.jsx(_s,{})},{path:"/auth/login",element:e.jsx(dt,{})},{path:"/auth/logout",element:e.jsx(Xr,{})},{path:"/auth/wblogin",element:e.jsx(Hl,{})},{path:"/auth/ext-auth",element:e.jsx(Rn,{})},{path:"/wb-id-sdk/callback",element:e.jsx(Al,{})},{path:"/profile",element:e.jsx(Qr,{})},{path:"/devices",element:e.jsx(Fn,{})},{path:"/campaigns/:campaignId/bidder",element:e.jsx(rr,{})},{path:"/campaigns/:campaignId",element:e.jsx(jr,{})},{path:"/campaigns",element:e.jsx(Ls,{})},{path:"/subjects/:subjectId",element:e.jsx(Ys,{})},{path:"/subjects",element:e.jsx(Zs,{})},{path:"/priority-subjects/:subjectId",element:e.jsx(qs,{})},{path:"/priority-subjects",element:e.jsx(Us,{})},{path:"/suppliers",element:e.jsx(xr,{})},{path:"/search-auction",element:e.jsx(Wr,{})},{path:"/external-analytics/niche-analysis/:subjectId",element:e.jsx(Ti,{})},{path:"/external-analytics/niche-analysis",element:e.jsx(gi,{})},{path:"/external-analytics/category-analysis",element:e.jsx(Bi,{})},{path:"/external-analytics/category-matrix",element:e.jsx(Ji,{})},{path:"/external-analytics/subject-matrix",element:e.jsx(cl,{})},{path:"/search-queries",element:e.jsx(Sl,{})},{path:"/search-queries/:query",element:e.jsx(Wl,{})},{path:"/wishes",element:e.jsx(Zl,{})},{path:"/helpdesk",element:e.jsx(aa,{})},{path:"/helpdesk-support",element:e.jsx(ya,{})}]}]);function va(){return e.jsx(us,{router:ja})}function ba(){return e.jsx(e.Fragment,{children:e.jsx(va,{})})}ps.createRoot(document.getElementById("root")).render(e.jsx(rn.StrictMode,{children:e.jsx(hs,{theme:gs,children:e.jsx(Tr,{children:e.jsx(js,{children:e.jsx(zs,{children:e.jsx(ba,{})})})})})}));