1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { ScreenService } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { Video } from '../shared-main'
7 selector: 'my-video-thumbnail',
8 styleUrls: [ './video-thumbnail.component.scss' ],
9 templateUrl: './video-thumbnail.component.html'
11 export class VideoThumbnailComponent {
15 @Input() videoRouterLink: any[]
16 @Input() queryParams: { [ p: string ]: any }
17 @Input() videoHref: string
18 @Input() videoTarget: string
20 @Input() displayWatchLaterPlaylist: boolean
21 @Input() inWatchLaterPlaylist: boolean
23 @Output() watchLaterClick = new EventEmitter<boolean>()
25 addToWatchLaterText: string
26 addedToWatchLaterText: string
29 private screenService: ScreenService,
32 this.addToWatchLaterText = this.i18n('Add to watch later')
33 this.addedToWatchLaterText = this.i18n('Remove from watch later')
37 if (!this.video) return ''
39 if (this.screenService.isInMobileView()) {
40 return this.video.previewUrl
43 return this.video.thumbnailUrl
46 getProgressPercent () {
47 if (!this.video.userHistory) return 0
49 const currentTime = this.video.userHistory.currentTime
51 return (currentTime / this.video.duration) * 100
54 getVideoRouterLink () {
55 if (this.videoRouterLink) return this.videoRouterLink
57 return [ '/videos/watch', this.video.uuid ]
60 onWatchLaterClick (event: Event) {
61 this.watchLaterClick.emit(this.inWatchLaterPlaylist)
63 event.stopPropagation()