(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[138],{64523:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/books/create",function(){return t(87178)}])},87178:function(e,n,t){"use strict";t.r(n);var s=t(85893),i=t(67294),l=t(9473),r=t(55952),a=t(39332),o=t(86886),c=t(21737),d=t(92401),u=t(68269),x=t(15861),h=t(69417);t(41664);var j=t(44267),v=t(50135),f=t(5616),Z=t(66242);n.default=function(e){let n=(0,l.I0)(),{push:t}=(0,a.useRouter)(),p=(0,l.v9)(r.V_),m=(0,l.v9)(r.R0),g=(0,l.v9)(r.Vp),[b,_]=(0,i.useState)(""),[k,P]=(0,i.useState)(""),[S,w]=(0,i.useState)(""),[y,E]=(0,i.useState)(""),[C,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&&(_("Book added successfully!"),setTimeout(()=>{t("/books")},500))},[g,p]);let fileValidation=()=>{let e=[];return e.length>0&&n((0,r.B$)(e)),e.length<1};return(0,s.jsxs)(o.ZP,{container:!0,spacing:6,children:[(0,s.jsx)(o.ZP,{item:!0,xs:12,children:(0,s.jsx)(x.Z,{variant:"h5",children:"Create Book"})}),(0,s.jsx)(o.ZP,{item:!0,xs:12,children:(0,s.jsx)(Z.Z,{children:(0,s.jsxs)(j.Z,{children:[b?(0,s.jsxs)(c.Z,{severity:"success",sx:{mb:4},children:[(0,s.jsx)(d.Z,{children:"Success"}),(0,s.jsx)(f.Z,{component:"strong",sx:{display:"block"},children:b})]}):"",m&&m.length>0?(0,s.jsxs)(c.Z,{severity:"error",sx:{mb:4},children:[(0,s.jsx)(d.Z,{children:"Errors"}),m.map((e,n)=>(0,s.jsx)(f.Z,{component:"strong",sx:{display:"block"},children:e},n))]}):"",(0,s.jsx)("form",{onSubmit:e=>{e.preventDefault(),!p&&fileValidation()&&n((0,r.TA)({title:k,image:C,file:T,description:y,url:S}))},children:(0,s.jsxs)(o.ZP,{row:!0,children:[(0,s.jsx)(o.ZP,{item:!0,xs:12,children:(0,s.jsx)(v.Z,{fullWidth:!0,label:"Title",value:k,onChange:e=>P(e.target.value)})}),(0,s.jsx)(o.ZP,{item:!0,xs:12,mt:5,children:(0,s.jsx)(v.Z,{fullWidth:!0,label:"URL",value:S,onChange:e=>w(e.target.value)})}),(0,s.jsx)(o.ZP,{item:!0,xs:12,sx:{mt:5},children:(0,s.jsxs)(u.Z,{direction:"row",gap:2,children:[(0,s.jsxs)(h.Z,{variant:"contained",component:"label",children:["Upload File",(0,s.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var n,t;V(null!==(t=null===(n=e.target)||void 0===n?void 0:n.files[0])&&void 0!==t?t:"")}})]}),(0,s.jsxs)(h.Z,{variant:"contained",component:"label",children:["Upload Image",(0,s.jsx)("input",{type:"file",hidden:!0,onChange:e=>{var n,t;N(null!==(t=null===(n=e.target)||void 0===n?void 0:n.files[0])&&void 0!==t?t:"")}})]})]})}),(0,s.jsx)(o.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,8589,9774,2888,179],function(){return e(e.s=64523)}),_N_E=e.O()}]);