(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3124],{17784:function(e,n,l){(window.__NEXT_P=window.__NEXT_P||[]).push(["/sermons/create",function(){return l(13752)}])},13752:function(e,n,l){"use strict";l.r(n);var s=l(85893),i=l(67294),t=l(9473),r=l(87079),a=l(39332),u=l(86886),d=l(21737),o=l(92401),c=l(68269),x=l(15861),h=l(69417);l(41664);var j=l(44267),v=l(50135),m=l(5616),f=l(66242);n.default=function(e){let n=(0,t.I0)(),{push:l}=(0,a.useRouter)(),p=(0,t.v9)(r.V_),Z=(0,t.v9)(r.R0),g=(0,t.v9)(r.Vp),[b,_]=(0,i.useState)(null),[S,P]=(0,i.useState)(""),[w,y]=(0,i.useState)(""),[C,E]=(0,i.useState)(""),[k,N]=(0,i.useState)(null),[T,V]=(0,i.useState)(null);(0,i.useEffect)(()=>{n((0,r.xM)(!1))},[g]),(0,i.useEffect)(()=>{!p&&g&&(_("Sermon added successfully!"),setTimeout(()=>{l("/sermons")},500))},[g,p]);let fileValidation=()=>{let e=[];return null===T&&e.push("Image is required!"),console.log("img",k),null===k&&e.push("Media is required!"),e.length>0&&n((0,r.B$)(e)),e.length<1};return(0,s.jsxs)(u.ZP,{container:!0,spacing:6,children:[(0,s.jsx)(u.ZP,{item:!0,xs:12,children:(0,s.jsx)(x.Z,{variant:"h5",children:"Create Sermon"})}),(0,s.jsx)(u.ZP,{item:!0,xs:12,children:(0,s.jsx)(f.Z,{children:(0,s.jsxs)(j.Z,{children:[b?(0,s.jsxs)(d.Z,{severity:"success",sx:{mb:4},children:[(0,s.jsx)(o.Z,{children:"Success"}),(0,s.jsx)(m.Z,{component:"strong",sx:{display:"block"},children:b})]}):null,Z&&Z.length>0?(0,s.jsxs)(d.Z,{severity:"error",sx:{mb:4},children:[(0,s.jsx)(o.Z,{children:"Errors"}),Z.map((e,n)=>(0,s.jsx)(m.Z,{component:"strong",sx:{display:"block"},children:e},n))]}):null,(0,s.jsx)("form",{onSubmit:e=>{e.preventDefault(),!p&&fileValidation()&&n((0,r.u7)({title:S,description:w,url:C,media:k,image:T}))},children:(0,s.jsxs)(u.ZP,{row:!0,children:[(0,s.jsx)(u.ZP,{item:!0,xs:12,children:(0,s.jsx)(v.Z,{fullWidth:!0,label:"Title",value:S,onChange:e=>P(e.target.value)})}),(0,s.jsx)("br",{}),(0,s.jsx)(u.ZP,{item:!0,xs:12,children:(0,s.jsx)(v.Z,{fullWidth:!0,label:"Description",value:w,onChange:e=>y(e.target.value)})}),(0,s.jsx)("br",{}),(0,s.jsx)(u.ZP,{item:!0,xs:12,children:(0,s.jsx)(v.Z,{fullWidth:!0,label:"Url",value:C,onChange:e=>E(e.target.value)})}),(0,s.jsx)(u.ZP,{item:!0,xs:12,sx:{mt:5},children:(0,s.jsxs)(c.Z,{direction:"row",gap:2,children:[(0,s.jsxs)(h.Z,{variant:"contained",component:"label",children:["Upload Image",(0,s.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var n,l;V(null!==(l=null===(n=e.target)||void 0===n?void 0:n.files[0])&&void 0!==l?l:null)}})]}),(0,s.jsxs)(h.Z,{variant:"contained",component:"label",children:["Upload Media",(0,s.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var n,l;N(null!==(l=null===(n=e.target)||void 0===n?void 0:n.files[0])&&void 0!==l?l:null)}})]})]})}),(0,s.jsx)(u.ZP,{item:!0,xs:12,sx:{mt:5},children:(0,s.jsx)(h.Z,{type:"submit",variant:"contained",disabled:p,children:p?"Saving":"Save"})})]})})]})})})]})}}},function(e){e.O(0,[2657,315,341,4270,9774,2888,179],function(){return e(e.s=17784)}),_N_E=e.O()}]);