(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[57],{3056:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/Manager/Roles/Edit/[id]",function(){return r(1861)}])},9413:function(e,t,r){"use strict";var a=r(5893),l=r(1664),s=r.n(l),n=r(1163);let i=e=>{let{title:t,children:r,create:l}=e,i=(0,n.useRouter)();return(0,a.jsxs)("div",{className:"m-5 shadow rounded-3xl hover:shadow-2xl",children:[(0,a.jsxs)("div",{className:"border-b border-gray-200 py-3 px-4 flex justify-between",children:[(0,a.jsx)("h1",{className:"font-bold text-gray-900",children:t}),l&&(0,a.jsx)(s(),{href:i.route+"/Create",passHref:!0,legacyBehavior:!0,children:(0,a.jsx)("a",{className:"hover:text-green-600",children:(0,a.jsx)("span",{children:"افزودن"})})})]}),(0,a.jsx)("div",{className:"p-4 lg:h-[80vh] overflow-y-auto",children:r})]})};t.Z=i},5911:function(e,t,r){"use strict";var a=r(5893);let l=e=>{let{type:t,label:r,className:l,onClick:s,icon:n,id:i}=e;return(0,a.jsxs)("button",{className:"bg-theme-main text-white py-2 px-5 rounded-lg min-w-[80px] inline-flex items-center justify-center"+(l?" "+l:""),type:t,onClick:s,id:i,children:[n,r]})};t.Z=l},8404:function(e,t,r){"use strict";var a=r(5893);let l=e=>{let{id:t,name:r,label:l,onChange:s,checked:n}=e,i={input:"w-4 h-4 text-gray-500 appearance-none checked:bg-second relative rounded border border-second checked:before:content-['✓'] checked:before:absolute checked:before:top-[50%] checked:before:left-[50%] checked:before:-translate-y-1/2 checked:before:-translate-x-1/2 hover:bg-second",label:"mr-2 text-sm font-medium select-none",div:"flex items-center"};return(0,a.jsxs)("div",{className:i.div,children:[(0,a.jsx)("input",{type:"checkbox",id:t,name:r,onChange:s,defaultChecked:n,className:i.input}),(0,a.jsx)("label",{htmlFor:r,className:i.label,children:l})]})};t.Z=l},9821:function(e,t,r){"use strict";var a=r(5893);let l=e=>{let{label:t,type:r,placeholder:l,onChange:s,onClick:n,defaultValue:i,value:d,name:c,id:o,onFocus:u,disabled:m}=e,h={div:"flex flex-col mb-2",label:"mb-2",input:"border border-gray-500 rounded-lg px-3 py-2"},x=e=>{let t=e.target.value;e.target.value=t.replace(/[^-a-zA-Z0-9-آ-ی\s+]+/gi,"").replace(/\s+/gi,"-").toLowerCase()};return(0,a.jsxs)("div",{className:h.div,children:[(0,a.jsx)("label",{className:h.label,htmlFor:c,children:t}),(0,a.jsx)("input",{type:r,placeholder:l,className:h.input,onChange:s,onClick:n,onFocus:u,name:c,id:o,disabled:!!m&&m,readOnly:!!m&&m,autoComplete:"off",onKeyUp:"slug"===r?x:void 0,defaultValue:i||d||void 0})]})};t.Z=l},1734:function(e,t,r){"use strict";var a=r(5893);let l=e=>{let{label:t,placeholder:r,onChange:l,defaultValue:s,name:n,disabled:i,id:d}=e,c={div:"flex flex-col mb-2",label:"mb-2",input:"border border-gray-500 rounded-lg px-3 py-2"};return(0,a.jsxs)("div",{className:c.div,children:[(0,a.jsx)("label",{className:c.label,htmlFor:n,children:t}),(0,a.jsx)("textarea",{placeholder:r,className:c.input,onChange:l,name:n,id:d,disabled:!!i&&i,readOnly:!!i&&i,autoComplete:"off",defaultValue:s})]})};t.Z=l},1861:function(e,t,r){"use strict";r.r(t),r.d(t,{__N_SSP:function(){return p}});var a=r(5893),l=r(4184),s=r(9413),n=r(5911),i=r(9821),d=r(2920),c=r(9552),o=r.n(c),u=r(7294),m=r(1734),h=r(8404);let x=e=>{let{status:t,data:r,permissions:c,selected_permissions:x}=e,[p,f]=(0,u.useState)(x),b=(e,t)=>e.reduce(function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e},[]),v=async e=>{e.preventDefault();let t={name:e.target.name.value,description:e.target.description.value,permissions:JSON.stringify(p)},a=o().get("token");fetch("/api/role/edit/"+r.id,{body:JSON.stringify(t),method:"POST",headers:{Authorization:"bearer "+a}}).then(async e=>{200===e.status?d.Am.success("با موفقیت بروز رسانی شد."):d.Am.error("خطا!")})},g=e=>{p.includes(e)?f(p.filter(t=>t!==e)):f([...p,e])};return(0,a.jsx)(l.Z,{title:"نقش ها - ویرایش: "+r.name,children:(0,a.jsx)(s.Z,{title:"ویرایش",children:(0,a.jsxs)("form",{onSubmit:v,children:[(0,a.jsx)(i.Z,{type:"text",label:"عنوان",defaultValue:r.name,id:"name",name:"name"}),(0,a.jsx)(m.Z,{type:"text",label:"توضیحات",defaultValue:r.description,id:"description",name:"description"}),(0,a.jsx)("div",{className:"grid grid-cols-4 space-x-2 space-x-reverse",children:Object.keys(b(c,"category")).map((e,t)=>(0,a.jsxs)("div",{className:"border border-gray-200 rounded-lg",children:[(0,a.jsx)("div",{className:"flex py-2 bg-gray-100 justify-center items-center",children:e}),(0,a.jsx)("div",{className:"mt-2 px-2",children:b(c,"category")[e].map((e,t)=>(0,a.jsx)("div",{className:"mb-2",children:(0,a.jsx)(h.Z,{id:e.id,name:e.id,label:e.persian_name,onChange:()=>g(e.id),checked:p.includes(e.id)})},e.id+t))})]},t+e))}),(0,a.jsx)("div",{className:"text-left mt-3",children:(0,a.jsx)(n.Z,{type:"submit",label:"بروزرسانی"})})]})})})};var p=!0;t.default=x}},function(e){e.O(0,[4617,1057,3874,699,4184,9774,2888,179],function(){return e(e.s=3056)}),_N_E=e.O()}]);