import moment from 'moment';
import i18n from '@/vue/i18n';

export const flahsaleProductMax = 10;
export const flahsalePercentMin = {
  number: 0.05,
  text: '5%',
};

export const listStatus = [
  {
    label: i18n.t('FLASHSALE_STATUS_BY.SCHEDULER'),
    value: 'scheduler',
    count: 0,
  },
  {
    label: i18n.t('FLASHSALE_STATUS_BY.NEXT'),
    value: 'next',
    count: 0,
  },
  {
    label: i18n.t('FLASHSALE_STATUS_BY.CURRENT'),
    value: 'current',
    count: 0,
  },
  {
    label: i18n.t('FLASHSALE_STATUS_BY.END'),
    value: 'end',
    count: 0,
  },
  {
    label: i18n.t('FLASHSALE_STATUS_SAVED'),
    value: 'save',
    count: 0,
  },
];

export const listPriceOrignalType = [
  {
    value: 'priceOrginal',
    text: i18n.t('REDUCE_PRICE_BY_ORIGNAL'),
  },
  {
    value: 'priceDiscounted',
    text: i18n.t('REDUCE_PRICE_BY_DISCOUNTED'),
  },
  {
    value: 'priceCampaign',
    text: i18n.t('REDUCE_PRICE_BY_CAMPAIGN'),
  },
];

export const listPriceReduceBy = [
  {
    value: 'percent',
    label: '%',
    text: `${i18n.t('REDUCE_TYPE_PERCENT')} (%)`,
  },
  {
    value: 'price',
    label: '$',
    text: `${i18n.t('REDUCE_TYPE_AMOUNT')} ($)`,
  },
];

export const listSetMethod = [
  {
    value: 'default',
    disabled: false,
    text: i18n.t('FLASHSALE_SET_METHOD_DEFAULT'),
  },
  {
    value: 'scheduler',
    disabled: false,
    text: i18n.t('FLASHSALE_SET_METHOD_SCHEDULER'),
  },
];

export const listSearchProductType = [
  {
    value: 'name',
    text: i18n.t('PRODUCT_SEARCH_BY.PRODUCT_NAME'),
  },
  {
    value: 'id',
    text: i18n.t('PRODUCT_SEARCH_BY.PRODUCT_ID'),
  },
  {
    value: 'variation',
    text: i18n.t('PRODUCT_SEARCH_BY.VARIATION_NAME'),
  },
  {
    value: 'sku',
    text: i18n.t('PRODUCT_SEARCH_BY.PRODUCT_SKU'),
  },
  {
    value: 'msku',
    text: i18n.t('PRODUCT_SEARCH_BY.VARIATION_SKU'),
  },
];

export const tableProductColumn = [
  {
    title: '#',
    key: 'index',
    width: 60,
  },
  {
    title: i18n.t('PRODUCT_ID'),
    key: 'id',
    width: 150,
  },
  {
    title: i18n.t('PRODUCT_SKU'),
    key: 'sku',
    width: 150,
  },
  {
    title: i18n.t('PRODUCT_TIME_CREATE'),
    key: 'timeCreate',
    sortable: true,
    width: 120,
  },
  {
    title: i18n.t('PRODUCT_NAME'),
    slot: 'name',
    sortable: true,
    minWidth: 300,
  },
  {
    title: i18n.t('PRODUCT_MODEL'),
    key: 'modelCount',
    width: 100,
  },
  {
    title: i18n.t('PRODUCT_SOLD'),
    key: 'soldCount',
    sortable: true,
    width: 100,
  },
  {
    title: i18n.t('PRODUCT_STOCK'),
    key: 'stock',
    sortable: true,
    width: 100,
  },
  {
    title: i18n.t('PRODUCT_PRICE_ORIGINAL'),
    key: 'priceOrginal',
    sortable: true,
    width: 120,
  },
  {
    title: i18n.t('PRODUCT_PRICE_PROMOTION'),
    key: 'pricePromotion',
    sortable: true,
    width: 120,
  },
  {
    title: i18n.t('TABLE_COLUM_ACTION'),
    slot: 'action',
    width: 150,
  },
];

export const tablePromotionColumn = [
  {
    title: '#',
    key: 'index',
    width: 60,
  },
  {
    title: i18n.t('PRODUCT_NAME'),
    key: 'name',
    slot: 'name',
    sortable: true,
    minWidth: 250,
  },
  {
    title: i18n.t('PRODUCT_MODEL'),
    key: 'modelName',
    sortable: true,
    minWidth: 120,
  },
  {
    title: i18n.t('PRODUCT_STOCK'),
    key: 'stock',
    width: 100,
  },
  {
    title: i18n.t('PRODUCT_PRICE_ORIGINAL'),
    slot: 'priceOrginal',
    width: 110,
  },
  {
    title: i18n.t('PRODUCT_PRICE_PROMOTION'),
    slot: 'priceDiscounted',
    width: 110,
  },
  {
    title: i18n.t('PRODUCT_PERCENT_FLASHSALE'),
    slot: 'percentPromotion',
    width: 120,
  },
  {
    title: i18n.t('PRODUCT_PRICE_FLASHSALE'),
    slot: 'pricePromotion',
    width: 150,
  },
  {
    title: i18n.t('PRODUCT_PROMOTION_STOCK_LIMIT'),
    slot: 'stockLimit',
    width: 200,
  },
  {
    title: i18n.t('PRODUCT_PROMOTION_PURCHASE_LIMIT'),
    slot: 'purchaseLimit',
    width: 200,
  },
  {
    title: i18n.t('PRODUCT_PROMOTION_STATUS'),
    slot: 'status',
    width: 150,
  },
];

export const excelResultColumn = {
  [i18n.t('FLASHSALE_ID')]: 'id',
  [i18n.t('FLASHSALE_STATUS')]: 'status',
  [i18n.t('FLASHSALE_TIME')]: 'time',
  [i18n.t('PRODUCT_NAME')]: 'product',
  [i18n.t('PRODUCT_MODEL')]: 'modelName',
  [i18n.t('PRODUCT_STOCK')]: 'stock',
  [i18n.t('PRODUCT_PROMOTION_CHANGE')]: 'percentPromotion',
  [i18n.t('PRODUCT_PRICE_ORIGINAL')]: 'priceOrginal',
  [i18n.t('PRODUCT_PRICE_PROMOTION')]: 'pricePromotion',
  [i18n.t('PRODUCT_PROMOTION_STOCK_LIMIT')]: 'stockLimit',
  [i18n.t('PRODUCT_PROMOTION_PURCHASE_LIMIT')]: 'purchaseLimit',
  [i18n.t('FLASHSALE_LINK')]: 'url',
  [i18n.t('FLASHSALE_LOG')]: 'log',
};

export const configPromotion = {
  priceMin: 1000,
  percentMax: 0.1,
  percentMin: 0.8,
  stockDuration: 1,
  limitProduct: 10,
  defaultPromotion: {
    pricePromotion: 0,
    purchaseLimit: 0,
    stockLimit: 0,
    status: true,
  },
  stockSplitDefault: 3,
  getPriceMinPromotion(price) {
    return price * flahsalePercentMin.number;
  },
  getPriceMaxPromotion(price) {
    return price * 1;
  },
};

export const mapStatusLabel = {
  0: i18n.t('FLASHSALE_STATUS_BY.UNKNOW'),
  1: i18n.t('FLASHSALE_STATUS_BY.NEXT'),
  2: i18n.t('FLASHSALE_STATUS_BY.CURRENT'),
  3: i18n.t('FLASHSALE_STATUS_BY.END'),
};

/**
 *
 * @param {number} num
 * @returns  {number}
 */

export const roundNumber = (num) => Math.floor(num, 0);

/**
 *
 * @param {number} num
 * @returns {Date}
 */
export const unixTime = (num) => new Date(num * 1000);

/**
 *
 * @param {Date} start
 * @param {Date} end
 * @returns {string}
 */
export const labelTime = (start, end) => [moment(start).format('DD/MM/YYYY'), moment(start).format('HH:mm:ss'), moment(end).format('HH:mm:ss')].join(' - ');
