1import{r as p,j as e,A,n,S as R}from"./app-vjiAmbD7.js";import{B as g,D as P}from"./dashboardLayout-C5e_Sh5d.js";import{D as S}from"./dialog.esm-D2KGmk3Q.js";import{f as G,g as H,h as O,i as U}from"./queries-Dv3lOL5w.js";import{D as W,C as x}from"./column.esm-CW47ZH1Q.js";import{C as $,c as K}from"./confirmdialog.esm-DGUyGJJz.js";import{T as b}from"./tag.esm-B3h_iv_e.js";import{C as f}from"./checkbox.esm-Ct0pw4k8.js";import{I as Q}from"./inputnumber.esm-BXe_tu-R.js";import{I as q}from"./inputtext.esm-CzYhL0nZ.js";import{M as z}from"./multiselect.esm-CvrR5nn5.js";import{a as J}from"./roles.api-BMekMYy1.js";import"./ScrollToTopButton--FoKvnl3.js";import"./useAuth-k1BkeSQG.js";import"./logo-BO4ZkFZy.js";/* empty css */import"./roles.types-CcPEwc3b.js";import"./csstransition.esm-pa3sXKLA.js";import"./setPrototypeOf-SZTCiYDs.js";import"./index.esm-CTJTJ3r3.js";import"./index.esm-Bq3QXLRZ.js";import"./overlayservice.esm-DDj4nrlw.js";import"./index.esm-BjQWSvAl.js";import"./index.esm-DB_vBYbq.js";import"./keyfilter.esm-BaTlbvln.js";import"./index.esm-jNN1BPik.js";import"./createEntityAdapter-DDq-tnWI.js";const j=()=>({title:"",sort_order:0,is_for_all:!1,is_public:!1,is_published:!1,role_ids:[]}),F=({form:s,onChange:r})=>{const{data:i,isLoading:c}=J(),d=((i==null?void 0:i.options)??[]).map(l=>({label:l.label,value:Number(l.value)})),a=(l,o)=>{r({...s,[l]:o})};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Ðазвание Ñаздела *"}),e.jsx(q,{value:s.title,onChange:l=>a("title",l.target.value),placeholder:"ÐапÑимеÑ: ÐÐ»Ñ Ð²ÑеÑ
полÑзоваÑелей",className:"w-full bg-gray-100"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"ÐоÑÑдок (ÑанжиÑование) *"}),e.jsx(Q,{value:s.sort_order,onValueChange:l=>a("sort_order",l.value??0),min:0,className:"w-full",inputClassName:"w-full bg-gray-100"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{inputId:"is_for_all",checked:s.is_for_all,onChange:l=>{const o=l.checked??!1;r({...s,is_for_all:o,role_ids:o?[]:s.role_ids})}}),e.jsx("label",{htmlFor:"is_for_all",className:"text-sm text-gray-700",children:"ÐÐ»Ñ Ð²ÑеÑ
Ñолей"})]}),!s.is_for_all&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Роли *"}),e.jsx(z,{value:s.role_ids,options:d,onChange:l=>a("role_ids",l.value??[]),placeholder:"ÐÑбеÑиÑе Ñоли",display:"chip",className:"w-full",loading:c,filter:!0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{inputId:"is_public",checked:s.is_public,onChange:l=>a("is_public",l.checked??!1)}),e.jsx("label",{htmlFor:"is_public",className:"text-sm text-gray-700",children:"ÐоÑÑÑпно без авÑоÑизаÑии"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{inputId:"is_published",checked:s.is_published,onChange:l=>a("is_published",l.checked??!1)}),e.jsx("label",{htmlFor:"is_published",className:"text-sm text-gray-700",children:"ÐпÑбликован"})]})]})},X=s=>{var r;return{title:s.title,sort_order:s.sort_order,is_for_all:s.is_for_all,is_public:s.is_public,is_published:s.is_published,role_ids:((r=s.roles)==null?void 0:r.map(i=>i.id))??[]}},I=({initial:s}={})=>{const[r,i]=p.useState(s??j());return p.useEffect(()=>{s&&i(s)},[s]),{form:r,setForm:i,reset:()=>i(j())}},Y=()=>{var w;const[s,r]=p.useState({}),{data:i,isLoading:c}=G(s),d=((w=i==null?void 0:i.data)==null?void 0:w.sections)??[],a=!!s.title,l=t=>{r(h=>({...h,title:t.trim()||void 0}))},o=()=>{r({})},[E,u]=p.useState(!1),[y,v]=p.useState(null),{form:m,setForm:N}=I(),_=H(),D=t=>{v(t),N(X(t)),u(!0)},T=()=>{if(!(!y||!m.title.trim())){if(!m.is_for_all&&m.role_ids.length===0){n({type:"error",message:"ÐÑбеÑиÑе Ñ
оÑÑ Ð±Ñ Ð¾Ð´Ð½Ñ ÑÐ¾Ð»Ñ Ð¸Ð»Ð¸ вклÑÑиÑе «ÐÐ»Ñ Ð²ÑеÑ
Ñолей»"});return}_.mutate({sectionId:y.id,body:{...m,title:m.title.trim()}},{onSuccess:()=>{n({type:"success",message:"Раздел обновлÑн"}),u(!1),v(null)},onError:()=>{n({type:"error",message:"ÐÑибка пÑи обновлении"})}})}},L=O(),M=t=>{K({message:`УдалиÑÑ Ñаздел «${t.title}» и вÑе его ÑÑаÑÑи?`,header:"ÐодÑвеÑждение ÑдалениÑ",icon:"pi pi-exclamation-triangle",acceptLabel:"УдалиÑÑ",rejectLabel:"ÐÑмена",acceptClassName:"p-button-danger mx-3",accept:()=>{L.mutate(t.id,{onSuccess:()=>{n({type:"success",message:"Раздел ÑдалÑн"})},onError:()=>{n({type:"error",message:"ÐÑибка пÑи Ñдалении"})}})}})},B=t=>{var h;return t.is_for_all?e.jsx(b,{value:"ÐÐ»Ñ Ð²ÑеÑ
",severity:"info"}):(h=t.roles)!=null&&h.length?e.jsx("div",{className:"flex flex-wrap gap-1",children:t.roles.map(k=>e.jsx(b,{value:k.name,severity:"secondary"},k.id))}):e.jsx("span",{className:"text-gray-400",children:"â"})},C=t=>t?e.jsx(b,{value:"Ðа",severity:"success"}):e.jsx(b,{value:"ÐеÑ",severity:"warning"}),V=t=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>A.visit(`/dashboard/instructions/${t.id}/articles`),className:"text-blue-600 hover:text-blue-800 transition-colors p-1.5 rounded hover:bg-blue-50",title:"СÑаÑÑи",children:e.jsx("i",{className:"pi pi-file-edit text-sm"})}),e.jsx("button",{type:"button",onClick:()=>D(t),className:"text-amber-600 hover:text-amber-800 transition-colors p-1.5 rounded hover:bg-amber-50",title:"РедакÑиÑоваÑÑ",children:e.jsx("i",{className:"pi pi-pencil text-sm"})}),e.jsx("button",{type:"button",onClick:()=>M(t),className:"text-red-600 hover:text-red-800 transition-colors p-1.5 rounded hover:bg-red-50",title:"УдалиÑÑ",children:e.jsx("i",{className:"pi pi-trash text-sm"})})]});return e.jsxs(e.Fragment,{children:[e.jsx($,{}),e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-200 mb-6 overflow-hidden",children:e.jsx("div",{className:"px-6 py-4 bg-gray-50 border-b border-gray-100",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 w-full",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Ðазвание"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-2 pointer-events-none text-gray-400",children:e.jsx("i",{className:"pi pi-search text-sm"})}),e.jsx("input",{value:s.title??"",onChange:t=>
1l(t.target.value),placeholder:"ÐоиÑк по названиÑ",className:"w-full px-4 pl-10 py-2.5 text-sm text-gray-700 bg-white border border-gray-300 rounded-lg focus:ring-1 focus:ring-blue-500 focus:border-blue-500 outline-none transition-colors h-[40px]"})]})]}),e.jsx("div",{className:"flex items-end",children:a&&e.jsxs("button",{onClick:o,className:"flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 transition-colors text-sm font-medium h-[40px]",children:[e.jsx("i",{className:"pi pi-filter-slash text-sm"}),"СбÑоÑиÑÑ ÑилÑÑÑÑ"]})})]})})}),e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(W,{value:d,loading:c,dataKey:"id",emptyMessage:"Ð Ð°Ð·Ð´ÐµÐ»Ñ Ð½Ðµ найденÑ",className:"min-w-full p-datatable-sm",pt:{wrapper:{className:"rounded-none border-0"},thead:{className:"bg-gray-50"},column:{headerCell:{className:"py-3 px-6 text-left"},headerContent:{className:"text-xs font-medium text-gray-600 uppercase tracking-wider"},bodyCell:{className:"py-3 px-6 border-b border-gray-100 text-sm"}},bodyRow:{className:"hover:bg-gray-50 transition-colors"}},children:[e.jsx(x,{field:"sort_order",header:"ÐоÑÑдок",style:{width:"90px"}}
1),e.jsx(x,{field:"title",header:"Ðазвание"}),e.jsx(x,{header:"Роли",body:B}),e.jsx(x,{header:"ÐÑблиÑнÑй",body:t=>C(t.is_public),style:{width:"110px"}}),e.jsx(x,{field:"articles_count",header:"СÑаÑей",style:{width:"90px"}}),e.jsx(x,{header:"ÐпÑбликован",body:t=>C(t.is_published),style:{width:"120px"}}),e.jsx(x,{header:"ÐейÑÑвиÑ",body:V,headerStyle:{width:"130px"}})]})}),e.jsx("div",{className:"px-6 py-3 bg-gray-50 border-t border-gray-100",children:e.jsxs("span",{className:"text-sm text-gray-600",children:["ÐÑего: ",d.length]})})]}),e.jsx(S,{header:"РедакÑиÑование Ñаздела",visible:E,style:{width:"90vw",maxWidth:"560px"},className:"dashboard-crud-dialog",onHide:()=>u(!1),footer:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{label:"ÐÑмена",icon:"pi pi-times",className:"p-button-text",onClick:()=>u(!1)}),e.jsx(g,{label:"СоÑ
ÑаниÑÑ",icon:"pi pi-check",onClick:T,loading:_.isPending,disabled:!m.title.trim()})]}),children:e.jsx(F,{form:m,onChange:N})})]})};function ke(){const[s,r]=p.useState(!1),{form:i,setForm:c,reset:d}=I(),a=U(),l=()=>{if(i.title.trim()){if(!i.is_for_all&&i.role_ids.length===0){n({type:"error",message:"ÐÑбеÑиÑе Ñ
оÑÑ Ð±Ñ Ð¾Ð´Ð½Ñ ÑÐ¾Ð»Ñ Ð¸Ð»Ð¸ вклÑÑиÑе «ÐÐ»Ñ Ð²ÑеÑ
Ñолей»"});return}a.mutate({...i,title:i.title.trim()},{onSuccess:()=>{n({type:"success",message:"Раздел Ñоздан"}),d(),r(!1)},onError:()=>{n({type:"error",message:"ÐÑибка пÑи Ñоздании"})}})}},o=()=>{d(),c(j()),r(!0)};return e.jsxs(P,{children:[e.jsx(R,{children:e.jsx("title",{children:"ÐнÑÑÑÑкÑии"})}),e.jsxs("div",{className:"dashboard-crud-page",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-medium text-lg text-mono m-0",children:"ÐнÑÑÑÑкÑии"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 mb-0",children:"УпÑавление Ñазделами и ÑÑаÑÑÑми инÑÑÑÑкÑий Ð´Ð»Ñ Ð¿Ð¾Ð»ÑзоваÑелей плаÑÑоÑмÑ"})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-2 p-button-normal",children:[e.jsx("i",{className:"pi pi-plus"}),"ÐобавиÑÑ Ñаздел"]})})]}),e.jsx(Y,{})]}),e.jsx(S,{header:"Создание Ñаздела",visible:s,style:{width:"90vw",maxWidth:"560px"},className:"dashboard-crud-dialog",onHide:()=>r(!1),footer:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{label:"ÐÑмена",icon:"pi pi-times",className:"p-button-text",onClick:()=>r(!1)}),e.jsx(g,{label:"СоздаÑÑ",icon:"pi pi-check",onClick:l,loading:a.isPending,disabled:!i.title.trim()})]}),children:e.jsx(F,{form:i,onChange:c})})]})}export{ke 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.