const template = html`
  <span>
    <h4>
      Orders: <span class="badge badge-info ng-binding">{{data.length}}</span>
    </h4>
    <jsontable
      :header="['ID','Ordered By','Client','Status','Created']"
      :data="data"
    ></jsontable>
  </span>
`;
import jsontable from "../../generic/jsontable.js";

export default {
  data: function() {
    return {
      data: []
    };
  },
  components: {
    jsontable
  },
  mounted() {
    this.load();
  },
  methods: {
    async load() {
      const raw = await fetch("/api/v1/tasks/orders?client=true&status_id=16");
      const json = await raw.json();
      this.data = json.data.map(el => {
        return [
          el.id,
          el.creator.name,
          el.client.name,
          el.status.name,
          moment(el.created_at).fromNow()
        ];
      });
    }
  },
  template
};
