import _ from 'lodash';

export const convertToAppEvent = (event) => {
  const eventInputActivities = _.filter(event.eventActivities || [], activity => activity.type === 'input');
  const eventWatchActivities = _.filter(event.eventActivities || [], activity => activity.type === 'watch');
  return {
    tag: _.head(event.tags),
    product: event.product || {},
    productPrice: _.get(event, 'product.Po_Price', 0),
    productImage: 'images/product-2.png', // _.get(event, 'product.Po_Img', 0),
    howTo: _.map(event.howTo, (instruction) => {
      const th = instruction.th || '';
      const isMSISDN = /เบอร์มือถือ/i.test(th);
      const isEmail = /อีเมล/i.test(th);
      const isLineId = /line/i.test(th);
      const isBarCode = /barcode/i.test(th);
      const isQrCode = /qr/i.test(th);
      if (isMSISDN) return (<span>{th}<img className="icon middle-line" src="images/icon-phone.png" height="30" /></span>);
      if (isEmail) return (<span>{th}<img className="icon middle-line" src="images/icon-email.png" height="30" /></span>);
      if (isLineId) return (<span>{th}<img className="icon middle-line" src="images/icon-linelogo.png" height="30" /></span>);
      if (isBarCode) return (<span>{th}<img className="icon middle-line" src="images/icon-barcode.png" height="30" /></span>);
      if (isQrCode) return (<span>{th}<img className="icon middle-line" src="images/icon-qrcode.png" height="30" /></span>);
      return th;
    }),
    inputs: _.map(eventInputActivities || [], (eventInputActivity) => {
      return {
        ...eventInputActivity,
        completed: false
      };
    }),
    watches: _.map(eventWatchActivities, (eventWatchActivity) => {
      return {
        ...eventWatchActivity,
        completed: false
      };
    }),
    rewards: _.map(event.rewards || [], (reward) => {
      return {
        ...reward,
        completed: false
      };
    }),
    remarks: _.map(event.remarks || [], (remark) => {
      return {
        ...remark,
        completed: false
      };
    }),
  };
};

@@ -16,16 +16,712 @@
 lodash';
+%0Aimport cuid from 'cuid';%0A%0Aconst isSoldout = () =%3E _.random(1, 5) === 5;%0A%0A/*%0Aproduct: %7B%0A  Po_ID: 'PO0001',%0A  Po_Name: %7B%0A    th: '%E0%B9%81%E0%B8%9A%E0%B8%A3%E0%B8%99%E0%B8%94%E0%B9%8C Gen U',%0A    en: '%E0%B9%81%E0%B8%9A%E0%B8%A3%E0%B8%99%E0%B8%94%E0%B9%8C Gen U',%0A  %7D,%0A  Po_Price: '45',%0A  Po_Img: 'images/product-20170819110019.png',%0A  Po_Imgbig: 'images/product-bg-20170819110019.png',%0A  Row: '1',%0A  Column: '1',%0A%7D,%0A*/%0Aexport const convertToAppProduct = (product) =%3E %7B%0A  return %7B%0A    cuid: cuid(),%0A    id: product.Po_ID %7C%7C '',%0A    name: product.Po_Name %7C%7C '',%0A    price: product.Po_Price %7C%7C '',%0A    isSoldout: isSoldout() %7C%7C true,%0A    image: product.Po_Img %7C%7C '',%0A    imageBig: product.Po_Imgbig %7C%7C '',%0A    row: product.Row %7C%7C '',%0A    col: product.Column %7C%7C '',%0A    isDropped: false,%0A  %7D;%0A%7D;
 %0A%0Aexport
@@ -1035,161 +1035,47 @@
 ct: 
-event.product %7C%7C %7B%7D,%0A    productPrice: _.get(event, 'product.Po_Price', 0),%0A    productImage: 'images/product-2.png', // _.ge
+convertToAppProduc
 t(event
-, '
+.
 product
-.Po_Img', 0
+ %7C%7C %7B%7D
 ),%0A 
@@ -1123,24 +1123,27 @@
 ) =%3E %7B%0A     
+ //
  const th = 
@@ -1165,24 +1165,27 @@
 %7C%7C '';%0A     
+ //
  const isMSI
@@ -1212,32 +1212,35 @@
 .test(th);%0A     
+ //
  const isEmail =
@@ -1256,32 +1256,35 @@
 .test(th);%0A     
+ //
  const isLineId 
@@ -1300,32 +1300,35 @@
 .test(th);%0A     
+ //
  const isBarCode
@@ -1356,16 +1356,19 @@
 );%0A     
+ //
  const i
@@ -1394,24 +1394,27 @@
 t(th);%0A     
+ //
  if (isMSISD
@@ -1521,24 +1521,27 @@
 pan%3E);%0A     
+ //
  if (isEmail
@@ -1647,24 +1647,27 @@
 pan%3E);%0A     
+ //
  if (isLineI
@@ -1777,24 +1777,27 @@
 pan%3E);%0A     
+ //
  if (isBarCo
@@ -1911,16 +1911,19 @@
 );%0A     
+ //
  if (isQ
@@ -2047,18 +2047,27 @@
  return 
-th
+instruction
 ;%0A    %7D)

Update function convertToAppEvent & convertToAppProduct format