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