"use strict";(self.webpackChunkarter=self.webpackChunkarter||[]).push([[139],{28139:function(e,t,i){i.d(t,{z:function(){return M}});var n=i(64762),a=i(88720),o=i(3679),s=i(49670),r=i(79765),c=i(94402),g=i(35758),l=i(45435),d=i(43190),m=i(7821),h=i(89042),u=i(95389),f=i(38583);const p=["file"];function b(e,t){if(1&e){const e=a.EpF();a.TgZ(0,"span",13),a.NdJ("click",function(){a.CHM(e);const t=a.oxw(3).$implicit;return a.oxw().editImage(t)}),a._UZ(1,"i",14),a.qZA()}}function I(e,t){if(1&e){const e=a.EpF();a.TgZ(0,"span",15),a.NdJ("click",function(){a.CHM(e);const t=a.oxw(3).$implicit;return a.oxw().rotateImage(t)}),a._UZ(1,"i",16),a.qZA()}}function v(e,t){if(1&e){const e=a.EpF();a.TgZ(0,"span",17),a.NdJ("click",function(){a.CHM(e);const t=a.oxw(3).$implicit;return a.oxw().sortImage(t,-1)}),a._UZ(1,"i",18),a.qZA()}}function x(e,t){if(1&e){const e=a.EpF();a.TgZ(0,"span",17),a.NdJ("click",function(){a.CHM(e);const t=a.oxw(3).$implicit;return a.oxw().sortImage(t,1)}),a._UZ(1,"i",19),a.qZA()}}function w(e,t){if(1&e){const e=a.EpF();a.TgZ(0,"span",20),a.NdJ("click",function(){a.CHM(e);const t=a.oxw(3).$implicit;return a.oxw().clearImage(t,!0)}),a._uU(1,"\xd7"),a.qZA()}}function C(e,t){if(1&e&&(a.TgZ(0,"div",8),a.YNc(1,b,2,0,"span",9),a.YNc(2,I,2,0,"span",10),a.YNc(3,v,2,0,"span",11),a.YNc(4,x,2,0,"span",11),a.YNc(5,w,2,0,"span",12),a.qZA()),2&e){const e=a.oxw(2).$implicit,t=a.oxw();a.xp6(1),a.Q6J("ngIf",t.canEdit()),a.xp6(1),a.Q6J("ngIf",t.canRotate(e)),a.xp6(1),a.Q6J("ngIf",t.canSort),a.xp6(1),a.Q6J("ngIf",t.canSort),a.xp6(1),a.Q6J("ngIf",e.canRemove)}}const k=function(){return{"mb-3":"item.mediaUrl","mr-1":!0}};function S(e,t){if(1&e&&(a.TgZ(0,"div"),a.TgZ(1,"div",4),a._UZ(2,"img",5,6),a.YNc(4,C,6,5,"div",7),a.qZA(),a.qZA()),2&e){const e=a.oxw().$implicit,t=a.oxw();a.xp6(1),a.Q6J("ngClass",a.DdM(3,k)),a.xp6(1),a.Q6J("src",e.mediaUrl,a.LSH),a.xp6(2),a.Q6J("ngIf",!t.isSorting)}}function D(e,t){if(1&e&&(a.ynx(0),a.YNc(1,S,5,4,"div",3),a.BQk()),2&e){const e=t.$implicit;a.xp6(1),a.Q6J("ngIf",e.mediaUrl)}}function y(e,t){if(1&e){const e=a.EpF();a.ynx(0),a.TgZ(1,"label",21),a._uU(2),a.TgZ(3,"input",22,23),a.NdJ("change",function(){a.CHM(e);const t=a.MAs(4);return a.oxw().onFileChange(t.files)}),a.qZA(),a.qZA(),a.BQk()}if(2&e){const e=a.oxw();a.xp6(2),a.hij(" ",e.selectFileButtonText," ")}}let M=(()=>{class e{constructor(e,t,i){this.cdRef=e,this.fileService=t,this.translate=i,this.action$=new r.xQ,this.loadImage=this.action$.pipe((0,l.h)(e=>null!==e&&e.length>0),(0,d.w)(e=>{const t=e.map(e=>(0,c.D)(this.readImage(e)));return(0,g.D)(t)})).subscribe(e=>{this.maskAsDeleteAction(!1),this.cdRef.markForCheck()}),this.$enableSorting=!1,this.canSort=!1,this.sources=new Array,this.imageEditClicked=new a.vpe,this.deleteChanged=new a.vpe,this.sortChanged=new a.vpe,this.addDataSourceTranscriptItem=new a.vpe,this.fileChanged=new a.vpe,this.restrainDeleteImage=!0,this.maxImages=100,this.allowedFileTypes=["image/png","image/jpeg"],this.isSorting=!1,this.isRotating=!1,this.imageFileService=new m.U,this.onChange=e=>{}}set enableSorting(e){this.$enableSorting=e,this.canSort=!0}ngOnInit(){this.getSelectFileButtonText()}ngOnDestroy(){this.action$.unsubscribe(),this.loadImage.unsubscribe()}getSelectFileButtonText(){this.selectFileButtonText||this.translate.get("select_image.lbl_select_image_from_computer").subscribe(e=>{this.selectFileButtonText=e,this.cdRef.markForCheck()})}writeValue(e){e?(this.sources=e,this.updateRemoveAbleItem(),this.cdRef.markForCheck()):(this.sources=[],this.file&&this.file.nativeElement&&(this.file.nativeElement.value=null),this.cdRef.markForCheck())}registerOnChange(e){this.onChange=e}registerOnTouched(e){}setDisabledState(e){}onFileChange(e){if(0===e.length)return;const t=[];for(let n=0;n<e.length&&n<5;n++){const i=e[n];this.allowedFileTypes.includes(i.type)&&t.push(i)}const i=Array.from(t.slice(0,5));this.action$.next(i),this.fileChanged.emit(i),this.cdRef.markForCheck()}readImage(e){return(0,n.mG)(this,void 0,void 0,function*(){const t=yield this.imageFileService.readAsDataURL(e);yield this.setImageData(e.name,t,e)})}setImageData(e,t,i){return(0,n.mG)(this,void 0,void 0,function*(){(yield this.readImageInfo(t,e,i))&&this.cdRef.detectChanges()})}readImageInfo(e,t,i){return(0,n.mG)(this,void 0,void 0,function*(){if(this.sources.length>4)return;if(this.sources.length>=this.maxImages){if(this.maxImages>1)return;this.sources[0].imgName!==t&&(this.sources.length=0)}const n=this.sources.find(e=>e.imgName===t);if(void 0!==n)return n.mediaUrl=e,!1;const a={latMap:null,longMap:null,locationModel:null,observationDateTime:null,zoom:null,mediaUrl:null,imgName:null,canRemove:!0,orientation:null,isSubmitted:!1},o=new Date(i.lastModified);return this.addDataSourceTranscriptItem.emit(["Billedfil \xe6ndret: ",o.toISOString()]),a.observationDateTime=o,a.mediaUrl=e,a.imgName=t,this.imageFileService.extractExifInformationIntoModel(a,e,this.addDataSourceTranscriptItem),this.sources.push(a),this.updateRemoveAbleItem(),yield this.reorientResizeImage(e,a.orientation,a.imgName,i),!1})}reorientResizeImage(e,t,i,a){return(0,n.mG)(this,void 0,void 0,function*(){const n=new Image;n.src=e;const o=(yield this.imageFileService.getCanvasSize(n,t)).toDataURL("image/jpeg",100);yield this.setImageData(i,o,a),this.onChange(this.sources),this.maskAsDeleteAction(!1)})}getMediaUrl(e){return e.includes(s.X.settings.suffixInternalMediaUrl)?this.fileService.getSmallUrl(e):e}clearImage(e,t=!0){this.sources=this.sources.filter(e&&e.imgName?t=>t.imgName!==e.imgName:e&&e.id?t=>t.id!==e.id:t=>t.imgName!==e),this.file&&this.file.nativeElement.value.includes(null==e?void 0:e.imgName)&&(this.file.nativeElement.value=null),this.updateRemoveAbleItem(),this.maskAsDeleteAction(t),this.onChange(this.sources),this.cdRef.markForCheck()}canEdit(){return this.imageEditClicked.observers.length>0}editImage(e){this.imageEditClicked.emit(e)}rotateImage(e){if(this.isRotating)return;let t;e&&e.imgName?t=this.sources.find(t=>t.imgName===e.imgName):e&&e.id&&(t=this.sources.find(t=>t.id===e.id)),this.isRotating=!0,e&&this.rotateImage45Degress(t)}rotateImage45Degress(e){const t=document.createElement("canvas"),i=t.getContext("2d"),n=new Image;n.onload=()=>{const a=n.width;t.width=n.height,t.height=a,i.transform(0,-1,1,0,0,a),i.drawImage(n,0,0);const o=t.toDataURL("image/jpeg",1);e.id&&!e.imgName&&(e.imgName=e.id+".jpeg"),e.mediaUrl=o,this.cdRef.detectChanges(),this.isRotating=!1,this.onChange(this.sources)},n.src=e.mediaUrl,n.crossOrigin="Anonymous"}updateRemoveAbleItem(){this.sources.length>1?(this.sources.forEach(e=>{e.canRemove=!0}),this.canSort=this.$enableSorting):(this.canSort=!1,this.sources.forEach(e=>{e.canRemove=!this.restrainDeleteImage}),this.sources.forEach(e=>{e.canRemove=void 0===e.id?this.mayDeleteLastImage:!this.restrainDeleteImage}))}maskAsDeleteAction(e){this.sources.forEach(t=>{t.isDeleteAction=e})}sortImage(e,t){const i=this.sources.indexOf(e),n=i+t,a=this.sources.length;n<0?this.sources.splice(a,0,this.sources.splice(0,1)[0]):n>=a?this.sources.splice(0,0,this.sources.splice(a-1,1)[0]):this.sources.splice(n,0,this.sources.splice(i,1)[0]),this.onChange(this.sources),this.sortChanged.emit(this.sources)}canRotate(e){return!0}}return e.\u0275fac=function(t){return new(t||e)(a.Y36(a.sBO),a.Y36(h.Ip),a.Y36(u.sK))},e.\u0275cmp=a.Xpm({type:e,selectors:[["app-select-image"]],viewQuery:function(e,t){if(1&e&&a.Gf(p,5),2&e){let e;a.iGM(e=a.CRH())&&(t.file=e.first)}},inputs:{restrainDeleteImage:"restrainDeleteImage",maxImages:"maxImages",enableSorting:"enableSorting",taxonId:"taxonId",taxonEtag:"taxonEtag",mayDeleteLastImage:"mayDeleteLastImage",hideInputFile:"hideInputFile",isSorting:"isSorting",isRotating:"isRotating",selectFileButtonText:"selectFileButtonText"},outputs:{imageEditClicked:"imageEditClicked",deleteChanged:"deleteChanged",sortChanged:"sortChanged",addDataSourceTranscriptItem:"addDataSourceTranscriptItem",fileChanged:"fileChanged"},features:[a._Bn([{provide:o.JU,useExisting:e,multi:!0}])],decls:4,vars:2,consts:[[1,"mt-2"],[1,"d-flex","flex-wrap"],[4,"ngFor","ngForOf"],[4,"ngIf"],["id","preview",1,"preview-image",3,"ngClass"],["width","100%",2,"image-orientation","from-image",3,"src"],["imgElement",""],["class","button-menu",4,"ngIf"],[1,"button-menu"],["id","editImage","aria-hidden","true","class","badge badge-dark mr-1",3,"click",4,"ngIf"],["class","badge badge-dark mr-1",3,"click",4,"ngIf"],["id","clearImage","aria-hidden","true","class","badge badge-dark mr-1",3,"click",4,"ngIf"],["id","clearImage","aria-hidden","true","class","badge badge-dark",3,"click",4,"ngIf"],["id","editImage","aria-hidden","true",1,"badge","badge-dark","mr-1",3,"click"],[1,"far","fa-pen","fa-xs"],[1,"badge","badge-dark","mr-1",3,"click"],[1,"fas","fa-undo","fa-xs"],["id","clearImage","aria-hidden","true",1,"badge","badge-dark","mr-1",3,"click"],[1,"far","fa-chevron-left","fa-xs"],[1,"far","fa-chevron-right","fa-xs"],["id","clearImage","aria-hidden","true",1,"badge","badge-dark",3,"click"],[1,"btn","btn-primary","btn-sm","mb-0"],["type","file","name","file","hidden","","multiple","",3,"change"],["file",""]],template:function(e,t){1&e&&(a.TgZ(0,"div",0),a.TgZ(1,"div",1),a.YNc(2,D,2,1,"ng-container",2),a.qZA(),a.YNc(3,y,5,1,"ng-container",3),a.qZA()),2&e&&(a.xp6(2),a.Q6J("ngForOf",t.sources),a.xp6(1),a.Q6J("ngIf",!t.isSorting&&!t.hideInputFile))},directives:[f.sg,f.O5,f.mk],styles:['@import"https://fonts.googleapis.com/css?family=Roboto+Slab:300,400,700&display=swap";@import\'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,600,600i,700,700i,900,900i&display=swap" rel="stylesheet\';.blue-tint[_ngcontent-%COMP%]{background:rgba(64,71,88,.25);background:linear-gradient(135deg,rgba(64,71,88,.25) 0%,rgba(158,108,80,.25) 99%)}.bg-blue-gradient[_ngcontent-%COMP%]{background:#404758;background:linear-gradient(135deg,#404758 0%,#765d54 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#404758",endColorstr="#765d54",GradientType=1)}.preview-image[_ngcontent-%COMP%]{line-height:0;max-height:30rem;position:relative;display:inline-block}.preview-image[_ngcontent-%COMP%] img[_ngcontent-%COMP%]{max-width:100%;max-height:10rem;width:auto;height:auto;box-shadow:0 10px 32px #65594a0f,0 2px 9px #65594a05;border-radius:.4rem}.preview-image[_ngcontent-%COMP%] .overlay[_ngcontent-%COMP%]{position:absolute;top:auto;bottom:0;color:#fff;left:0;right:0;background:black;height:4rem;width:100%;line-height:1rem;vertical-align:middle;font-family:"Roboto Slab","Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";border-bottom-right-radius:.4rem;border-bottom-left-radius:.4rem;padding-right:.5rem;padding-left:.5rem;padding-bottom:.5rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;background:linear-gradient(to bottom,rgba(0,0,0,0) 0%,rgba(0,0,0,.63) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#00000000",endColorstr="#a1000000",GradientType=0)}.preview-image[_ngcontent-%COMP%] .overlay[_ngcontent-%COMP%] small[_ngcontent-%COMP%]{line-height:6rem}.preview-image[_ngcontent-%COMP%] .button-menu[_ngcontent-%COMP%]{position:absolute;top:-2px;right:-2px;z-index:100}.preview-image[_ngcontent-%COMP%] .button-menu[_ngcontent-%COMP%] .badge[_ngcontent-%COMP%]{color:#fff;border-radius:30%;cursor:pointer}.preview-image[_ngcontent-%COMP%] .button-menu[_ngcontent-%COMP%] .badge.disabled[_ngcontent-%COMP%]{background-color:gray;opacity:.6}'],changeDetection:0}),e})()},7821:function(e,t,i){i.d(t,{U:function(){return o}});var n=i(64762),a=i(49670);class o{readAsDataURL(e){return(0,n.mG)(this,void 0,void 0,function*(){return new Promise((t,i)=>{if(null==e.type.match(/image\/*/))return;const n=new FileReader;n.readAsDataURL(e),n.onload=()=>{t(n.result)}})})}extractExifInformationIntoModel(e,t,i){if(EXIF){const a=EXIF.readFromBinaryFile(this.base64ToArrayBuffer(t));if(a){i&&i.emit(["Exif: ","Billedet indeholder Exif-oplysninger"]);const t=a.GPSLatitude,o=a.GPSLongitude,s=a.DateTimeDigitized?a.DateTimeDigitized:a.DateTime;if(e.orientation=a.Orientation,t&&o){t.toString(),i&&i.emit(["Exif-lokalitet: ","Lat: "+t+a.GPSLatitudeRef+" Long: "+o+a.GPSLongitudeRef]),i&&i.emit(["Exif-lokalitet: ","Lat: "+t[0].numerator+"/"+t[0].denominator+","+t[1].numerator+"/"+t[1].denominator+","+t[2].numerator+"/"+t[2].denominator+a.GPSLatitudeRef+" Long: "+o[0].numerator+"/"+o[0].denominator+","+o[1].numerator+"/"+o[1].denominator+","+o[2].numerator+"/"+o[2].denominator+a.GPSLongitudeRef]);const n=a.GPSLongitudeRef||"W";e.latMap=(t[0]+t[1]/60+t[2]/3600)*("N"===(a.GPSLatitudeRef||"N")?1:-1),e.longMap=(o[0]+o[1]/60+o[2]/3600)*("W"===n?-1:1),e.locationModel={location:{lat:+e.latMap,lng:+e.longMap}},e.zoom=11}if(s){i&&i.emit(["Exif-dato: ",s]);const t=s.split(" "),a=t[0].replace(/:/g,"-")+" "+t[1];try{const t=new Date(a);isNaN(t.getTime())||(e.observationDateTime=t)}catch(n){}}}}else i&&i.emit(["Fejl: ","Der skete en fejl under indl\xe6sning af EXIF-biblioteket"])}getCanvasSize(e,t){return(0,n.mG)(this,void 0,void 0,function*(){const i=document.createElement("canvas"),n=i.getContext("2d");return new Promise((o,s)=>{e.onload=()=>{const s=e.width,r=e.height;if(i.height=e.height,i.width=e.width,navigator.userAgent.toLowerCase().indexOf("firefox")>-1)switch(t>4&&(i.height=e.width,i.width=e.height),t){case 2:n.transform(-1,0,0,1,s,0);break;case 3:n.transform(-1,0,0,-1,s,r);break;case 4:n.transform(1,0,0,-1,0,r);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,r,0);break;case 7:n.transform(0,-1,-1,0,r,s);break;case 8:n.transform(0,-1,1,0,0,s)}var c=Math.min(a.X.settings.imageMaxWidth,e.width),g=0;0===g?(g=e.height*c/e.width)>c&&(c=e.width*(g=c)/e.height):(c=e.width*g/e.height)>g&&(g=e.height*(c=g)/e.width),i.width=c,i.height=g,n.drawImage(e,0,0,c,g),o(i)}})})}base64ToArrayBuffer(e){e=e.replace(/^data\:([^\;]+)\;base64,/gim,"");const t=atob(e),i=t.length,n=new Uint8Array(i);for(let a=0;a<i;a++)n[a]=t.charCodeAt(a);return n.buffer}}}}]);