const template = html`
  <span>
    <h4>
      Subscribed:
      <span class="badge badge-info ng-binding">{{data.length}}</span>
      <jsontable :header="header" :data="data"></jsontable>
    </h4>
  </span>
`;
import jsontable from "../../generic/jsontable.js";

export default {
  data: function() {
    return {
      data: [],
      header: ["ID", "Title", "Client", "", "Assigned To", "Status", "Created"]
    };
  },
  components: {
    jsontable
  },
  mounted() {
    this.load();
  },
  methods: {
    async load() {
      const raw = await fetch(
        "/api/v1/task?client=true&creator=true&limit=100&results=subscribed&user=true&user_id=1"
      );
      const json = await raw.json();
      this.data = json.data.map(el => {
        return [
          el.id,
          el.title,
          el.client.name,
          "",
          el.status.name,
          moment(el.created_at).fromNow()
        ];
      });
    }
  },
  template
};
