import Vue from 'vue';
import dayjs from 'dayjs';
import { startsWith } from 'lodash-es';

Vue.filter('formatTime', function (date, pattern = 'YYYY-MM-DD') {
  if (!date) {
    return '-';
  }

  return dayjs(date).format(pattern);
});

function formatImg(url) {
  const prefix = process.env.VUE_APP_BASE_RESOURCE_PREFIX;
  if (!url) {
    return '-';
  }

  return startsWith(url, 'http') ? url : prefix + url;
}

Vue.filter('formatImg', formatImg);

Vue.prototype.formatImg = formatImg;
