!function(e,o,i,r){"use strict";i(document).ready((function(){var s=function(e){this._baseUrl=e,this._persons=[],this._activePerson=r,this._clustersByName=[],this._unassignedClusters=[],this._ignoredClusters=[],this._loaded=!1,this._mustReload=!1};s.prototype={isLoaded:function(){return this._loaded},mustReload:function(){return this._mustReload},load:function(){var e=i.Deferred(),n=this;return i.get(this._baseUrl+"/persons").done((function(o){n._persons=o.persons.sort((function(e,n){return n.count-e.count})),n._loaded=!0,n._mustReload=!1,e.resolve()})).fail((function(){e.reject()})),e.promise()},loadPerson:function(e){this.unsetActive();var n=i.Deferred(),o=this;return i.get(this._baseUrl+"/person/"+encodeURIComponent(e)).done((function(e){o._activePerson=e,n.resolve()})).fail((function(){n.reject()})),n.promise()},getPersons:function(){return this._persons},getActivePerson:function(){return this._activePerson},renamePerson:function(e,n){var o=this,t=i.Deferred(),r={name:n};return i.ajax({url:this._baseUrl+"/person/"+encodeURIComponent(e),method:"PUT",contentType:"application/json",data:JSON.stringify(r)}).done((function(e){o._activePerson=e,o._mustReload=!0,t.resolve()})).fail((function(){t.reject()})),t.promise()},setVisibility:function(e,n){var o=this,t=i.Deferred(),r={visible:n};return i.ajax({url:this._baseUrl+"/person/"+encodeURIComponent(e)+"/visibility",method:"POST",contentType:"application/json",data:JSON.stringify(r)}).done((function(e){o._mustReload=!0,t.resolve()})).fail((function(){t.reject()})),t.promise()},loadClustersByName:function(e){var n=i.Deferred(),o=this;return i.get(this._baseUrl+"/clusters/"+encodeURIComponent(e)).done((function(e){o._clustersByName=e.clusters.sort((function(e,n){return n.count-e.count})),n.resolve()})).fail((function(){n.reject()})),n.promise()},loadUnassignedClusters:function(){this._unassignedClusters=[];var e=i.Deferred(),n=this;return i.get(this._baseUrl+"/clusters").done((function(o){n._unassignedClusters=o.clusters.sort((function(e,n){return n.count-e.count})),e.resolve()})).fail((function(){e.reject()})),e.promise()},loadIgnoredClusters:function(){this._ignoredClusters=[];var e=i.Deferred(),n=this;return i.get(this._baseUrl+"/clustersIgnored").done((function(o){n._ignoredClusters=o.clusters.sort((function(e,n){return n.count-e.count})),e.resolve()})).fail((function(){e.reject()})),e.promise()},getClustersByName:function(){return this._clustersByName},getUnassignedClusters:function(){return this._unassignedClusters},getIgnoredClusters:function(){return this._ignoredClusters},getNamedClusterById:function(e){var n=r;for(var o of this._clustersByName)if(o.id===e){n=o;break}return n},renameCluster:function(e,n){var o=this,t=i.Deferred(),r={name:n};return i.ajax({url:this._baseUrl+"/cluster/"+e,method:"PUT",contentType:"application/json",data:JSON.stringify(r)}).done((function(i){o._clustersByName.forEach((function(o){o.id===e&&(o.name=n)})),o._mustReload=!0,t.resolve()})).fail((function(){t.reject()})),t.promise()},setClusterVisibility:function(e,n){var o=this,t=i.Deferred(),r={visible:n};return i.ajax({url:this._baseUrl+"/cluster/"+e+"/visibility",method:"POST",contentType:"application/json",data:JSON.stringify(r)}).done((function(n){var i=o._clustersByName.findIndex((n=>n.id===e));o._clustersByName.splice(i,1),o._mustReload=!0,t.resolve()})).fail((function(){t.reject()})),t.promise()},unsetActive:function(){this._activePerson=r,this._clustersByName=[]}};var a=function(e){this._enabled=OCP.InitialState.loadState("facerecognition","user-enabled"),this._hasUnamed=OCP.InitialState.loadState("facerecognition","has-unamed"),this._hasHidden=OCP.InitialState.loadState("facerecognition","has-hidden"),this._persons=e,this._observer=lozad(".lozad")};a.prototype={reload:function(n){var o=this;this._persons.load().done((function(){o.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error trying to show your friends"))}))},setEnabledUser:function(n){var o=this;i.ajax({type:"POST",url:e.generateUrl("apps/facerecognition/setuservalue"),data:{type:"enabled",value:n},success:function(){n?e.Notification.showTemporary(t("facerecognition","The analysis is enabled, please be patient, you will soon see your friends here.")):e.Notification.showTemporary(t("facerecognition","The analysis is disabled. Soon all the information found for facial recognition will be removed.")),o._enabled=n,o.reload()}})},renameUnassignedClusterDialog:function(){var n=this,o=this._persons.getUnassignedClusters().shift();if(o===r)return e.Notification.showTemporary(t("facerecognition","You don't have more people to recognize.")),n.renderContent(),void(n._persons.mustReload()&&n.reload());FrDialogs.assignName(o.faces,(function(i,r){!0===i?null!==r?r.length>0?n._persons.renameCluster(o.id,r).done((function(){n.renameUnassignedClusterDialog()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error renaming this person"))})):n.renameUnassignedClusterDialog():n._persons.setClusterVisibility(o.id,!1).done((function(){n.renameUnassignedClusterDialog()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error ignoring this person"))})):n._persons.mustReload()&&n.reload()}))},renameIgnoredClusterDialog:function(){var n=this,o=this._persons.getIgnoredClusters().shift();if(o===r)return e.Notification.showTemporary(t("facerecognition","You no longer have people ignored")),n.renderContent(),void(n._persons.mustReload()&&n.reload());FrDialogs.assignIgnored(o.faces,(function(i,r){!0===i?null!==r&&r.length>0?n._persons.renameCluster(o.id,r).done((function(){n.renameIgnoredClusterDialog()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error renaming this person"))})):n.renameIgnoredClusterDialog():n._persons.mustReload()&&n.reload()}))},renderContent:function(){var n={loaded:this._persons.isLoaded(),appName:t("facerecognition","Face Recognition"),welcomeHint:t("facerecognition","Here you can see photos of your friends that are recognized"),enableDescription:t("facerecognition","Analyze my images and group my loved ones with similar faces"),loadingMsg:t("facerecognition","Looking for your recognized friends"),showMoreButton:t("facerecognition","Review face groups"),showIgnoredButton:t("facerecognition","Review ignored people"),emptyMsg:t("facerecognition","The analysis is disabled"),emptyHint:t("facerecognition","Enable it to find your loved ones"),renameHint:t("facerecognition","Rename"),hideHint:t("facerecognition","Hide it"),loadingIcon:e.imagePath("core","loading.gif")};!0===this._enabled&&(n.enabled=!0,n.hasUnamed=this._hasUnamed,n.hasHidden=this._hasHidden,n.persons=this._persons.getPersons(),n.reviewPeopleMsg=t("facerecognition","Review people found"),n.reviewIgnoredMsg=t("facerecognition","Review ignored people"),n.emptyMsg=t("facerecognition","Your friends have not been recognized yet"),n.emptyHint=t("facerecognition","Please, be patient"));var s=this._persons.getActivePerson();s!=r&&(n.personName=s.name,n.personImages=s.images);var a=this._persons.getClustersByName();a.length>0&&(n.clustersByName=a);var l=Handlebars.templates.personal(n);i("#div-content").html(l),this._observer.observe(),s!==r?c(s.name):c();var u=this;i("#enableFacerecognition").click((function(){!1===i(this).is(":checked")?e.dialogs.confirm(t("facerecognition","You will lose all the information analyzed, and if you re-enable it, you will start from scratch."),t("facerecognition","Do you want to deactivate the grouping by faces?"),(function(e){!0===e?u.setEnabledUser(!1):i("#enableFacerecognition").prop("checked",!0)}),!0):u.setEnabledUser(!0)})),i("#show-more-clusters").click((function(){u._persons.loadUnassignedClusters().done((function(){u._persons.getUnassignedClusters().length>0?u.renameUnassignedClusterDialog():e.Notification.showTemporary(t("facerecognition","You dont have more people to recognize."))}))})),i("#show-ignored-clusters").click((function(){u._persons.loadIgnoredClusters().done((function(){u._persons.getIgnoredClusters().length>0?u.renameIgnoredClusterDialog():e.Notification.showTemporary(t("facerecognition","You no longer have people ignored"))}))})),i("#facerecognition .file-preview-big").click((function(){var e=i(this).data("id");if(o.event.ctrlKey){var n=u._persons.getActivePerson().images.find((function(n){return n.filename==e}));o.open(n.fileUrl,"_blank")}else{var t=u._persons.getActivePerson().images.map((function(e){return{basename:e.basename,filename:e.filename,mime:e.mimetype}}));OCA.Viewer.open({path:e,list:t})}})),i("#facerecognition .face-preview-big").click((function(){i(this).css("cursor","wait");var n=i(this).parent().data("id");u._persons.loadPerson(n).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error when trying to find photos of your friend"))}))})),i("#facerecognition #rename-person").click((function(){var n=u._persons.getActivePerson();FrDialogs.rename(n.name,[n],(function(o,i){!0===o&&i&&u._persons.renamePerson(n.name,i).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error renaming this person"))}))}))})),i("#facerecognition #hide-person").click((function(){var n=u._persons.getActivePerson();FrDialogs.hide([n],(function(o){!0===o&&u._persons.setVisibility(n.name,!1).done((function(){u._persons.unsetActive(),u.reload()})).fail((function(){e.Notification.showTemporary(t("facerecognition","An error occurred while hiding this person"))}))}))})),i("#facerecognition #rename-cluster").click((function(){var n=i(this).data("id"),o=u._persons.getNamedClusterById(n);FrDialogs.rename(o.name,[o.faces[0]],(function(o,i){!0===o&&i&&u._persons.renameCluster(n,i).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error renaming this cluster of faces"))}))}))})),i("#facerecognition #hide-cluster").click((function(){var n=i(this).data("id"),o=u._persons.getNamedClusterById(n);FrDialogs.hide([o.faces[0]],(function(o){!0===o&&u._persons.setClusterVisibility(n,!1).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","An error occurred while hiding this group of faces"))}))}))})),i("#facerecognition #review-person-clusters").click((function(){i(this).css("cursor","wait");var n=u._persons.getActivePerson();u._persons.loadClustersByName(n.name).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error when trying to find photos of your friend"))}))})),i("#facerecognition #show-ignored-clusters").click((function(){i(this).css("cursor","wait");var n=u._persons.getActivePerson();u._persons.loadClustersByName(n.name).done((function(){u.renderContent()})).fail((function(){e.Notification.showTemporary(t("facerecognition","There was an error when trying to find photos of your friend"))}))})),i("#facerecognition .icon-back").click((function(){u._persons.unsetActive(),u.renderContent(),!u._persons.mustReload()&&u._persons.isLoaded()||u.reload()}))}};var c=function(e){var n=o.location.href.split("?")[0],i=t("facerecognition","Face Recognition");e&&(n+="?name="+encodeURIComponent(e),i+=" - "+e),o.history.replaceState({},i,n),document.title=i};Handlebars.registerHelper("noPhotos",(function(e){return n("facerecognition","%n image","%n images",e)}));var l=new s(e.generateUrl("/apps/facerecognition")),u=new a(l),f=function(){var e=r,n=document.createElement("a");n.href=o.location.href;for(var t=n.search.substring(1).split("&"),i=0;i