1import{cf as e,t as D,cx as c,aU as k,ab as G,b3 as z,S as K,U as F,v as T,H as U}from"./PopupSearchContainer-Bwfwi4m3.js";import{A as Q}from"./Add-DVIHkdXl.js";import{C as J}from"./Container-CqsLAxSd.js";import{P as X}from"./PageHeader-BSGYLAEH.js";import{M as E,N as O,H as Y,u as Z,L as ee,v as te,e as ne}from"./tenant-DjAq54Gx.js";import{c1 as H,ac as se,b$ as re,u as W,aG as ae,aJ as I,bU as oe,bP as ie,c9 as w,aH as le,c0 as ce,bx as de,s as me,a1 as ue,M as he,k as B,n as N,m as q,N as fe,R as pe,Q as P,o as xe}from"./ErrorBoundary-CeAh1tMp.js";import{L as A}from"./LightTooltip-DTvNlwmj.js";import{D as V}from"./Delete-DDxDFRrD.js";import{d as ye,h as S}from"./TextField-BODc6iyq.js";import{a as je,u as ge,b as Ce,c as Se,s as be,D as ve}from"./syncColumnsWithState-B_TubX5h.js";import{T as De,g as R}from"./ThreeButtonsIcon-CsdqaFt2.js";import{C as we}from"./Chip-B7o5Mwv3.js";import{C as Me}from"./Card-DYLNolAN.js";import"./SearchForm-DHajHEfb.js";import"./Grow-BoCZ4eQG.js";import"./generateUtilityClasses-D_-ZXuKL.js";import"./Autocomplete-BsIXq69v.js";import"./pluralize-CM9OE0TL.js";import"./ConfirmDialog-CgMo_Ngg.js";import"./InputAdornment-DWEXqx_9.js";import"./Checkbox-BlCjR0RB.js";import"./FormControlLabel-Bg2LYzli.js";import"./TablePagination-X5Luk4Kf.js";import"./KeyboardArrowRight-CFnsN3Rh.js";import"./LastPage-mrKLI79A.js";import"./TableCell-Bis8gKqQ.js";const L=({name:l,placeholder:n,onKeyDown:t,inputRef:s})=>{const{setValue:i,getFieldState:r,watch:a}=H(),{error:d}=r(l),m=a(l),u=o=>{t&&t(o)};return e.jsx(D,{sx:{flex:1},children:e.jsx(D,{children:e.jsx(se,{fullWidth:!0,placeholder:n??"",error:!!d,onChange:o=>{i(l,o.target.value)},onKeyDown:u,helperText:d?.message??"",value:m??"",inputRef:s})})})},Fe=({errorMessage:l})=>{const{control:n,setValue:t,watch:s,register:i}=H(),r="temp_synonym",a=c.useRef(null),{fields:d,append:m,remove:u}=re({control:n,name:"synonyms"}),o=s(r),p=()=>{o?.trim()&&(m(o.trim()),t(r,""),setTimeout(()=>{a.current&&a.current.focus()},0))},y=g=>{g.key==="Enter"&&(g.preventDefault(),p())},j=g=>{u(g)};return c.useEffect(()=>{t(r,""),i(r)},[t,i]),e.jsxs(D,{children:[e.jsx(k,{variant:"subtitle1",sx:{mb:1},children:"СинонимÑ"}),l&&e.jsx(ye,{sx:{mb:2},error:!0,children:l}),e.jsxs(S,{spacing:2,children:[d.map((g,x)=>e.jsxs(S,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(L,{placeholder:"",name:`synonyms[${x}]`}),e.jsx(A,{title:"УдалиÑÑ",children:e.jsx(G,{onClick:()=>{j(x)},sx:{"&:hover":{color:h=>h.palette.error.main,bgcolor:h=>z(h.palette.error.main,.1)}},children:e.jsx(V,{fontSize:"small"})})})]},x)),e.jsxs(S,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(L,{placeholder:"ÐобавÑÑе Ñиноним",name:r,onKeyDown:y,inputRef:a}),e.jsx(A,{title:"ÐобавиÑÑ Ñиноним",children:e.jsx(G,{onClick:p,children:e.jsx(W,{icon:"eva:plus-fill",width:20,height:20})})})]})]})]})};oe(ie);const Re={word:I().label("Слово").required(),synonyms:ae().label("СинонимÑ").of(I().label("Синоним").max(512).required().trim())},$=({isEdit:l,isProcessing:n,goToBackPage:t,currentSynonym:s,saveData:i,formErrors:r})=>{const{enqueueSnackbar:a}=w(),d=le().shape(Re),m=c.useMemo(()=>s,[s]),u=ce({resolver:de(d),defaultValues:m}),{handleSubmit:o,setError:p,formState:{errors:y,isSubmitting:j}}=u;c.useEffect(()=>{if(r){if(!r.violations){a(K,{variant:"error"});return}Object.entries(r.violations).forEach(([x,h])=>{const b=Array.isArray(h)?h:[h];p(x,{type:"custom",message:b[0]})})}},[a,r,p]);const g=x=>{i(x)};return e.jsxs(me,{methods:u,onSubmit:o(g),children:[e.jsxs(F,{container:!0,spacing:3,children:[e.jsx(F,{item:!0,xs:12,md:12,children:e.jsx(ue,{name:"word",label:"Слово",fullWidth:!0,sx:{mt:1}})}),e.jsx(F,{item:!0,xs:12,md:12,children:e.jsx(Fe,{addItemLabelButton:"ÐобавиÑÑ Ñиноним",errorMessage:y?.synonyms?.message??""})})]}),e.jsxs(S,{justifyContent:"flex-end",direction:"row",spacing:2,sx:{mt:3,mb:3},children:[t&&e.jsx(T,{variant:"outlined",color:"inherit",disabled:n||j,onClick:t,children:"ÐÑмена"}),e.jsx(he,{variant:"contained",loading:n||j,onClick:o(g),children:l?"СоÑ
ÑаниÑÑ":"ÐобавиÑÑ"})]})]})},ke=({open:l,onClose:n,onSuccess:t})=>{const{enqueueSnackbar:s}=w(),i=E(),{isLoading:r,error:a}=O(m=>m.synonym),d=c.useCallback(m=>{(async o=>{i(Y(o)).then(p=>{p&&(s("Слово добавлено",{variant:"success"}),n(),t&&t())})})(m)},[i,s,n,t]);return e.jsxs(B,{open:l,onClose:n,fullWidth:!0,maxWidth:"sm",children:[e.jsx(N,{children:"ÐобавиÑÑ Ñиноним"}),e.jsx(q,{children:e.jsx($,{formErrors:a,isEdit:!1,isProcessing:r,saveData:d,goToBackPage:n})})]})},Ee=({open:l,onClose:n,synonymId:t,onSuccess:s})=>{const{enqueueSnackbar:i}=w(),r=E(),{synonym:a,isLoading:d,error:m}=O(o=>o.synonym);c.useEffect(()=>{l&&t&&r(Z(t))},[r,t,l]);const u=c.useCallback(o=>{(async y=>{r(ee(t,y)).then(j=>
1{j&&(i("Слово обновлено",{variant:"success"}),n(),s&&s())})})(o)},[r,t,i,n,s]);return e.jsxs(B,{open:l,onClose:n,fullWidth:!0,maxWidth:"sm",children:[e.jsx(N,{children:"РедакÑиÑоваÑÑ Ñиноним"}),e.jsxs(q,{children:[!a&&e.jsx(fe,{}),a&&e.jsx($,{formErrors:m,isEdit:!0,isProcessing:d,saveData:u,goToBackPage:n,currentSynonym:a})]})]})};function Oe({onEditRow:l,handleDeleteAfterConfirm:n}){const[t,s]=c.useState(!1),[i,r]=c.useState(null),a=()=>{s(!0)},d=()=>{s(!1)},m=o=>{r(o.currentTarget)},u=()=>{r(null)};return e.jsxs(e.Fragment,{children:[e.jsx(De,{title:"ÐейÑÑвиÑ",openPopover:i,handleOpenPopover:m}),e.jsxs(pe,{open:i,onClose:u,arrow:"right-top",sx:{width:140,color:o=>o.palette.mode==="light"?"grey.600":"grey.400"},children:[e.jsxs(P,{onClick:()=>{l(),u()},children:[e.jsx(W,{icon:"eva:edit-fill"}),"ÐзмениÑÑ"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx(xe,{}),e.jsxs(P,{onClick:()=>{a(),u()},sx:{color:"error.main"},children:[e.jsx(V,{}),"УдалиÑÑ"]})]})]}),e.jsx(je,{title:"УдалиÑÑ Ñлово?",content:e.jsx(k,{sx:{color:"text.secondary"},children:"Слово и вÑе ÑÐ¸Ð½Ð¾Ð½Ð¸Ð¼Ñ Ðº Ð½ÐµÐ¼Ñ Ð±ÑдÑÑ ÑдаленÑ"}),setOpenConfirm:o=>{s(o)},openConfirm:t,handleOnConfirmDelete:()=>{d(),n&&n()}})]})}const Ge={columns:{columnVisibilityModel:{id:!1}}},Ie=({handleEditRow:l},n)=>{const{state:t,isStateInit:s,paginationModel:i,setPaginationModel:r,queryOptions:a,handleFilterChange:d,handleSortModelChange:m,saveDataGridState:u}=ge(Ge),{enqueueSnackbar:o}=w(),p=Ce(),{synonyms:y,pagination:j,isLoading:g}=O(C=>C.synonym),x=E(),h=c.useCallback(async(C,f)=>{await x(te({page:{currentPage:Math.max(f.page,0)+1,perPage:f.pageSize},...C}))},[x]);c.useImperativeHandle(n,()=>({refreshData:()=>{h(a,i)}}));const b=c.useCallback(async C=>{x(ne(C)).then(f=>{f&&(o("Слово Ñдалено",{variant:"success"}),h(a,i))})},[x,h,a,i]),M=c.useMemo(()=>{const C=[{field:"id",headerName:"ID",filterOperators:R(),renderCell:f=>e.jsx(e.Fragment,{children:f.row.id})},{field:"word",headerName:"Слово",flex:1,filterOperators:R(),renderCell:f=>e.jsx(e.Fragment,{children:f.row.word})},{field:"synonyms",headerName:"Синоним",flex:2,filterOperators:R(),renderCell:f=>e.jsx(e.Fragment,{children:f.row.synonyms.map(v=>e.jsx(we,{sx:{marginRight:"16px"},variant:"outlined",label:v},v))})},{field:"action",type:"actions",headerName:" ",align:"right",width:80,sortable:!1,filterable:!1,disableColumnMenu:!0,renderCell:f=>{const v=()=>b(f.row.id);return e.jsx(Oe,{onEditRow:()=>{l(f.row.id)},handleDeleteAfterConfirm:v})},hideable:!1}];return Se(C)},[l,b]),_=c.useMemo(()=>{if(s)return be(t,M)},[s,t,M]);return c.useEffect(()=>{s&&h(a,i)},[s,a,i,h]),s?e.jsx(ve,{apiRef:p,loading:g,columns:M,initialState:_,rows:y||[],rowCount:j.total??0,rowHeight:60,showQuickFilter:!1,onFilterModelChange:d,onSortModelChange:m,paginationModel:i,setPaginationModel:r,stateChangeHandler:C=>{u(C)},disableColumnSorting:!0,disableColumnFilter:!0,disableColumnMenu:!0,disableDensitySelector:!0,disableColumnSelector:!0,zebraMode:!0}):e.jsx(S,{sx:{p:"2rem"},direction:"row",justifyContent:"center",children:e.jsx(U,{})})},Pe=c.forwardRef(Ie),Ae=({handleEditRow:l},n)=>{const t=c.useRef(null);return c.useImperativeHandle(n,()=>({refreshData:()=>{t.current&&t.current.refreshData()}})),e.jsx(Pe,{handleEditRow:l,ref:t})},Le=c.forwardRef(Ae);function ct(){const[l,n]=c.useState(!1),[t,s]=c.useState(!1),[i,r]=c.useState(""),a=c.useRef(null),d="СинонимÑ",m=()=>{n(!0)},u=()=>{n(!1)},o=j=>{r(j),s(!0)},p=()=>{s(!1)},y=()=>{a.current&&a.current.refreshData()};return e.jsx(e.Fragment,{children:e.jsxs(J,{children:[e.jsx(X,{title:d}),e.jsxs(D,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[e.jsx(k,{variant:"h4",children:d}),e.jsx(T,{variant:"contained",startIcon:e.jsx(Q,{}),onClick:m,children:"ÐобавиÑÑ Ñиноним"})]}),e.jsx(Me,{children:e.jsx(Le,{handleEditRow:o,ref:a})}),e.jsx(ke,{open:l,onClose:u,onSuccess:y}),e.jsx(Ee,{open:t,onClose:p,synonymId:i,onSuccess:y})]})})}export{ct 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.