1import{r as n,j as l}from"./app-DoaXZv-P.js";import{d as Z}from"./debounce-DDTPCSXT.js";import{A as J,S as Q}from"./config-DpGUFdYL.js";import de from"./InlineSelect-rRujcXXf.js";import Me from"./SourceSelector-DDzw3WsB.js";import{CrossIcon as Ae}from"./svg-tbklvPv8.js";import Te from"./PrefilledAutoWidthInput-CYdlts1L.js";import _e from"./RequiredFieldsBanner-qYKJK6MR.js";import{u as $e}from"./useRequiredFieldsValidation-BipS8sIr.js";import{i as A,b as we}from"./inlineValidation-BRY-SvzL.js";import{s as xe,O as Ve,f as Pe}from"./fetchOrganizationBooks-DrV4Xh1Z.js";import{s as a}from"./aiAssistant.module-C8LuTZr5.js";import"./roles.types-E2dAPaKE.js";import"./AutoWidthInput-DUSQwmUw.js";import"./prefilledInput-BGWOu7mO.js";import"./ManualBooksWithChapters-BUkRIVNd.js";import"./BookSearchOption-Boh9alga.js";import"./utils-DNRMjIiI.js";import"./search.api-BXd3cqBj.js";import"./search.payload-BPQmPT1S.js";import"./search.types-B70f2CFi.js";import"./entities.types-CAAeLS-h.js";const m="название ÑемÑ";function cs({onSearch:me}){const[g,X]=n.useState(m),[T,ee]=n.useState(J[0]),[Se,B]=n.useState(!1),_=n.useRef(null),[$,w]=n.useState(null),[he,u]=n.useState([]),[x,C]=n.useState(!1),[be,se]=n.useState(!1),[D,j]=n.useState(""),[V,P]=n.useState(null),[ke,O]=n.useState([]),[N,ge]=n.useState([]),[F,E]=n.useState(!1),[Oe,te]=n.useState(!1),[L,y]=n.useState(""),[S,q]=n.useState(Q[0]),[ne,M]=n.useState(!1),[h,R]=n.useState([null]),[Re,b]=n.useState([""]),[ve,c]=n.useState([[]]),[v,p]=n.useState(null),[Ie,k]=n.useState([!1]),[Be,f]=n.useState([null]),[oe,le]=n.useState(null),{showRequiredFieldsError:U,requiredFieldsMessage:Ce,triggerRequiredFieldsError:De,clearRequiredFieldsError:I}=$e(),H=n.useRef(null),W=n.useRef(null),z=n.useRef(null),je=n.useRef(null),Ne=n.useRef(null),G=n.useRef(null),ae=n.useCallback(async e=>{var o;if(!e.trim()){u([]);return}se(!0);try{const t=new URLSearchParams;t.append("name",e),t.append("limit","10");const i=await(await fetch(`/classifiers/disciplines/get?${t.toString()}`)).json();i.success&&((o=i.data)!=null&&o.disciplines)?u(i.data.disciplines.map(d=>({value:d.id.toString(),label:d.name}))):u([])}catch{u([])}finally{se(!1)}},[]),K=n.useMemo(()=>Z(ae,300),[ae]);n.useEffect(()=>(x&&D&&K(D),()=>{K.cancel()}),[D,x,K]);const ie=n.useCallback(async()=>{var e;if(!(N.length>0)){te(!0);try{const t=await(await fetch("/classifiers/profiles/get")).json();t.success&&((e=t.data)!=null&&e.profiles)&&ge(t.data.profiles.map(s=>({value:s.id.toString(),label:s.code?`${s.code} ${s.name}`:s.name})))}catch{}finally{te(!1)}}},[N.length]),re=n.useCallback(e=>{if(!e.trim()){O([]);return}const o=e.toLowerCase();O(N.filter(t=>t.label.toLowerCase().includes(o)).slice(0,10))},[N]),Y=n.useMemo(()=>Z(re,150),[re]);n.useEffect(()=>(F&&L&&Y(L),()=>{Y.cancel()}),[L,F,Y]),n.useEffect(()=>{ie()},[ie]);const ce=n.useCallback(async(e,o)=>{if(!e.trim()){c(t=>{const s=[...t];return s[o]=[],s}),f(t=>{const s=[...t];
1return s[o]=null,s});return}k(t=>{const s=[...t];return s[o]=!0,s}),f(t=>{const s=[...t];return s[o]=null,s});try{const t=await xe(e);if(t===null)return;c(s=>{const i=[...s];return i[o]=t,i})}catch(t){c(s=>{const i=[...s];return i[o]=[],i}),f(s=>{const i=[...s];return i[o]=(t==null?void 0:t.message)||"Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ ÐºÐ°Ñалог",i})}k(t=>{const s=[...t];return s[o]=!1,s})},[]),Ee=n.useMemo(()=>Z((e,o)=>ce(e,o),Ve),[ce]);n.useEffect(()=>{const e=o=>{const t=o.target;_.current&&!_.current.contains(t)&&B(!1),H.current&&!H.current.contains(t)&&C(!1),W.current&&!W.current.contains(t)&&E(!1),z.current&&!z.current.contains(t)&&M(!1),G.current&&!G.current.contains(t)&&p(null)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]);const ue=()=>{X(m),ee(J[0]),B(!1),w(null),j(""),C(!1),u([]),P(null),y(""),E(!1),O([]),q(Q[0]),M(!1),R([null]),b([""]),c([[]]),k([!1]),f([null]),p(null),le(null),I()},Le=e=>{e.preventDefault(),le(null);const o=A(g,m),t=S.value==="manual"&&h.filter(Boolean).length<1;if(o||t){const r=[];o&&r.push({field:"Ñема",kind:"text"}),t&&r.push({field:"книги",kind:"books"}),De(we(r));return}I();const s=h.filter(Boolean).map(r=>r.value).map(r=>{const fe=Number(r);return Number.isFinite(fe)?fe:r}),i=S.value==="manual"?` вÑбÑаннÑÑ
вÑÑÑнÑÑ: ${h.filter(Boolean).map(r=>Pe(r)).join(", ")}`:" ÑекомендÑемÑÑ
";let d=`ÐÑоведи глÑбокое иÑÑледование и ÑоÑÑÐ°Ð²Ñ ÑÑÑÑкÑÑÑÑ ÑÑаÑÑи по Ñеме «${g.trim()}», Ñип ÑÑаÑÑи ${T.label}`;$&&(d+=`, по диÑÑиплине «${$.label}»`),V&&(d+=` Ð´Ð»Ñ Ð½Ð°Ð¿ÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ð´Ð³Ð¾Ñовки «${V.label}»`),d+=`, Ñ Ð¸ÑполÑзованием иÑÑоÑников${i}`,me(d,{source_mode:S.value==="manual"?"manual":"recommended",...S.value==="manual"?{selected_book_ids:s}:{}}),ue()},pe=U&&A(g,m),ye=U&&S.value==="manual"&&h.filter(Boolean).length<1;return l.jsxs("div",{className:a.bookSearchContainer,children:[U&&l.jsx(_e,{message:Ce}),l.jsxs("div",{className:`${a.bookSearchInput} ${a.bookSearchInputFilled} ${a.curriculumInput}`,children:[l.jsxs("div",{className:a.bookInputContent,children:[l.jsx("span",{className:a.bookLabel,children:"ÐÑоведи глÑбокое иÑÑледование и ÑоÑÑÐ°Ð²Ñ ÑÑÑÑкÑÑÑÑ ÑÑаÑÑи по Ñеме"})," ",l.jsx(Te,{type:"text",className:`${a.bookInlineInput} ${pe?a.bookInlineInputInvalid:""}`,placeholder:m,invalid:pe,value:g,onValueChange:e=>{X(e),A(e,m)||I()}}),l.jsx("span",{className:a.bookLabel,children:", Ñип ÑÑаÑÑи"})," ",l.jsxs("div",{ref:_,className:a.curriculumSelectWrapper,children:[l.jsx("button",{type:"button",className:a.sourceSelectBtn,onClick:()=>B(e=>!e),children:T.label}),Se&&l.jsx("div",{className:a.chapterDropdown,children:J.map(e=>l.jsx("button",{type:"button",className:`${a.bookOption} ${T.value===e.value?a.bookOptionActive:""}`,onClick:()=>{ee(e),B(!1)},children:l.jsx("div",{className:a.bookOptionTitle,children:e.label})},e.value))})]}),l.jsx("span",{className:a.bookLabel,children:", по диÑÑиплине"})," ",l.jsx(de,{selected:$,options:he,isOpen:x,isLoading:be,searchValue:D,placeholder:"название диÑÑиплинÑ",emptyMessage:"ÐиÑÑÐ¸Ð¿Ð»Ð¸Ð½Ñ Ð½Ðµ найденÑ",onSearchChange:j,onOpen:()=>C(!0),onSelect:e=>{w(e),C(!1),j(""),u([])},onClear:()=>{w(null),j(""),u([])},wrapperRef:H,inputRef:je}),l.jsx("span",{className:a.bookLabel,children:" Ð´Ð»Ñ Ð½Ð°Ð¿ÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ð´Ð³Ð¾Ñовки"})," ",l.jsx(de,{selected:V,options:ke,isOpen:F,isLoading:Oe,searchValue:L,placeholder:"название напÑавлениÑ",emptyMessage:"ÐапÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð½Ðµ найденÑ",onSearchChange:y,onOpen:()=>E(!0),onSelect:e=>{P(e),E(!1),y(""),O([])},onClear:()=>{P(null),y(""),O([])},wrapperRef:W,inputRef:Ne}),l.jsx(Me,{source:S,isSourceSelectOpen:ne,onToggleSourceSelect:()=>M(!ne),onSelectSource:e=>{q(e),M(!1),e.value!=="manual"&&I()},sourceSelectRef:z,withChapters:!1,invalidManualBooks:ye,manualBooksSimple:{books:h,searchValues:Re,options:ve,activeIndex:v,isLoading:Ie,searchErrors:Be,containerRef:G,onSearchChange:(e,o)=>{b(t=>{const s=[...t];return s[e]=o,s}),Ee(o,e)},onOpen:e=>p(e),onSelect:(e,o)=>{R(t=>{const s=[...t];return s[e]=o,s}),q(Q[1]),p(null),b(t=>{const s=[...t];return s[e]="",s}),c(t=>{const s=[...t];return s[e]=[],s}),A(g,m)||I()},onRemove:e=>{if(h.length<=1){R([null]),b([""]),c([[]]),k([!1]),f([null]),p(null);return}R(o=>o.filter((t,s)=>s!==e)),b(o=>o.filter((t,s)=>s!==e)),c(o=>o.filter((t,s)=>s!==e)),k(o=>o.filter((t,s)=>s!==e)),f(o=>o.filter((t,s)=>s!==e)),v===e?p(null):v!==null&&v>e&&p(v-1)},onAdd:()=>{R(e=>[...e,null]),b(e=>[...e,""]),c(e=>[...e,[]]),k(e=>[...e,!1]),f(e=>[...e,null])}}})]}),l.jsxs("div",{className:a.bookActions,children:[oe&&l.jsx("p",{className:a.errorText,children:oe}),l.jsxs("button",{type:"button",className:a.resetBtn,onClick:ue,children:[l.jsx(Ae,{className:a.resetIcon}),"СбÑоÑиÑÑ"]}),l.jsx("button",{type:"button",className:a.searchBtn,onClick:Le,children:"ÐайÑи"})]})]})]})}export{cs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.