<commit_before><template lang="pug">
  v-card.pa-2
    v-layout(row, wrap, column)
      v-tooltip(top, lazy, v-show='torrentName')
        .torrent-title.ellipsis.pt-1.pb-2(slot='activator') {{ torrentName }}
        span {{ torrentName }}

      v-divider

      v-flex(pl-4, pr-2, pb-0, d-flex, justify-space-between, align-center)
        v-progress-linear(v-model='progress', height='12', color='green')
        .progress-text {{ progress }}%

      v-flex(pt-0, pr-2, pb-2, d-flex, justify-end)
        .progress-text.time-remaining.grey--text.text-uppercase.text-xs-right {{ timeRemaining }}

      v-divider

      v-layout(justify-space-around, pl-4, pr-4)
        template(v-for='action in actions')
          v-btn(v-if='!action.displayInfo', icon, @click='action.action', large)
            v-icon(:color='action.color', large) {{ action.icon }}

        torrent-info(:torrent='torrent')
</template>

<script>
import moment from 'moment'

import TorrentInfo from '@/components/torrents/torrentInfo.vue'

export default {
  name: 'Torrent-Card',

  components: { TorrentInfo },

  props: ['torrent'],

  data: () => ({
    isPaused: false,
    creationDate: moment(),
    timeRemaining: ''
  }),

  computed: {
    torrentName () {
      return this.torrent.files && this.torrent.files.length
        ? this.torrent.files[0].name
        : undefined
    },
    progress () {
      return this.torrent
        ? (this.torrent.progress * 100).toFixed(2)
        : 0
    },
    actions () {
      return [{
        icon: this.isPaused ? 'play_arrow' : 'stop',
        color: '',
        action: () => this.actOnTorrent(this.isPaused ? 'resume' : 'pause')
      }, {
        icon: 'delete',
        color: 'red',
        action: this.stop
      }]
    }
  },

  methods: {
    stop () {
      this.actOnTorrent('pause')
      this.actOnTorrent('destroy')
    },
    setRemainingTime (torrent) {
      if (torrent.progress === 1) {
        this.timeRemaining = 'Done'
        return
      }

      this.timeRemaining = torrent.timeRemaining
        ? 'Ends ' + this.creationDate
          .clone()
          .add(torrent.timeRemaining)
          .fromNow()
        : 'Unknown time remaining...'
    },
    actOnTorrent (action) {
      this.$ipc.send(this.$eventsList.torrent.act.main, {
        magnet: this.torrent.magnetURI,
        action
      })

      if (action === 'pause') this.isPaused = true
      else if (action === 'resume') this.isPaused = false
    }
  },<commit_msg>Fixed remaining time for torrents<commit_after><template lang="pug">
  v-card.pa-2
    v-layout(row, wrap, column)
      v-tooltip(top, lazy, v-show='torrentName')
        .torrent-title.ellipsis.pt-1.pb-2(slot='activator') {{ torrentName }}
        span {{ torrentName }}

      v-divider

      v-flex(pl-4, pr-2, pb-0, d-flex, justify-space-between, align-center)
        v-progress-linear(v-model='progress', height='12', color='green')
        .progress-text {{ progress }}%

      v-flex(pt-0, pr-2, pb-2, d-flex, justify-end)
        .progress-text.time-remaining.grey--text.text-uppercase.text-xs-right {{ timeRemaining }}

      v-divider

      v-layout(justify-space-around, pl-4, pr-4)
        template(v-for='action in actions')
          v-btn(v-if='!action.displayInfo', icon, @click='action.action', large)
            v-icon(:color='action.color', large) {{ action.icon }}

        torrent-info(:torrent='torrent')
</template>

<script>
import moment from 'moment'

import TorrentInfo from '@/components/torrents/torrentInfo.vue'

export default {
  name: 'Torrent-Card',

  components: { TorrentInfo },

  props: ['torrent'],

  data: () => ({
    isPaused: false,
    timeRemaining: ''
  }),

  computed: {
    torrentName () {
      return this.torrent.files && this.torrent.files.length
        ? this.torrent.files[0].name
        : undefined
    },
    progress () {
      return this.torrent
        ? (this.torrent.progress * 100).toFixed(2)
        : 0
    },
    actions () {
      return [{
        icon: this.isPaused ? 'play_arrow' : 'stop',
        color: '',
        action: () => this.actOnTorrent(this.isPaused ? 'resume' : 'pause')
      }, {
        icon: 'delete',
        color: 'red',
        action: this.stop
      }]
    }
  },

  methods: {
    stop () {
      this.actOnTorrent('pause')
      this.actOnTorrent('destroy')
    },
    setRemainingTime (torrent) {
      if (torrent.progress === 1) {
        this.timeRemaining = 'Done'
        return
      }

      const endsIn = parseInt(Date.now() + torrent.timeRemaining)

      this.timeRemaining = torrent.timeRemaining
        ? 'Ends ' + moment(endsIn).fromNow()
        : 'Unknown time remaining...'
    },
    actOnTorrent (action) {
      this.$ipc.send(this.$eventsList.torrent.act.main, {
        magnet: this.torrent.magnetURI,
        action
      })

      if (action === 'pause') this.isPaused = true
      else if (action === 'resume') this.isPaused = false
    }
  },
{'fraction_non_alphanumeric': 0.16143317230273752, 'fraction_numerical': 0.008051529790660225, 'mean_word_length': 2.271231073074391, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4999973', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1649, 'n_words': 283}