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