"use strict";angular.module("jtt_aping_vimeo",["jtt_vimeo"]).directive("apingVimeo",["apingVimeoHelper","apingUtilityHelper","vimeoFactory",function(n,o,s){return{require:"?aping",restrict:"A",replace:"false",link:function(e,t,i,r){var a=r.getAppSettings();o.parseJsonFromAttributes(i.apingVimeo,n.getThisPlattformString(),a).forEach(function(e){var t={model:a.model};void 0!==a.getNativeData?t.getNativeData=a.getNativeData:t.getNativeData=!1;var i={access_token:o.getApiCredentials(n.getThisPlattformString(),"access_token")};if(void 0!==e.items?i.per_page=e.items:i.per_page=a.items,0===i.per_page||"0"===i.per_page)return!1;(i.per_page<0||isNaN(i.per_page))&&(i.per_page=void 0),50<i.per_page&&(i.per_page=50),void 0!==e.search&&(i.query=e.search),e.user?(i.user=e.user,i.filter="embeddable",i.filter_embeddable=!0,s.getVideosFromUser(i).then(function(e){e&&r.concatToResults(n.getObjectByJsonData(e,t))})):e.channel?(i.channel=e.channel,i.filter="embeddable",i.filter_embeddable=!0,s.getVideosFromChannel(i).then(function(e){e&&r.concatToResults(n.getObjectByJsonData(e,t))})):e.tag?(i.tag=e.tag,s.getVideosFromTag(i).then(function(e){e&&r.concatToResults(n.getObjectByJsonData(e,t))})):e.category&&(i.category=e.category,i.filter="embeddable",i.filter_embeddable=!0,s.getVideosFromCategory(i).then(function(e){e&&r.concatToResults(n.getObjectByJsonData(e,t))}))})}}}]),angular.module("jtt_aping_vimeo").service("apingVimeoHelper",["apingModels","apingTimeHelper","apingUtilityHelper",function(r,a,e){this.getThisPlattformString=function(){return"vimeo"},this.getThisPlattformLink=function(){return"https://vimeo.com/"},this.getIdFromUri=function(e){return e.split("/").slice(-1)[0]},this.getActionCounter=function(e,t){if(e[t])return e[t].total||void 0},this.getDifference=function(e,t){return t<e?e-t:t-e},this.getImagesFromImageArray=function(e){var i=this,r={thumb_url:void 0,thumb_width:void 0,thumb_height:void 0,img_url:void 0,img_width:void 0,img_height:void 0,native_url:void 0,native_width:void 0,native_height:void 0};return e.constructor===Array&&angular.forEach(e,function(e,t){void 0!==e.link&&(void 0===r.thumb_url?(r.thumb_url=e.link,r.thumb_width=e.width,r.thumb_height=e.height):i.getDifference(r.thumb_width,200)>i.getDifference(e.width,200)&&200<=e.width&&(r.thumb_url=e.link,r.thumb_width=e.width,r.thumb_height=e.height),void 0===r.img_url?(r.img_url=e.link,r.img_width=e.width,r.img_height=e.height):i.getDifference(r.img_width,700)>i.getDifference(e.width,700)&&(r.img_url=e.link,r.img_width=e.width,r.img_height=e.height),void 0===r.native_url?(r.native_url=e.link,r.native_width=e.width,r.native_height=e.height):e.width>r.native_width&&(r.native_url=e.link,r.native_width=e.width,r.native_height=e.height))}),r},this.getObjectByJsonData=function(e,r){var a=[];if(e&&e.data){var n=this;e.data.data&&angular.forEach(e.data.data,function(e,t){var i;(i=!0===r.getNativeData||"true"===r.getNativeData?e:n.getItemByJsonData(e,r.model))&&a.push(i)})}return a},this.getItemByJsonData=function(e,t){var i={};if(e&&t)switch(t){case"social":i=this.getSocialItemByJsonData(e);break;case"video":i=this.getVideoItemByJsonData(e);break;default:return!1}return i},this.getSocialItemByJsonData=function(e){var t=r.getNew("social",this.getThisPlattformString());if(angular.extend(t,{blog_name:e.user.name,blog_id:this.getIdFromUri(e.user.uri),blog_link:e.user.link,intern_type:"video",type:"video",intern_id:this.getIdFromUri(e.uri),timestamp:a.getTimestampFromDateString(e.created_time,1e3,36e5),post_url:e.link,caption:e.name,text:e.description}),t.date_time=new Date(t.timestamp),e.pictures&&0<e.pictures.sizes.length){var i=this.getImagesFromImageArray(e.pictures.sizes);t.img_url=i.img_url||void 0,t.thumb_url=i.thumb_url||void 0,t.native_url=i.native_url||void 0}return e.embed&&e.embed.html&&(t.source=e.embed.html),t.text||(t.text=t.caption,t.caption=""),e.metadata&&e.metadata.connections&&(t.likes=this.getActionCounter(e.metadata.connections,"likes"),t.comments=this.getActionCounter(e.metadata.connections,"comments")),t},this.getVideoItemByJsonData=function(e){var t=r.getNew("video",this.getThisPlattformString());if(angular.extend(t,{blog_name:e.user.name,blog_id:this.getIdFromUri(e.user.uri),blog_link:e.user.link,intern_id:this.getIdFromUri(e.uri),timestamp:a.getTimestampFromDateString(e.created_time,1e3,36e5),post_url:e.link,caption:e.name,text:e.description,duration:e.duration,width:e.width,height:e.height}),e.pictures&&0<e.pictures.sizes.length){var i=this.getImagesFromImageArray(e.pictures.sizes);t.img_url=i.img_url||void 0,t.thumb_url=i.thumb_url||void 0,t.native_url=i.native_url||void 0}return t.date_time=new Date(t.timestamp),!(!e.embed||!e.embed.html)&&(t.markup=e.embed.html,t.text||(t.text=t.caption,t.caption=""),e.metadata&&e.metadata.connections&&(t.likes=this.getActionCounter(e.metadata.connections,"likes"),t.comments=this.getActionCounter(e.metadata.connections,"comments")),t)}}]),angular.module("jtt_vimeo",[]).factory("vimeoFactory",["$http","vimeoSearchDataService",function(i,r){var e={getVideosFromChannel:function(e){if(!e.channel)return!1;var t=r.getNew("videosFromChannel",e);return i({method:"GET",url:t.url,params:t.object})},getVideosFromCategory:function(e){if(!e.category)return!1;var t=r.getNew("videosFromCategory",e);return i({method:"GET",url:t.url,params:t.object})},getVideosFromTag:function(e){if(!e.tag)return!1;var t=r.getNew("videosFromTag",e);return i({method:"GET",url:t.url,params:t.object})},getVideosFromUser:function(e){if(!e.user)return!1;var t=r.getNew("videosFromUser",e);return i({method:"GET",url:t.url,params:t.object})}};return e}]).service("vimeoSearchDataService",function(){this.getApiBaseUrl=function(e){return"https://api.vimeo.com/"},this.fillDataInObjectByList=function(i,r,e){return angular.forEach(e,function(e,t){void 0!==r[e]&&(i.object[e]=r[e])}),i},this.getNew=function(e,t){var i={object:{access_token:t.access_token},url:""};switch(e){case"videosFromChannel":(i=this.fillDataInObjectByList(i,t,["page","query","filter","filter_embeddable","sort","direction","per_page"])).url=this.getApiBaseUrl()+"channels/"+t.channel+"/videos";break;case"videosFromCategory":(i=this.fillDataInObjectByList(i,t,["page","query","filter","filter_embeddable","sort","direction","per_page"])).url=this.getApiBaseUrl()+"categories/"+t.category+"/videos";break;case"videosFromTag":(i=this.fillDataInObjectByList(i,t,["page","query","sort","direction","per_page"])).url=this.getApiBaseUrl()+"tags/"+t.tag+"/videos";break;case"videosFromUser":(i=this.fillDataInObjectByList(i,t,["page","query","filter","filter_embeddable","sort","direction","per_page"])).url=this.getApiBaseUrl()+"users/"+t.user+"/videos"}return i}});