function genCard(vcard){
  // 名片預覽
  let vcardLink
  if(vcard.url.trim().length>0){
    if(vcard.level===0){
      vcardLink =
      `{
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://demo.zltest.com.tw/line/icon02.png",
            "offsetTop": "3px"
          },
          {
            "type": "text",
            "text": "${vcard.url}",
            "color": "#333334",
            "size": "sm",
            "weight": "bold"
          }
        ],
        "spacing": "lg",
        "margin": "sm"
      },
      `
    }else{
      vcardLink =`
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://demo.zltest.com.tw/line/icon02.png",
            "offsetTop": "3px"
          },
          {
            "type": "text",
            "text": "${vcard.url}",
            "color": "#333334",
            "size": "sm",
            "weight": "bold",
            "action": {
              "type": "uri",
              "label": "action",
              "uri": "${vcard.url}"
            }
          }
        ],
        "spacing": "lg",
        "margin": "sm"
      },
      `
    }
  }else{
    vcardLink=''
  }

  let vcardAddr
  if(vcard.address.trim().length>0){
      vcardAddr =`
      ,
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://demo.zltest.com.tw/line/icon04.png",
            "offsetTop": "3px"
          },
          {
            "type": "text",
            "text": "${vcard.address}",
            "color": "#333334",
            "size": "sm",
            "weight": "bold",
            "action": {
              "type": "uri",
              "label": "action",
              "uri": "https://www.google.com.tw/maps/place/${encodeURIComponent(vcard.address)}"
            },
            "wrap": true
          }
        ],
        "spacing": "lg",
        "margin": "sm"
      }      
      `
  }else{
    vcardAddr=''
  }


  let vcardTel

  if(vcard.tel.trim().length>0){
    vcardTel=`
    {
      "type": "box",
      "layout": "baseline",
      "contents": [
        {
          "type": "icon",
          "url": "https://demo.zltest.com.tw/line/icon01.png",
          "offsetTop": "3px"
        },
        {
          "type": "text",
          "text": "${vcard.tel}",
          "color": "#333334",
          "size": "sm",
          "weight": "bold",
          "action": {
            "type": "uri",
            "label": "action",
            "uri": "tel:${vcard.tel}"
          }
        }
      ],
      "spacing": "lg",
      "margin": "sm"
    },
    `

  }else{
    vcardTel=''
  }

// 名片發送

    let card = `
    {
      "altText": "UTel電子名片",
      "type": "flex",
      "contents": 
      {
        "type": "bubble",
        "size": "giga",
        "body": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "image",
              "url": "https://demo.zltest.com.tw/line/bg02.jpg",
              "size": "full",
              "aspectMode": "cover",
              "aspectRatio": "4:3",
              "gravity": "top"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "image",
                  "url": "${vcard.avatar}",
                  "size": "xs"
                },
                {
                  "type": "text",
                  "text": "${vcard.company}",
                  "color": "#ffffff",
                  "size": "md",
                  "weight": "bold",
                  "wrap": true,
                  "align": "center",
                  "margin": "sm"
                }
              ],
              "position": "absolute",
              "offsetTop": "13%",
              "offsetStart": "3%",
              "width": "26%"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "加入好友",
                      "align": "center",
                      "color": "#ffffff",
                      "weight": "bold",
                      "margin": "xs"
                    }
                  ],
                  "backgroundColor": "#06c755",
                  "width": "100%",
                  "cornerRadius": "5px",
                  "action": {
                    "type": "uri",
                    "label": "action",
                    "uri": "https://line.naver.jp/ti/p/~${vcard.line}"
                  },
                  "paddingTop": "5px",
                  "paddingBottom": "5px"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "分享名片",
                      "align": "center",
                      "color": "#ffffff",
                      "weight": "bold",
                      "margin": "xs"
                    }
                  ],
                  "backgroundColor": "#ffcc5b",
                  "width": "100%",
                  "cornerRadius": "5px",
                  "margin": "md",
                  "paddingTop": "5px",
                  "paddingBottom": "5px",
                  "action": {
                    "type": "uri",
                    "label": "action",
                    "uri": "${process.env.VUE_APP_SEND_URL}/?userid=${vcard.user_id}&cardid=1"
                  }
                }
              ],
              "position": "absolute",
              "offsetStart": "4%",
              "width": "25%",
              "offsetBottom": "5%"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "box",
                  "layout": "baseline",
                  "contents": [
                    {
                      "type": "text",
                      "text": "${vcard.title}",
                      "color": "#333334",
                      "size": "md",
                      "weight": "bold"
                    }
                  ],
                  "spacing": "lg"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "${vcard.name}",
                      "size": "xxl",
                      "color": "#333334",
                      "weight": "bold"
                    }
                  ]
                },
                {
                  "type": "box",
                  "layout": "baseline",
                  "contents": [],
                  "backgroundColor": "#d5602d",
                  "height": "3px",
                  "margin": "lg"
                },
                {
                  "type": "box",
                  "layout": "baseline",
                  "contents": [
                    {
                      "type": "icon",
                      "url": "https://demo.zltest.com.tw/line/icon01.png",
                      "offsetTop": "3px"
                    },
                    {
                      "type": "text",
                      "text": "${vcard.phone}",
                      "color": "#333334",
                      "size": "sm",
                      "weight": "bold",
                      "action": {
                        "type": "uri",
                        "label": "action",
                        "uri": "tel:${vcard.phone}"
                      }
                    }
                  ],
                  "spacing": "lg",
                  "margin": "xxl"
                },
                ${vcardTel}
                ${vcardLink}
                {
                  "type": "box",
                  "layout": "baseline",
                  "contents": [
                    {
                      "type": "icon",
                      "url": "https://demo.zltest.com.tw/line/icon03.png",
                      "offsetTop": "3px"
                    },
                    {
                      "type": "text",
                      "text": "${vcard.email}",
                      "color": "#333334",
                      "size": "sm",
                      "weight": "bold",
                      "action": {
                        "type": "uri",
                        "label": "action",
                        "uri": "mailto:${vcard.email}"
                      }
                    }
                  ],
                  "spacing": "lg",
                  "margin": "sm"
                }
                ${vcardAddr}
              ],
              "position": "absolute",
              "offsetTop": "12%",
              "offsetStart": "35%",
              "offsetEnd": "5%"
            }
          ],
          "paddingAll": "0px"
        }
      }
    }
    `
    return { card }
}

function genJCICard(vcard){

  let card = 
  {
    altText: "UTel電子名片",
    type: "flex",
    contents: 
    {
    type: "bubble",
    size: "giga",
    body: {
      type: "box",
      layout: "vertical",
      contents: [
        {
          type: "image",
          url: "https://ecard.h888.fun/images/jcibg.png",
          size: "full",
          aspectMode: "fit",
          aspectRatio: "4:3",
          gravity: "top"
        },
        {
          type: "box",
          layout: "vertical",
          contents: [
            {
              type: "image",
              url: "https://demo.zltest.com.tw/line/qr.jpg",
              action: {
                type: "uri",
                label: "action",
                uri: "https://lin.ee/eXQEVnC"
              }
            }
          ],
          position: "absolute",
          offsetTop: "13%",
          offsetStart: "2%",
          width: "21%"
        },
        {
          type: "box",
          layout: "vertical",
          contents: [
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "text",
                  text: "加入好友",
                  align: "center",
                  color: "#ffffff",
                  weight: "bold",
                  margin: "xs"
                }
              ],
              backgroundColor: "#06c755",
              width: "100%",
              cornerRadius: "5px",
              action: {
                type: "uri",
                label: "action",
                uri: "https://line.naver.jp/ti/p/~"
              }
            },
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "text",
                  text: "分享名片",
                  align: "center",
                  color: "#ffffff",
                  weight: "bold",
                  margin: "xs"
                }
              ],
              backgroundColor: "#ffcc5b",
              width: "100%",
              cornerRadius: "5px",
              margin: "md"
            }
          ],
          position: "absolute",
          offsetStart: "2%",
          width: "20%",
          offsetBottom: "8%"
        },
        {
          type: "box",
          layout: "vertical",
          contents: [
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "text",
                  text: "Wayne 許家威",
                  size: "lg",
                  color: "#4EA2D9",
                  weight: "bold",
                  align: "end"
                }
              ]
            },
            {
              type: "box",
              layout: "baseline",
              contents: [
                {
                  type: "text",
                  text: "2004年會長",
                  color: "#333334",
                  size: "md",
                  weight: "bold",
                  align: "end"
                }
              ],
              spacing: "lg"
            },
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "separator"
                }
              ],
              height: "20px"
            },
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "text",
                  text: "大同國際青年商會",
                  color: "#4EA2D9",
                  size: "md",
                  weight: "bold",
                  align: "end"
                }
              ],
              spacing: "lg",
              margin: "xs"
            },
            {
              type: "box",
              layout: "vertical",
              contents: [
                {
                  type: "text",
                  text: "台北市復興北路179號",
                  weight: "bold",
                  color: "#333334",
                  size: "sm",
                  align: "end"
                }
              ],
              spacing: "lg",
              margin: "xs"
            },
            {
              type: "box",
              layout: "horizontal",
              contents: [
                {
                  type: "text",
                  text: "0225016501",
                  align: "end",
                  size: "sm",
                  color: "#333334",
                  weight: "bold"
                },
                {
                  type: "text",
                  text: "0983214434",
                  size: "sm",
                  align: "end",
                  weight: "bold"
                }
              ]
            },
            {
              type: "box",
              layout: "baseline",
              contents: [
                {
                  type: "text",
                  text: "http://www.coolgo.tw",
                  color: "#333334",
                  size: "sm",
                  action: {
                    type: "uri",
                    label: "action",
                    uri: "http://www.coolgo.tw"
                  },
                  weight: "bold",
                  align: "end"
                }
              ],
              spacing: "lg",
              margin: "xs"
            },
            {
              type: "box",
              layout: "baseline",
              contents: [
                {
                  type: "text",
                  text: "510@cityagogo.com.tw",
                  color: "#333334",
                  size: "sm",
                  weight: "bold",
                  action: {
                    type: "uri",
                    label: "action",
                    uri: "mailto:510@cityagogo.com.tw"
                  },
                  align: "end"
                }
              ],
              spacing: "lg",
              margin: "xs"
            }
          ],
          position: "absolute",
          offsetTop: "30%",
          offsetStart: "35%",
          offsetEnd: "5%"
        }
      ],
      paddingAll: "0px"
    }
  }
  }

  return { card: JSON.stringify(card)}
}

export { genCard , genJCICard }