(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-622082f6"],{"8b31":function(e,t,r){},be8b:function(e,t,r){"use strict";r("8b31")},c331:function(e,t,r){"use strict";r.r(t);r("a4d3"),r("e01a");var a=function(){var e=this,t=e._self._c;return t("div",{staticClass:"main-content"},[t("breadcumb",{attrs:{page:this.$route.id?"Edit Pembinaan":"Tambah Pembinaan",folder:"Pembinaan"}}),t("b-card",{ref:"formContainer",staticClass:"wrapper"},[t("b-form",{on:{submit:function(t){return t.preventDefault(),e.onSubmit.apply(null,arguments)}}},[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-3",attrs:{"label-for":"description",label:"Short 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("short deskripsi")},attrs:{id:"description",placeholder:"Masukkan Short Deskripsi",name:"short deskripsi",rows:"6","max-rows":"6"},on:{keydown:e.onKeyDown,input:e.onDescriptionInput},model:{value:e.form.shortDescription,callback:function(t){e.$set(e.form,"shortDescription",t)},expression:"form.shortDescription"}}),t("small",[e._v(e._s(e.form.shortDescription.length)+" / 100 karakter")]),t("p",{directives:[{name:"show",rawName:"v-show",value:e.errors.has("short deskripsi"),expression:"errors.has('short deskripsi')"}],staticClass:"text-danger"},[e._v(" "+e._s(e.errors.first("short 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.sourceName,callback:function(t){e.$set(e.form,"sourceName",t)},expression:"form.sourceName"}}):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:"Deksripsi","label-for":"input-1"}},[t("vue-editor",{directives:[{name:"validate",rawName:"v-validate",value:"required|min:10",expression:"'required|min:10'"}],class:{input:!0,"is-danger":e.errors.has("deskripsi")},attrs:{useCustomImageHandler:"",name:"deskripsi",id:"responsibilityEdit"},on:{"image-added":e.handleImageAdded},model:{value:e.form.description,callback:function(t){e.$set(e.form,"description",t)},expression:"form.description"}}),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:"Foto"}},[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"}],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):e.removeFormFile(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.addFormFile}}):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):e.removeFormFile(a,!0)}}}):e._e()])])})),t("small",{staticClass:"text-muted"},[e._v("Maksimal 10 gambar beserta deskripsinya.")])],2):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)},s=[],i=r("c7eb"),o=r("1da1"),n=r("5530"),c=r("668b"),l=(r("99af"),r("4de4"),r("7db0"),r("c740"),r("caad"),r("d81d"),r("14d9"),r("fb6a"),r("a434"),r("e9f5"),r("910d"),r("f665"),r("7d54"),r("ab43"),r("d3b7"),r("2532"),r("3ca3"),r("159b"),r("ddb0"),r("5873")),u=r("95c3"),d=r.n(u),m=(r("6107"),r("7c8d")),p=r.n(m),h={name:"CoachingForm",components:{VueEditor:l["a"],VueCropper:d.a},data:function(){return{form:{title:"",shortDescription:"",description:"",images:[{src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1}],imageGalleries:[],coachingIds:[],mediaTypes:"image",sourceName:null,source:null},sources:[],userSource:!1,isBusy:!1,loading:!1}},watch:{"$route.params.uuid":{handler:function(e){e&&this.getCoachingDetail()},immediate:!0}},computed:{sourceList:function(){return this.sources.map((function(e){return{value:e.source_id,text:e.source_name}}))}},mounted:function(){this.loadSources()},methods:{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.sourceName=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")}))},getCoachingDetail:function(){var e=this;this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","events/").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.shortDescription=r.short_deskripsi,e.form.description=r.deskripsi||"",e.form.source=r.source_id||"",e.getEventDetailList(r.event_id)})).catch((function(t){e.$store.dispatch("error",t)}))},getEventDetailList:function(e){var t=this;this.$http.get("".concat("https://orchestrator.bwa.id/api/v1/","event-details?event_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=[],r.data.forEach((function(e){t.form.images.push({src:e.file_gambar,desc:e.deskripsi&&!e.deskripsi.includes("null")?e.deskripsi:"",id:e.event_detail_id,cropImg:"",file:null,isExist:!0})}))),0===t.form.images.length&&t.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1})})).catch((function(e){t.$store.dispatch("error",e)}))},onDescriptionInput:function(e){e.length<=100?this.form.shortDescription=e:this.form.shortDescription=e.slice(0,100)},onKeyDown:function(e){var t=["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"];!(this.form.shortDescription.length>=100)||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()},handleImageAdded:function(e,t,r,a){var s=this,i=new FormData;i.append("file",e),this.$http.post("".concat("https://orchestrator.bwa.id/api/v1/","file-assets"),i,{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(e){var s=e.data.file_url;t.insertEmbed(r,"image",s),a()})).catch((function(e){s.$store.dispatch("error",e)}))},onImageChange:function(e,t){var r=this,a=e.target.files[0];if(a){var s=new FileReader;s.onload=function(e){r.$set(r.form.images,t,e.target.result);var s=r.form.imageGalleries.findIndex((function(e){return e.id===t})),i={id:t,file:a};-1!==s?r.form.imageGalleries.splice(s,1,i):r.form.imageGalleries.push(i)},s.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 s=new FileReader;s.onload=function(e){var s;r.$set(r.form.images,t,Object(n["a"])(Object(n["a"])({},r.form.images[t]),{},{src:e.target.result,file:a,cropImg:"",desc:(null===(s=r.form.images[t])||void 0===s?void 0:s.desc)||"",isExist:!1}))},s.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(n["a"])(Object(n["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(o["a"])(Object(i["a"])().mark((function t(){return Object(i["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=Object(o["a"])(Object(i["a"])().mark((function t(r,a){return Object(i["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:try{e.toBlob((function(e){e.size>1048576?new p.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(s){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;return Object(o["a"])(Object(i["a"])().mark((function t(){var r,a,s,o,n,l,u,d,m,p,h,f,g,v,b,k,x,w;return Object(i["a"])().wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,e.$validator.validateAll();case 2:if(r=t.sent,r){t.next=5;break}return t.abrupt("return");case 5:if(a=function(){return e.form.images.map((function(e){return e.file?e.file:e.src?e.src:null})).filter((function(e){return e}))},0!==a().length){t.next=9;break}return e.$store.dispatch("error","Gambar tidak boleh kosong"),t.abrupt("return");case 9:return e.loading=!0,s=!!e.$route.params.uuid,o={judul:e.form.title,short_deskripsi:e.form.shortDescription,deskripsi:e.form.description,source_id:e.form.source},s&&(o._method="PATCH"),t.prev=13,t.next=16,e.$http.post(s?"".concat("https://orchestrator.bwa.id/api/v1/","events/").concat(e.$route.params.uuid):"".concat("https://orchestrator.bwa.id/api/v1/","events"),o,{headers:{Authorization:"Bearer ".concat(e.$store.getters["accessToken"])}});case 16:if(n=t.sent,l=n.data.event_id||e.$route.params.uuid,u=e.form.images.filter((function(e){return!e.id&&e.file})),d=!1,!(u.length>0)){t.next=68;break}t.prev=21,m=0,p=!1,h=!1,t.prev=25,g=Object(c["a"])(u);case 27:return t.next=29,g.next();case 29:if(!(p=!(v=t.sent).done)){t.next=44;break}if(b=v.value,!b.file||"function"!==typeof b.file.toBlob){t.next=39;break}return t.next=34,e.getImageBlob(b.file);case 34:return k=t.sent,t.next=37,e.onSubmitGalleryDetail(l,k,b.desc,b.id);case 37:t.next=40;break;case 39:e.$store.dispatch("error","File gambar "+(m+1)+" tidak valid atau tidak dapat diubah menjadi Blob");case 40:m++;case 41:p=!1,t.next=27;break;case 44:t.next=50;break;case 46:t.prev=46,t.t0=t["catch"](25),h=!0,f=t.t0;case 50:if(t.prev=50,t.prev=51,!p||null==g.return){t.next=55;break}return t.next=55,g.return();case 55:if(t.prev=55,!h){t.next=58;break}throw f;case 58:return t.finish(55);case 59:return t.finish(50);case 60:d=!0,t.next=66;break;case 63:t.prev=63,t.t1=t["catch"](21),e.$store.dispatch("error","Gagal menyimpan salah satu gambar");case 66:t.next=80;break;case 68:if(x=e.form.images.filter((function(e){return e.id})),!(x.length>0)){t.next=80;break}return w=x.map((function(t){return new Promise((function(r,a){try{e.onSubmitGalleryDetail(l,null,t.desc,t.id),r(!0)}catch(s){a(s)}}))})),t.prev=71,t.next=74,Promise.all(w);case 74:d=!0,t.next=80;break;case 77:t.prev=77,t.t2=t["catch"](71),e.$store.dispatch("error","Gagal menyimpan salah satu gambar");case 80:e.loading=!1,d?(e.$store.dispatch("success","Berhasil menyimpan pembinaan"),e.$router.push("/app/coaching")):e.onDeleteCoaching(n.data.event_id),t.next=87;break;case 84:t.prev=84,t.t3=t["catch"](13),e.$store.dispatch("error",t.t3);case 87:return t.prev=87,e.loading=!1,t.finish(87);case 90:case"end":return t.stop()}}),t,null,[[13,84,87,90],[21,63],[25,46,50,60],[51,,55,59],[71,77]])})))()},onSubmitGalleryDetail:function(e,t){var r=arguments,a=this;return Object(o["a"])(Object(i["a"])().mark((function s(){var o,n,c,l,u;return Object(i["a"])().wrap((function(s){while(1)switch(s.prev=s.next){case 0:return o=r.length>2&&void 0!==r[2]?r[2]:"",n=r.length>3?r[3]:void 0,c=!!n,l=new FormData,l.append("event_id",e),t&&l.append("file_gambar",t),l.append("deskripsi",o||""),c&&l.append("_method","PATCH"),u=c?"".concat("https://orchestrator.bwa.id/api/v1/","event-details/").concat(n):"".concat("https://orchestrator.bwa.id/api/v1/","event-details"),s.abrupt("return",a.$http.post(u,l,{headers:{Authorization:"Bearer ".concat(a.$store.getters["accessToken"])}}));case 10:case"end":return s.stop()}}),s)})))()},onDeleteCoaching:function(e){this.$http.delete("".concat("https://orchestrator.bwa.id/api/v1/","events/").concat(e),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(){})).catch((function(){}))},addFormFile:function(){"image"===this.form.mediaTypes&&this.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null})},removeFormFile:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.form.images.forEach((function(t,r){r===e&&(t.src=null,t.cropImg="",t.file=null,t.desc="",t.id=null,t.isExist=!1)})),t&&this.form.images.length>0&&this.form.images.pop()},removeGalleryImage:function(e,t){var r=this,a=this.form.images.find((function(t){return t.id===e}));if(a)t&&this.$http.delete("".concat("https://orchestrator.bwa.id/api/v1/","event-details/").concat(e),{headers:{Authorization:"Bearer ".concat(this.$store.getters["accessToken"])}}).then((function(){r.$store.dispatch("success","Berhasil menghapus gambar"),r.loading=!1;var t=r.form.images.findIndex((function(t){return t.id===e}));r.form.images.splice(t,1),0===r.form.images.length&&r.form.images.push({src:null,cropImg:"",file:null,desc:"",id:null,isExist:!1})})).catch((function(e){r.$store.dispatch("error",e),r.loading=!1}));else{var s=this.form.images.findIndex((function(t){return t.id===e}));this.form.images.splice(s,1)}}}},f=h,g=(r("be8b"),r("2877")),v=Object(g["a"])(f,a,s,!1,null,"4e172dbf",null);t["default"]=v.exports}}]);