import{j as e,r as c,v as W,k as he,B as U,N as ee,W as Y,M as pe,V as te,G as de,U as ne}from"./index-DCzV2WLr.js";import{S as E}from"./Skeleton-CNHOJHEt.js";import{S as se}from"./SearchBar-mE_U2lco.js";import{I as Ee}from"./InputRadio-XY5dTGj9.js";import{S as Se,f as oe,p as ae}from"./formatters-D7xccmJZ.js";const Xe=()=>e.jsxs("li",{className:"vacancy__item","aria-hidden":"true",children:[e.jsxs("div",{className:"vacancy__item-header",children:[e.jsx(E,{width:"50%",height:"28px"}),e.jsx(E,{variant:"circle",width:"30px"})]}),e.jsxs("div",{className:"vacancy__info",style:{gap:"8px"},children:[e.jsx(E,{width:"30%",height:"16px"}),e.jsx(E,{width:"50%",height:"16px"}),e.jsx(E,{width:"60%",height:"16px"})]}),e.jsx(E,{width:"45%",height:"14px",style:{marginBottom:"16px"}}),e.jsx(E,{width:"100%",height:"40px"})]}),fe="_vacancyFilter_3e2nj_1",be="_filterTitle_3e2nj_6",ye="_filterLabel_3e2nj_11",ge="_desktopTitle_3e2nj_18",Ie="_mobileSheetGrabber_3e2nj_22",Ce="_closeIcon_3e2nj_26",Re="_filterHeader_3e2nj_30",ve="_mobileResetButton_3e2nj_37",Te="_vacancyFilter_mobile_3e2nj_47",xe="_mobileSheetHeader_3e2nj_54",Ne="_mobileSheetTitle_3e2nj_62",je="_buttonContainer_3e2nj_68",Fe="_filterButton_3e2nj_77",Oe="_mobileSheetCloseButton_3e2nj_88",ke="_mobileFilterScrollableContent_3e2nj_108",Be="_filterButton_mobileSticky_3e2nj_120",we="_desktopResetButton_3e2nj_137",Le="_resetFilterButton_3e2nj_143",s={vacancyFilter:fe,filterTitle:be,filterLabel:ye,desktopTitle:ge,mobileSheetGrabber:Ie,closeIcon:Ce,filterHeader:Re,mobileResetButton:ve,vacancyFilter_mobile:Te,mobileSheetHeader:xe,mobileSheetTitle:Ne,buttonContainer:je,filterButton:Fe,mobileSheetCloseButton:Oe,mobileFilterScrollableContent:ke,filterButton_mobileSticky:Be,desktopResetButton:we,resetFilterButton:Le},Pe=t=>{const o=Math.abs(t),m=o%10,a=o%100;return a>=11&&a<=19?"вакансий":m===1?"вакансию":[2,3,4].includes(m)?"вакансии":"вакансий"},le=t=>{var m,a,p;const o={};return t.searchField&&(o.searchField=t.searchField),t.city&&(o.city=t.city),t.company&&(o.company=t.company),t.income&&(o.salaryFrom=String(t.income)),t.sorting&&(o.sorting=t.sorting),t.employer_id&&(o.employer_id=t.employer_id),((m=t.experience)==null?void 0:m.length)>0&&(o.workingExperience=t.experience.map(u=>({no_experience:"EXPERIENCE_WITHOUT","1_3_years":"EXPERIENCE_1_TO_3_YEARS","3_6_years":"EXPERIENCE_3_TO_6_YEARS","6_plus_years":"EXPERIENCE_6_YEARS"})[u])),((a=t.schedule)==null?void 0:a.length)>0&&(o.workingSchedule=t.schedule.map(u=>({full_time:"WORKING_SCHEDULE_FULL_TIME",part_time:"WORKING_SCHEDULE_PART_TIME",internship:"WORKING_SCHEDULE_INTERNSHIP",watch:"WORKING_SCHEDULE_WATCH",project_work:"WORKING_SCHEDULE_PROJECT_WORK"})[u])),((p=t.format)==null?void 0:p.length)>0&&(o.officeType=t.format.map(u=>({office:"OFFICE_TYPE_OFFICE",hybrid:"OFFICE_TYPE_HYBRID",remote:"OFFICE_TYPE_REMOTE",field_work:"OFFICE_TYPE_FIELD_WORK"})[u])),o},Ae=t=>{const o=new URLSearchParams;return Object.entries(t).forEach(([m,a])=>{Array.isArray(a)?a.forEach(p=>o.append(`filter.${m}`,p)):a&&o.append(`filter.${m}`,a)}),o},$=t=>{t.preventDefault()},De=[{value:"no_experience",label:"Без опыта"},{value:"1_3_years",label:"От 1 года до 3 лет"},{value:"3_6_years",label:"От 3 до 6 лет"},{value:"6_plus_years",label:"Более 6 лет"}],He=[{value:"full_time",label:"Полная занятость"},{value:"part_time",label:"Частичная занятость"},{value:"internship",label:"Стажировка"},{value:"watch",label:"Вахта"},{value:"project_work",label:"Проектная работа"}],Ge=[{value:"office",label:"Офис"},{value:"hybrid",label:"Гибрид"},{value:"remote",label:"Удалённая работа"},{value:"field_work",label:"Полевая работа"}],We=[{value:"FILTER_SORTING_UNSPECIFIED",label:"По соответствию"},{value:"FILTER_SORTING_BY_DATE",label:"По дате изменения"},{value:"FILTER_SORTING_BY_SALARY_DESC",label:"По убыванию зарплаты"},{value:"FILTER_SORTING_BY_SALARY_ASC",label:"По возрастанию зарплаты"}],Me=c.forwardRef(({isMobileView:t=!1,onApplyFilters:o,onCloseMobileView:m,initialFilters:a={},baseFilters:p={},hideCompanyFilter:u=!1},g)=>{const[S,I]=c.useState(""),[C,B]=c.useState(""),[f,R]=c.useState(""),[v,w]=c.useState(""),[T,L]=c.useState("FILTER_SORTING_UNSPECIFIED"),[x,P]=c.useState([]),[N,A]=c.useState([]),[j,D]=c.useState([]),[re,F]=c.useState([]),[ce,O]=c.useState([]),K=W(S,500),V=W(f,500),[X,M]=c.useState(0),[J,q]=c.useState(!0),H=(n,l)=>{if(!n)return[];const r=Array.isArray(n)?n:[n],h=[],_=Object.fromEntries(Object.entries(l).map(d=>d.reverse()));return r.forEach(d=>{_[d]&&h.push(_[d])}),h};c.useEffect(()=>{I(a.searchField||""),B(a.city||""),R(a.company||""),w(a.salaryFrom||""),L(a.sorting||"FILTER_SORTING_UNSPECIFIED");const n={no_experience:"EXPERIENCE_WITHOUT","1_3_years":"EXPERIENCE_1_TO_3_YEARS","3_6_years":"EXPERIENCE_3_TO_6_YEARS","6_plus_years":"EXPERIENCE_6_YEARS"};P(H(a.workingExperience,n));const l={full_time:"WORKING_SCHEDULE_FULL_TIME",part_time:"WORKING_SCHEDULE_PART_TIME",internship:"WORKING_SCHEDULE_INTERNSHIP",watch:"WORKING_SCHEDULE_WATCH",project_work:"WORKING_SCHEDULE_PROJECT_WORK"};A(H(a.workingSchedule,l));const r={office:"OFFICE_TYPE_OFFICE",hybrid:"OFFICE_TYPE_HYBRID",remote:"OFFICE_TYPE_REMOTE",field_work:"OFFICE_TYPE_FIELD_WORK"};D(H(a.officeType,r))},[a]);const Q=c.useMemo(()=>{const n={...p};return S.trim()&&(n.searchField=S.trim()),C.trim()&&(n.city=C.trim()),f.trim()&&!u&&(n.company=f.trim()),v.trim()&&(n.income=v.trim()),x.length>0&&(n.experience=x),N.length>0&&(n.schedule=N),j.length>0&&(n.format=j),T!=="FILTER_SORTING_UNSPECIFIED"&&(n.sorting=T),n},[p,S,C,f,v,x,N,j,T,u]),z=W(JSON.stringify(Q),500);c.useEffect(()=>{(async()=>{const l=JSON.parse(z);q(!0);try{const r=le(l),h=Ae(r),_=await te.fetchTotalVacanciesCountWithQueryString(h.toString());M(_)}catch{M(0)}finally{q(!1)}})()},[z]),c.useEffect(()=>{if(u)return;(async()=>{const l=V.trim();if(l.length<2){O([]);return}try{const r=await de.listCompaniesWithSearch(l);if(r!=null&&r.companies){const h=r.companies.map(_=>({label:_.companyName||"",value:_.companyName||""}));O(h)}}catch{O([])}})()},[V,u]),c.useEffect(()=>{(async()=>{const l=K.trim();if(l.length<2){F([]);return}try{const[r,h,_]=await Promise.all([ne.fetchAvailableSkills(l),ne.fetchAvailablePersonalQualities(l),te.fetchVacancies({...p,searchField:l,pageSize:5})]),d=r.slice(0,3).map(i=>({label:i.skillName,value:i.skillName})),b=h.slice(0,3).map(i=>({label:i.qualityName,value:i.qualityName})),k=l.toLowerCase(),y=Array.from(new Set((_.vacancies||[]).map(i=>i.title).filter(i=>typeof i=="string"&&i.toLowerCase().includes(k)))).map(i=>({label:i,value:i}));F([...y,...d,...b])}catch(r){console.error("Error fetching suggestions for filter:",r),F([])}})()},[K,JSON.stringify(p)]);const Z=()=>{if(o){const n=le(Q);o(n)}};c.useImperativeHandle(g,()=>({applyFilters:Z}));const G=()=>{I(""),B(""),R(""),w(""),P([]),A([]),D([]),L("FILTER_SORTING_UNSPECIFIED")},ie=n=>{I(n.label),F([])},ue=n=>{R(n.label),O([])},_e=n=>{const l=n.target,{value:r,selectionStart:h}=l,_=r.substring(0,h??0),d=ae(_).length,b=ae(r);b.length>18||(w(b),setTimeout(()=>{const k=oe(b);let y=0,i=0;for(const me of k){if(i===d)break;y++,/[0-9]/.test(me)&&i++}l&&(l.value=k,l.setSelectionRange(y,y))},0))};return e.jsxs("div",{className:`${s.vacancyFilter} ${t?s.vacancyFilter_mobile:""}`,children:[t&&e.jsxs("div",{className:s.mobileSheetHeader,children:[e.jsx(Se,{className:s.mobileSheetGrabber}),e.jsx("button",{onClick:m,className:s.mobileSheetCloseButton,"aria-label":"Закрыть фильтры",children:e.jsx(he,{className:s.closeIcon})})]}),e.jsxs("div",{className:s.filterHeader,children:[e.jsx("h1",{className:`h1 ${s.desktopTitle}`,children:"Фильтры"}),e.jsx("h2",{className:`h2 ${s.mobileSheetTitle}`,children:"Фильтры"}),e.jsx(U,{variant:"rounded-outlined",className:s.desktopResetButton,onClick:G,children:"Сбросить"}),e.jsx("button",{onClick:G,className:`body-1 ${s.mobileResetButton}`,children:"Сбросить"})]}),e.jsxs("div",{className:t?s.mobileFilterScrollableContent:"",children:[e.jsx("h3",{className:`h3 ${s.filterTitle}`,children:"Ключевые слова"}),e.jsx(se,{placeholder:"Поиск вакансий по названию, сферам, ключевым навыкам",type:"reverse",filter:"none",noBtn:!0,value:S,searchIconWithBackground:!1,allowClear:!0,onInputValueChange:I,suggestions:re,onSuggestionSelect:ie}),e.jsxs("label",{className:`body-2 ${s.filterLabel}`,onClick:$,children:["Город",e.jsx(ee,{type:"text",name:"city",placeholder:"Москва",value:C,onInputValueChange:B,validation:!0,validationType:"textOnly"})]}),!u&&e.jsxs("label",{className:`body-2 ${s.filterLabel}`,onClick:$,children:["Компания",e.jsx(se,{placeholder:"Компания",type:"reverse",filter:"none",noBtn:!0,value:f,searchIconWithBackground:!1,allowClear:!0,onInputValueChange:R,suggestions:ce,onSuggestionSelect:ue})]}),e.jsxs("label",{className:`body-2 ${s.filterLabel}`,onClick:$,children:["Уровень дохода от",e.jsx(ee,{type:"text",name:"income",placeholder:"100 000 ₽",value:oe(v),onChange:_e,validation:!0})]}),e.jsx("h3",{className:`h3 ${s.filterTitle}`,children:"Опыт работы"}),e.jsx(Y,{name:"experience",options:De,value:x,onChange:P,type:t?"mobile":"classic"}),e.jsx("h3",{className:`h3 ${s.filterTitle}`,children:"График работы"}),e.jsx(Y,{name:"schedule",options:He,value:N,onChange:A,type:t?"mobile":"classic"}),e.jsx("h3",{className:`h3 ${s.filterTitle}`,children:"Формат"}),e.jsx(Y,{name:"format",options:Ge,value:j,onChange:D,type:t?"mobile":"classic"}),e.jsx("h3",{className:`h3 ${s.filterTitle}`,children:"Сортировка"}),e.jsx(Ee,{name:"sorting",options:We,value:T,onChange:L})]}),e.jsxs("div",{className:s.buttonContainer,children:[e.jsx(U,{type:"button",className:`${s.filterButton} ${t?s.filterButton_mobileSticky:""}`,onClick:Z,disabled:J,children:J?e.jsx(pe,{size:"small"}):`Показать ${X} ${Pe(X)}`}),e.jsx(U,{onClick:G,className:s.resetFilterButton,variant:"outlined",children:"Сбросить"})]})]})});export{Me as V,Xe as a};