(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4461],{59754:function(e,l,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/posts/create",function(){return n(52864)}])},52864:function(e,l,n){"use strict";n.r(l);var t=n(85893),i=n(67294),s=n(10315),a=n(18972),r=n(94054),u=n(9473),d=n(59917),o=n(19736),c=n(39332),h=n(86886),x=n(21737),v=n(92401),j=n(68269),p=n(15861),Z=n(69417);n(41664);var f=n(44267),g=n(50135),m=n(47312),b=n(5616),P=n(66242);l.default=function(e){let l=(0,u.I0)(),{push:n}=(0,c.useRouter)(),S=(0,u.v9)(d.V_),C=(0,u.v9)(d.R0),_=(0,u.v9)(d.Vp),y=(0,u.v9)(o.Lp),[E,w]=(0,i.useState)(null),[k,W]=(0,i.useState)([]),[N,T]=(0,i.useState)(""),[U,V]=(0,i.useState)(""),[D,q]=(0,i.useState)(""),[A,I]=(0,i.useState)(""),[O,R]=(0,i.useState)(""),[X,B]=(0,i.useState)(""),[F,G]=(0,i.useState)(""),[L,M]=(0,i.useState)(null),[$,z]=(0,i.useState)(null),[H,J]=(0,i.useState)(1);(0,i.useEffect)(()=>{l((0,o.tG)({page:H}))},[H]),(0,i.useEffect)(()=>{l((0,d.xM)(!1))},[_]),(0,i.useEffect)(()=>{!S&&_&&(w("Post added successfully!"),setTimeout(()=>{n("/posts")},500))},[_,S]);let fileValidation=()=>{let e=[];return null===k&&e.push("Category is required!"),e.length>0&&l((0,d.B$)(e)),e.length<1};return(0,t.jsxs)(h.ZP,{container:!0,spacing:6,children:[(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(p.Z,{variant:"h5",children:"Create Post"})}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(P.Z,{children:(0,t.jsxs)(f.Z,{children:[E?(0,t.jsxs)(x.Z,{severity:"success",sx:{mb:4},children:[(0,t.jsx)(v.Z,{children:"Success"}),(0,t.jsx)(b.Z,{component:"strong",sx:{display:"block"},children:E})]}):null,C&&C.length>0?(0,t.jsxs)(x.Z,{severity:"error",sx:{mb:4},children:[(0,t.jsx)(v.Z,{children:"Errors"}),C.map((e,l)=>(0,t.jsx)(b.Z,{component:"strong",sx:{display:"block"},children:e},l))]}):null,(0,t.jsx)("form",{onSubmit:e=>{e.preventDefault(),!S&&fileValidation()&&l((0,d.q2)({category_ids:k,title:N,title_ar:U,description:D,description_ar:A,url:O,video:X,audio:F,image:L,pdf:$}))},children:(0,t.jsxs)(h.ZP,{row:!0,children:[(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsxs)(r.Z,{fullWidth:!0,required:!0,children:[(0,t.jsx)(m.Z,{children:"Select Category"}),(0,t.jsx)(s.Z,{multiple:!0,value:k,onChange:e=>{W(e.target.value)},children:y.length>0&&y.map(e=>(0,t.jsx)(a.Z,{value:e.id,children:e.name},e.id))})]})}),(0,t.jsx)("br",{}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(g.Z,{fullWidth:!0,label:"Title",value:N,onChange:e=>T(e.target.value)})}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(g.Z,{fullWidth:!0,label:"Title Arabic",value:U,onChange:e=>V(e.target.value)})}),(0,t.jsx)("br",{}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(g.Z,{fullWidth:!0,label:"Description",value:D,onChange:e=>q(e.target.value)})}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(g.Z,{fullWidth:!0,label:"Description Arabic",value:A,onChange:e=>I(e.target.value)})}),(0,t.jsx)("br",{}),(0,t.jsx)(h.ZP,{item:!0,xs:12,children:(0,t.jsx)(g.Z,{fullWidth:!0,label:"Url",value:O,onChange:e=>R(e.target.value)})}),(0,t.jsx)(h.ZP,{item:!0,xs:12,sx:{mt:5},children:(0,t.jsxs)(j.Z,{direction:"row",gap:2,children:[(0,t.jsxs)(Z.Z,{variant:"contained",component:"label",children:["Upload Video",(0,t.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var l,n;B(null!==(n=null===(l=e.target)||void 0===l?void 0:l.files[0])&&void 0!==n?n:null)}})]}),(0,t.jsxs)(Z.Z,{variant:"contained",component:"label",children:["Upload Audio",(0,t.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var l,n;G(null!==(n=null===(l=e.target)||void 0===l?void 0:l.files[0])&&void 0!==n?n:null)}})]}),(0,t.jsxs)(Z.Z,{variant:"contained",component:"label",children:["Upload PDF",(0,t.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var l,n;z(null!==(n=null===(l=e.target)||void 0===l?void 0:l.files[0])&&void 0!==n?n:null)}})]}),(0,t.jsxs)(Z.Z,{variant:"contained",component:"label",children:["Upload Image",(0,t.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var l,n;M(null!==(n=null===(l=e.target)||void 0===l?void 0:l.files[0])&&void 0!==n?n:null)}})]})]})}),(0,t.jsx)(h.ZP,{item:!0,xs:12,sx:{mt:5},children:(0,t.jsx)(Z.Z,{type:"submit",variant:"contained",disabled:S,children:S?"Saving":"Save"})})]})})]})})})]})}}},function(e){e.O(0,[2657,315,341,6056,9774,2888,179],function(){return e(e.s=59754)}),_N_E=e.O()}]);