(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-534f5c08"],{"129f":function(e,t,r){"use strict";e.exports=Object.is||function(e,t){return e===t?0!==e||1/e===1/t:e!==e&&t!==t}},"306d":function(e,t,r){"use strict";r.r(t);r("a4d3"),r("e01a"),r("d3b7"),r("ac1f"),r("841c"),r("ddb0");var a=function(){var e=this,t=e._self._c;return t("div",{staticClass:"main-content"},[t("breadcumb",{attrs:{page:this.$route.id?"Edit":"Tambah",folder:"Galeri"}}),t("b-card",{ref:"formContainer",staticClass:"wrapper"},[t("b-form",{on:{submit:function(t){return t.preventDefault(),e.onSubmit.apply(null,arguments)}}},[t("b-overlay",{attrs:{show:e.isLoading,rounded:"sm"}},[t("b-row",[t("b-form-group",{staticClass:"col-md-12 mb-3",attrs:{"label-for":"title",label:"Judul"}},[t("b-form-input",{directives:[{name:"validate",rawName:"v-validate",value:"required|min:5",expression:"'required|min:5'"}],class:{input:!0,"is-danger":e.errors.has("judul")},attrs:{type:"text",placeholder:"Masukkan Judul",name:"judul"},model:{value:e.form.title,callback:function(t){e.$set(e.form,"title",t)},expression:"form.title"}}),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("judul"),expression:"errors.has('judul')"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("judul"))+" ")])],1),t("b-form-group",{staticClass:"col-md-12 mb-2",attrs:{label:"Nama Project"}},[t("multiselect",{attrs:{options:e.getFilteredCampaigns,multiple:!1,"close-on-select":!0,"clear-on-select":!1,"preserve-search":!0,placeholder:"Search Project",label:"wakaf_name","track-by":"wakaf_name","preselect-first":!0,"open-direction":"bottom",searchable:!0,"internal-search":!1,"options-limit":50,limit:2,"show-no-results":!1,"hide-selected":!1,loading:e.isLoadingCampaign},on:{"search-change":e.onCampaignSearch},scopedSlots:e._u([{key:"selection",fn:function(r){var a=r.values,i=(r.search,r.isOpen);return[a.length&&!i?t("span",{staticClass:"multiselect__single"},[e._v(e._s(a.length)+" options selected")]):e._e()]}}]),model:{value:e.form.project,callback:function(t){e.$set(e.form,"project",t)},expression:"form.project"}})],1),t("b-form-group",{staticClass:"col-md-12 mb-3",attrs:{"label-for":"distributionDate",label:"Tanggal Distribusi"}},[t("b-form-datepicker",{directives:[{name:"validate",rawName:"v-validate",value:"required|min:5",expression:"'required|min:5'"}],class:{input:!0,"is-danger":e.errors.has("tanggal distribusi")},attrs:{id:"distributionDate",placeholder:"Pilih tanggal distribusi",locale:"id",name:"tanggal distribusi"},model:{value:e.form.distributionDate,callback:function(t){e.$set(e.form,"distributionDate",t)},expression:"form.distributionDate"}}),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("tanggal distribusi"),expression:"errors.has('tanggal distribusi')"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("tanggal distribusi"))+" ")])],1),t("b-form-group",{staticClass:"col-md-12 mb-3",attrs:{"label-for":"description",label:"Deskripsi"}},[t("b-form-textarea",{directives:[{name:"validate",rawName:"v-validate",value:"required|min:5",expression:"'required|min:5'"}],class:{input:!0,"is-danger":e.errors.has("deskripsi")},attrs:{id:"description",placeholder:"Masukkan Deskripsi",name:"deskripsi",rows:"6","max-rows":"6"},on:{keydown:e.onKeyDown,input:e.onDescriptionInput},model:{value:e.form.description,callback:function(t){e.$set(e.form,"description",t)},expression:"form.description"}}),t("small",[e._v(e._s(e.form.description.length)+" / 250 karakter")]),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("deskripsi"),expression:"errors.has('deskripsi')"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("deskripsi"))+" ")])],1),t("b-form-group",{staticClass:"col-md-12 mb-3",attrs:{label:"Klien"}},[e.userSource?t("b-form-input",{attrs:{readonly:""},model:{value:e.form.source_name,callback:function(t){e.$set(e.form,"source_name",t)},expression:"form.source_name"}}):e._e(),e.userSource?e._e():t("b-form-select",{directives:[{name:"validate",rawName:"v-validate",value:"required",expression:"'required'"}],class:{input:!0,"is-danger":e.errors.has("klien")},attrs:{options:e.sources,"value-field":"source_id","text-field":"source_name","disabled-field":"disabled",name:"klien"},model:{value:e.form.source,callback:function(t){e.$set(e.form,"source",t)},expression:"form.source"}}),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("klien"),expression:"errors.has('klien')"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("klien"))+" ")])],1),t("b-form-group",{staticClass:"col-md-12 mb-3",attrs:{label:"Foto/Video"}},[t("div",{staticClass:"d-flex align-items-center justify-content-between"},[t("b-form-radio-group",{staticClass:"mb-3",attrs:{options:[{text:"Photo",value:"image"},{text:"Video",value:"youtube"}],name:"mediaType"},model:{value:e.form.mediaTypes,callback:function(t){e.$set(e.form,"mediaTypes",t)},expression:"form.mediaTypes"}})],1),"image"===e.form.mediaTypes?t("div",[e._l(e.form.images,(function(r,a){return t("div",{key:"gallery-image-"+a,staticClass:"mb-4 d-flex align-items-start"},[t("div",{staticClass:"flex-grow-1"},[r.cropImg||r.id?e._e():t("input",{directives:[{name:"validate",rawName:"v-validate",value:"size:1048576",expression:"'size:1048576'"}],ref:"gallery-image-input-"+a,refInFor:!0,class:{input:!0,"is-danger":e.errors.has("gallery_image_"+(a+1))},staticStyle:{"font-size":"1.2em",padding:"10px 0"},attrs:{type:"file",id:"gallery-image-input-"+a,accept:"image/png, image/jpeg, image/jpg",name:"gallery_image_"+(a+1)},on:{change:function(t){return e.setGalleryImage(t,a)}}}),r.src?t("div",{staticStyle:{width:"100%",height:"100%",border:"1px solid gray",display:"inline-block"}},[r.id?e._e():t("h5",[e._v("Insert Image")]),t("vue-cropper",{ref:"galleryCropper"+a,refInFor:!0,attrs:{guides:!0,"view-mode":2,"drag-mode":"crop","auto-crop-area":1,"min-container-width":250,"min-container-height":90,background:!0,rotatable:!0,aspectRatio:16/9,initialAspectRatio:16/9,src:r.src,alt:"Source Image","img-style":{width:"400px"}}})],1):e._e(),t("div",{directives:[{name:"show",rawName:"v-show",value:!r.id,expression:"!img.id"}],staticClass:"mt-2"},[r.src?t("b-button",{staticClass:"m-1",attrs:{variant:"primary"},on:{click:function(t){return e.cropGalleryImage(a)}}},[e._v("Crop")]):e._e(),r.src?t("b-button",{staticClass:"m-1",attrs:{variant:"success"},on:{click:function(t){return e.rotateGalleryImage(a)}}},[e._v("Rotate")]):e._e()],1),r.cropImg?t("div",{staticStyle:{"margin-top":"-10px"}},[t("img",{staticStyle:{width:"400px",border:"1px solid gray"},attrs:{src:r.cropImg,alt:"Cropped Image"}})]):e._e(),r.cropImg||r.src?t("b-button",{staticClass:"mt-2 d-block",attrs:{variant:"danger"},on:{click:function(t){r.isExist?e.removeGalleryImage(r.id,r.isExist,"image"):e.removeImage(a)}}},[e._v("Remove")]):e._e(),t("b-form-textarea",{staticClass:"mt-2",attrs:{placeholder:"Deskripsi",rows:"2","max-rows":"2"},model:{value:r.desc,callback:function(t){e.$set(r,"desc",t)},expression:"img.desc"}}),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("gallery_image_"+(a+1)),expression:"errors.has('gallery_image_' + (idx + 1))"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("gallery_image_"+(a+1)))+" ")])],1),t("div",{staticClass:"ml-2 d-flex flex-column"},[e.form.images.length-1===a&&e.form.images.length<10?t("i",{staticClass:"i-Add text-24 text-info mb-2 cursor-pointer",on:{click:e.addFormImage}}):e._e(),e.form.images.length>1||r.isExist?t("i",{staticClass:"i-Close text-24 text-danger cursor-pointer",on:{click:function(t){r.isExist?e.removeGalleryImage(r.id,r.isExist,"image"):e.removeFormImage(a)}}}):e._e()])])})),t("small",{staticClass:"text-muted"},[e._v("Maksimal 10 gambar beserta deskripsinya.")])],2):"youtube"===e.form.mediaTypes?t("div",[t("b-row",{},e._l(e.form.youtubeLinks,(function(r,a){return t("b-col",{key:"youtube-link-"+a,staticClass:"mb-2 d-flex align-items-start",attrs:{cols:"12",md:"12",lg:"12"}},[t("div",{staticClass:"flex-grow-1"},[t("b-input-group",[t("b-input-group-prepend",{attrs:{"is-text":""}},[t("vue-fontawesome",{attrs:{icon:"youtube",size:"1"}})],1),t("b-form-input",{attrs:{type:"url",placeholder:"Paste link YouTube"},model:{value:r.url,callback:function(t){e.$set(r,"url",t)},expression:"link.url"}})],1),t("b-form-textarea",{staticClass:"mt-2",attrs:{placeholder:"Deskripsi video",rows:"2","max-rows":"2"},model:{value:r.desc,callback:function(t){e.$set(r,"desc",t)},expression:"link.desc"}})],1),t("div",{staticClass:"ml-2 d-flex flex-column"},[e.form.youtubeLinks.length-1===a&&e.form.youtubeLinks.length<10?t("i",{staticClass:"i-Add text-24 text-info mb-2 cursor-pointer",on:{click:e.addFormYoutubeLink}}):e._e(),e.form.youtubeLinks.length>1||r.isExist?t("i",{staticClass:"i-Close text-24 text-danger cursor-pointer",on:{click:function(t){r.isExist?e.removeGalleryImage(r.id,r.isExist,"youtube"):e.removeFormYoutubeLink(a)}}}):e._e()])])})),1),t("small",{staticClass:"text-muted"},[e._v("Maksimal 10 link video YouTube beserta deskripsinya.")])],1):e._e()]),t("b-form-group",{staticClass:"col-md-12"},[t("div",{staticClass:"d-flex"},[t("b-button",{attrs:{variant:"primary",size:"sm",type:"submit",disabled:e.loading}},[e._v(" "+e._s(e.loading?"Loading ...":"Save")+" ")]),t("b-button",{staticClass:"ml-auto",attrs:{variant:"danger",size:"sm",type:"button"},on:{click:function(t){return e.$router.go(-1)}}},[e._v(" Cancel ")])],1)])],1)],1)],1)],1)],1)},i=[],s=r("6b75");function n(e){if(Array.isArray(e))return Object(s["a"])(e)}r("d28b"),r("a630"),r("3ca3");function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}var c=r("06c5");r("d9e2");function l(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e){return n(e)||o(e)||Object(c["a"])(e)||l()}var d=r("c7eb"),m=r("1da1"),f=r("5530"),p=r("668b"),g=(r("99af"),r("4de4"),r("7db0"),r("c740"),r("caad"),r("d81d"),r("14d9"),r("fb6a"),r("a434"),r("e9f5"),r("d866"),r("910d"),r("f665"),r("7d54"),r("ab43"),r("25f0"),r("2532"),r("498a"),r("159b"),r("2b3d"),r("bf19"),r("9861"),r("88a7"),r("271a"),r("5494"),r("95c3")),h=r.n(g),b=r("8e5f"),v=r.n(b),k=(r("6107"),r("7c8d")),y=r.n(k),x={name:"GalleryForm",components:{Multiselect:v.a,VueCropper:h.a},data:function(){return{form:{title:"",project:null,distributionDate:"",description:"",source:null,source_name:"",images:[{src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1}],imageGalleries:[],youtubeLinks:[{url:null,desc:"",id:null,isExist:!1}],galleryDetailIds:[],mediaTypes:"image"},list:{selectedCampaigns:[],campaigns:[]},sources:[],userSource:!1,loading:!1,isLoading:!1,isLoadingCampaign:!1,getCampaignsTimeout:null}},watch:{"$route.params.uuid":{handler:function(e){e&&this.getGalleryDetail()},immediate:!0}},computed:{getFilteredCampaigns:function(){var e=[];return this.list.campaigns.forEach((function(t){e.push({wakaf_id:t.wakaf_id,wakaf_name:t.wakaf_name})})),e}},mounted:function(){this.getSelectedCampaigns(),this.loadSources()},methods:{getGalleryDetail:function(){var e=this;this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","galleries/").concat(this.$route.params.uuid),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(t){var r=t.data;e.form.title=r.judul,e.form.project={wakaf_id:r.campaign.wakaf_id,wakaf_name:r.campaign.wakaf_name},e.form.distributionDate=r.tanggal_distribusi,e.form.description=r.deskripsi,e.form.source=r.source_id||"",e.getGalleryDetailList(r.gallery_id)})).catch((function(t){e.$store.dispatch("error",t)}))},getGalleryDetailList:function(e){var t=this;this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","gallery-details?gallery_id=").concat(e),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(e){var r=e.data;r.data.length>0&&(t.form.images=[],t.form.youtubeLinks=[],r.data.forEach((function(e,r){r<10&&(e.file_gambar?t.form.images.push({src:e.file_gambar,desc:e.deskripsi||"",id:e.gallery_detail_id,cropImg:"",file:null,isExist:!0}):e.youtube_url?t.form.youtubeLinks.push({url:e.youtube_url,desc:e.deskripsi||"",id:e.gallery_detail_id,isExist:!0}):(t.form.images.push({src:null,desc:"",id:null,cropImg:"",file:null,isExist:!1}),t.form.youtubeLinks.push({url:null,desc:"",id:null,isExist:!1})))})));var a=t.form.images.every((function(e){return e.id&&e.isExist})),i=t.form.youtubeLinks.every((function(e){return e.id&&e.isExist}));a?t.form.mediaTypes="image":i&&(t.form.mediaTypes="youtube"),0===t.form.images.length&&t.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1}),0===t.form.youtubeLinks.length&&t.form.youtubeLinks.push({url:null,desc:"",id:null,isExist:!1})})).catch((function(e){t.$store.dispatch("error",e)}))},onDescriptionInput:function(e){e.length<250?this.form.description=e:this.form.description=e.slice(0,250)},onKeyDown:function(e){var t=["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"];!(this.form.description.length>=250)||t.includes(e.key)||e.ctrlKey&&("a"===e.key||"A"===e.key)||e.ctrlKey&&("x"===e.key||"X"===e.key)||e.ctrlKey&&("c"===e.key||"C"===e.key)||e.ctrlKey&&("v"===e.key||"V"===e.key)||e.preventDefault()},getSelectedCampaigns:function(){var e=this;this.isLoading=!0,this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","selected-campaigns?need_campaign=1")).then((function(t){t.data.data.forEach((function(t){e.list.selectedCampaigns.push({wakaf_id:t.wakaf_id,wakaf_name:t.campaign.wakaf_name})})),e.getCampaigns(),e.isLoading=!1})).catch((function(t){e.isLoading=!1,e.$store.dispatch("error",t)}))},onCampaignSearch:function(e){var t=this;this.getCampaignsTimeout&&clearTimeout(this.getCampaignsTimeout),void 0!==e&&(this.getCampaignsTimeout=setTimeout((function(){t.getCampaigns(e)}),300))},getCampaigns:function(e){var t=this;this.isLoadingCampaign=!0;var r=new URL(window.location.href);r.search="";var a=new URLSearchParams(r.search);e&&a.append("name",e),this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","campaigns?").concat(a.toString())).then((function(e){var r=e.data;t.list.campaigns=[],r.data.forEach((function(e){t.list.campaigns.push({wakaf_id:e.wakaf_id,wakaf_name:e.wakaf_name})})),t.isLoadingCampaign=!1})).catch((function(e){t.$store.dispatch("error",e)}))},loadSources:function(){var e=this,t=this.$store.getters.accountData.source_id;this.userSource?this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","white-labels/").concat(t),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(t){var r=t.data;e.form.source_name=r.source_name})).catch((function(){e.$store.dispatch("error","Maaf, terjadi kesalahan")})):this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","white-labels"),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(t){var r=t.data;e.sources=r.data,e.sources.unshift({source_id:null,source_name:"Pilih Klien",disabled:!0})})).catch((function(){e.$store.dispatch("error","Maaf, terjadi kesalahan")}))},onImageChange:function(e,t){var r=this,a=e.target.files[0];if(a){var i=new FileReader;i.onload=function(e){var i,s;r.$set(r.form.images,t,{src:e.target.result,desc:(null===(i=r.form.images[t])||void 0===i?void 0:i.desc)||""});var n=r.form.imageGalleries.findIndex((function(e){return e.id===t})),o={id:t,file:a,src:e.target.result,desc:(null===(s=r.form.images[t])||void 0===s?void 0:s.desc)||""};-1!==n?r.form.imageGalleries.splice(n,1,o):r.form.imageGalleries.push(o)},i.readAsDataURL(a)}},setGalleryImage:function(e,t){var r=this,a=e.target.files[0];if(a)if(a.size>2097152)this.$store.dispatch("error","file terlalu besar, harus dibawah 2mb");else if(a.type.includes("image/")){var i=new FileReader;i.onload=function(e){var i;r.$set(r.form.images,t,Object(f["a"])(Object(f["a"])({},r.form.images[t]),{},{src:e.target.result,file:a,cropImg:"",desc:(null===(i=r.form.images[t])||void 0===i?void 0:i.desc)||"",isExist:!1}))},i.readAsDataURL(a)}else alert("Please select an image file")},cropGalleryImage:function(e){var t=this.$refs["galleryCropper"+e],r=Array.isArray(t)?t[0]:t;r&&r.getCroppedCanvas&&this.$set(this.form.images,e,Object(f["a"])(Object(f["a"])({},this.form.images[e]),{},{file:r.getCroppedCanvas(),cropImg:r.getCroppedCanvas().toDataURL(),src:""}))},rotateGalleryImage:function(e){var t=this.$refs["galleryCropper"+e],r=Array.isArray(t)?t[0]:t;r&&r.rotate&&r.rotate(90)},getImageBlob:function(e){return Object(m["a"])(Object(d["a"])().mark((function t(){return Object(d["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=Object(m["a"])(Object(d["a"])().mark((function t(r,a){return Object(d["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:try{e.toBlob((function(e){e.size>1048576?new y.a(e,{quality:.8,maxWidth:1e3,success:function(e){var t=new FileReader;t.onload=function(e){console.log(e.target.result)},t.onerror=function(e){console.error("Error reading file:",e)},t.readAsDataURL(e),r(e)},error:function(e){console.log(e),a(e.message)}}):r(e)}))}catch(i){a(err)}case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)})))()},onSubmit:function(){var e=this;this.$validator.validateAll().then(function(){var t=Object(m["a"])(Object(d["a"])().mark((function t(r){var a,i,s,n,o,c,l,f;return Object(d["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:if(a=!!e.$route.params.uuid,i=[],s=e.form.youtubeLinks.filter((function(e){return e.url})).filter((function(e){return e})),n=function(){return e.form.images.map((function(e){return e.file?e.file:e.src?e.src:null})).filter((function(e){return e}))},i=[].concat(u(s),u(n())),0!==i.length){t.next=8;break}return e.$store.dispatch("error","Gambar atau link youtube masih kosong, minimal harus ada 1 gambar atau 1 link youtube dengan deskripsi yang benar"),t.abrupt("return");case 8:r?(e.isLoading=!0,o={judul:e.form.title,deskripsi:e.form.description,tanggal_distribusi:e.form.distributionDate,wakaf_id:e.form.project?e.form.project.wakaf_id:null,source_id:e.form.source},c={Authorization:"Bearer ".concat(e.$store.getters["accessToken"])},l=a?"".concat("https://orchestrator.bwa.id/api/v1/","galleries/").concat(e.$route.params.uuid):"".concat("https://orchestrator.bwa.id/api/v1/","galleries"),f=a?"patch":"post",e.$http[f](l,o,{headers:c}).then(function(){var t=Object(m["a"])(Object(d["a"])().mark((function t(r){var i,s,n,o,c,l,u,m,f,g,h,b,v,k,y,x,w,_,C,L,$,I,D,j;return Object(d["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:if(200!==r.status){t.next=139;break}if(i=r.data.gallery_id||e.$route.params.uuid,s=!1,n=!1,!(e.form.images.length>0)){t.next=85;break}if(o=e.form.images.filter((function(e){return!e.id&&e.file})),!(o.length>0)){t.next=64;break}if(c=o.every((function(e){return e.desc&&""!==e.desc.trim()})),c){t.next=16;break}if(e.$store.dispatch("error","Deskripsi gambar tidak boleh kosong"),e.isLoading=!1,a){t.next=14;break}return t.next=14,e.onDeleteGallery(i);case 14:return e.isLoading=!1,t.abrupt("return");case 16:t.prev=16,l=0,u=!1,m=!1,t.prev=20,g=Object(p["a"])(o);case 22:return t.next=24,g.next();case 24:if(!(u=!(h=t.sent).done)){t.next=39;break}if(b=h.value,!b.file||"function"!==typeof b.file.toBlob){t.next=34;break}return t.next=29,e.getImageBlob(b.file);case 29:return v=t.sent,t.next=32,e.onSubmitGalleryDetail(i,v,b.desc,b.id,"image");case 32:t.next=35;break;case 34:e.$store.dispatch("error","File gambar "+(l+1)+" tidak valid atau tidak dapat diubah menjadi Blob");case 35:l++;case 36:u=!1,t.next=22;break;case 39:t.next=45;break;case 41:t.prev=41,t.t0=t["catch"](20),m=!0,f=t.t0;case 45:if(t.prev=45,t.prev=46,!u||null==g.return){t.next=50;break}return t.next=50,g.return();case 50:if(t.prev=50,!m){t.next=53;break}throw f;case 53:return t.finish(50);case 54:return t.finish(45);case 55:s=!0,t.next=62;break;case 58:t.prev=58,t.t1=t["catch"](16),console.log("error",t.t1),e.$store.dispatch("error",t.t1);case 62:t.next=85;break;case 64:if(k=e.form.images.filter((function(e){return e.id})),!(k.length>0)){t.next=75;break}if(y=k.every((function(e){return e.desc&&""!==e.desc.trim()})),y){t.next=75;break}if(e.$store.dispatch("error","Deskripsi gambar tidak boleh kosong"),e.isLoading=!1,a){t.next=73;break}return t.next=73,e.onDeleteGallery(i);case 73:return e.isLoading=!1,t.abrupt("return");case 75:return x=k.map((function(t){return new Promise((function(r,a){try{e.onSubmitGalleryDetail(i,null,t.desc,t.id,"image"),r(!0)}catch(s){a(s)}}))})),t.prev=76,t.next=79,Promise.all(x);case 79:s=!0,t.next=85;break;case 82:t.prev=82,t.t2=t["catch"](76),e.$store.dispatch("error",t.t2);case 85:if(!(e.form.youtubeLinks.length>0)){t.next=130;break}if(w=e.form.youtubeLinks.filter((function(e){return e.url})),!(w.length>0)){t.next=109;break}if(_=w.every((function(e){return e.desc&&""!==e.desc.trim()})),_){t.next=97;break}if(e.$store.dispatch("error","Deskripsi link youtube tidak boleh kosong"),e.isLoading=!1,a){t.next=95;break}return t.next=95,e.onDeleteGallery(i);case 95:return e.isLoading=!1,t.abrupt("return");case 97:return C=w.map((function(t){return e.onSubmitGalleryDetail(i,t.url,t.desc,t.id,"youtube")})),t.prev=98,t.next=101,Promise.all(C);case 101:n=!0,t.next=107;break;case 104:t.prev=104,t.t3=t["catch"](98),e.$store.dispatch("error",t.t3);case 107:t.next=130;break;case 109:if(L=e.form.youtubeLinks.filter((function(e){return e.id})),!(L.length>0)){t.next=120;break}if($=L.every((function(e){return e.desc&&""!==e.desc.trim()})),$){t.next=120;break}if(e.$store.dispatch("error","Deskripsi link youtube tidak boleh kosong"),e.isLoading=!1,a){t.next=118;break}return t.next=118,e.onDeleteGallery(i);case 118:return e.isLoading=!1,t.abrupt("return");case 120:return I=L.map((function(t){return new Promise((function(r,a){try{e.onSubmitGalleryDetail(i,null,t.desc,t.id,"image"),r(!0)}catch(s){a(s)}}))})),t.prev=121,t.next=124,Promise.all(I);case 124:n=!0,t.next=130;break;case 127:t.prev=127,t.t4=t["catch"](121),e.$store.dispatch("error",t.t4);case 130:if(a&&(D=e.form.images.map((function(e){return e.id})).filter((function(e){return e})),j=e.form.youtubeLinks.map((function(e){return e.id})).filter((function(e){return e})),(D.length>0||j.length>0)&&(s=!0,n=!0)),e.isLoading=!1,!s&&!n){t.next=136;break}return e.$store.dispatch("success","Berhasil menambahkan galeri"),e.$router.push("/app/galleries"),t.abrupt("return");case 136:if(s&&n||a){t.next=139;break}return t.next=139,e.onDeleteGallery(i);case 139:case"end":return t.stop()}}),t,null,[[16,58],[20,41,45,55],[46,,50,54],[76,82],[98,104],[121,127]])})));return function(e){return t.apply(this,arguments)}}()).catch((function(t){e.isLoading=!1;var r=t.response&&t.response.data&&t.response.data.message?t.response.data.message:a?"Gagal memperbarui galeri.":"Gagal menambahkan galeri.";e.$store.dispatch("error",r)}))):e.isLoading=!1;case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())},onDeleteGallery:function(e){this.$http.delete("".concat("https://orchestrator.bwa.id/api/v1/","galleries/").concat(e),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(){})).catch((function(){}))},onSubmitGalleryDetail:function(e,t,r,a,i){var s=arguments,n=this;return Object(m["a"])(Object(d["a"])().mark((function o(){var c,l,u,m;return Object(d["a"])().wrap((function(o){while(1)switch(o.prev=o.next){case 0:return c=s.length>5&&void 0!==s[5]&&s[5],l=new FormData,l.append("gallery_id",e),"image"===i?(t&&l.append("file_gambar",t),r&&l.append("deskripsi",r)):"youtube"===i&&(t&&l.append("youtube_url",t),l.append("deskripsi",r||null)),a&&l.append("_method","PATCH"),u=a?"".concat("https://orchestrator.bwa.id/api/v1/","gallery-details/").concat(a):"".concat("https://orchestrator.bwa.id/api/v1/","gallery-details"),m=c?"patch":"post",o.next=9,n.$http[m](u,l,{headers:{Authorization:"Bearer ".concat(n.$store.getters["accessToken"])}});case 9:case"end":return o.stop()}}),o)})))()},removeImage:function(e){this.$set(this.form.images,e,{src:null,desc:""});var t=this.form.imageGalleries.findIndex((function(t){return t.id===e}));-1!==t&&this.form.imageGalleries.splice(t,1)},removeFormFile:function(){"image"===this.form.mediaTypes?1===this.form.images.length?this.form.images[0]={src:null,cropImg:"",file:null,desc:"",id:null}:this.form.images.pop():"youtube"===this.form.mediaTypes&&(1===this.form.youtubeLinks.length?this.form.youtubeLinks[0]={url:null,desc:"",id:null}:this.form.youtubeLinks.pop())},addFormFile:function(){"image"===this.form.mediaTypes?this.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null}):"youtube"===this.form.mediaTypes&&this.form.youtubeLinks.push({url:null,desc:"",id:null})},removeGalleryImage:function(e,t,r){var a=this,i=null;if("image"===r?i=this.form.images.find((function(t){return t.id===e})):"youtube"===r&&(i=this.form.youtubeLinks.find((function(t){return t.id===e}))),i)t&&this.$http.delete("".concat("https://orchestrator.bwa.id/api/v1/","gallery-details/").concat(e),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(){if(a.$store.dispatch("success","Berhasil menghapus gambar"),a.loading=!1,"image"===r){var t=a.form.images.findIndex((function(t){return t.id===e}));a.form.images.splice(t,1),0===a.form.images.length&&a.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1})}else if("youtube"===r){var i=a.form.youtubeLinks.findIndex((function(t){return t.id===e}));a.form.youtubeLinks.splice(i,1),0===a.form.youtubeLinks.length&&a.form.youtubeLinks.push({url:null,desc:"",id:null,isExist:!1})}})).catch((function(e){a.$store.dispatch("error",e),a.loading=!1}));else if("image"===r){var s=this.form.images.findIndex((function(t){return t.id===e}));this.form.images.splice(s,1)}else if("youtube"===r){var n=this.form.youtubeLinks.findIndex((function(t){return t.id===e}));this.form.youtubeLinks.splice(n,1)}},addFormImage:function(){this.form.images.length<10&&this.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1})},removeFormImage:function(e){this.form.images.length>1&&this.form.images.splice(e,1)},addFormYoutubeLink:function(){this.form.youtubeLinks.length<10&&this.form.youtubeLinks.push({url:"",desc:"",id:null})},removeFormYoutubeLink:function(e){this.form.youtubeLinks.length>1&&this.form.youtubeLinks.splice(e,1)}}},w=x,_=(r("f0ed"),r("6520"),r("2877")),C=Object(_["a"])(w,a,i,!1,null,"952a9d1e",null);t["default"]=C.exports},"35e3":function(e,t,r){},"498a":function(e,t,r){"use strict";var a=r("23e7"),i=r("58a8").trim,s=r("c8d2");a({target:"String",proto:!0,forced:s("trim")},{trim:function(){return i(this)}})},6520:function(e,t,r){"use strict";r("35e3")},"841c":function(e,t,r){"use strict";var a=r("c65b"),i=r("d784"),s=r("825a"),n=r("861d"),o=r("1d80"),c=r("129f"),l=r("577e"),u=r("dc4a"),d=r("14c3");i("search",(function(e,t,r){return[function(t){var r=o(this),i=n(t)?u(t,e):void 0;return i?a(i,t,r):new RegExp(t)[e](l(r))},function(e){var a=s(this),i=l(e),n=r(t,a,i);if(n.done)return n.value;var o=a.lastIndex;c(o,0)||(a.lastIndex=0);var u=d(a,i);return c(a.lastIndex,o)||(a.lastIndex=o),null===u?-1:u.index}]}))},a0dd:function(e,t,r){},c8d2:function(e,t,r){"use strict";var a=r("5e77").PROPER,i=r("d039"),s=r("5899"),n="​…᠎";e.exports=function(e){return i((function(){return!!s[e]()||n[e]()!==n||a&&s[e].name!==e}))}},d866:function(e,t,r){"use strict";var a=r("23e7"),i=r("c65b"),s=r("2266"),n=r("59ed"),o=r("825a"),c=r("46c4"),l=r("2a62"),u=r("f99f"),d=u("every",TypeError);a({target:"Iterator",proto:!0,real:!0,forced:d},{every:function(e){o(this);try{n(e)}catch(a){l(this,"throw",a)}if(d)return i(d,this,e);var t=c(this),r=0;return!s(t,(function(t,a){if(!e(t,r++))return a()}),{IS_RECORD:!0,INTERRUPTED:!0}).stopped}})},f0ed:function(e,t,r){"use strict";r("a0dd")}}]);