function genCard(vcard) {
  // 名片預覽
  let vcardLink;
  if (vcard.url.trim().length > 0) {
    if (vcard.nc_func.indexOf("nourl") !== -1) {
      vcardLink = `{
        "type": "text",
        "text": "${vcard.url}",
        "color": "#6c6664",
        "size": "md"
      },
      `;
    } else {
      vcardLink = `
      {
        "type": "text",
        "text": "${vcard.url}",
        "color": "#6c6664",
        "size": "md",
        "action": {
          "type": "uri",
          "label": "yahoo",
          "uri": "${vcard.url}"
        }
      },
      `;
    }
  } else {
    vcardLink = "";
  }

  let vcardAddr;
  if (vcard.address.trim().length > 0) {
    vcardAddr = `
      {
        "type": "text",
        "text": "${vcard.address}",
        "color": "#6c6664",
        "size": "md",
        "action": {
          "type": "uri",
          "label": "action",
          "uri": "https://www.google.com.tw/maps/place/${encodeURIComponent(
            vcard.address
          )}"
        },
        "wrap": true,
        "align": "end"
      } 
      `;
  } else {
    vcardAddr = "";
  }

  let vcardTel;

  if (vcard.tel.trim().length > 0) {
    vcardTel = `
      {
        "type": "text",
        "text": "${vcard.tel}",
        "color": "#6c6664",
        "size": "md",
        "action": {
          "type": "uri",
          "label": "action",
          "uri": "tel:${vcard.tel}"
        }
      },
    `;
  } else {
    vcardTel = "";
  }

  let vcardPhone;

  if (vcard.phone.trim().length > 0) {
    vcardPhone = `
    {
      "type": "text",
      "text": "${vcard.phone}",
      "size": "lg",
      "color": "#ffffff",
      "action": {
        "type": "uri",
        "label": "action",
        "uri": "tel:${vcard.phone}"
      }
    }
    `;
  } else {
    vcardPhone = "";
  }

  let vcardAvatar;

  if (vcard.avatar.trim().length > 0) {
    vcardAvatar = `
    {
      "type": "image",
      "url": "${vcard.avatar}",
      "size": "full",
      "aspectRatio": "1:1",
      "aspectMode": "cover",
      "action": {
        "type": "uri",
        "label": "action",
        "uri": "${vcard.nfcurl}&cardid=1"
      }    
    }
    `;
  } else {
    vcardAvatar = "";
  }

  let vcardEmail;

  if (vcard.email.trim().length > 0) {
    vcardEmail = `
    {
      "type": "text",
      "text": "${vcard.email}",
      "color": "#6c6664",
      "size": "md",
      "action": {
        "type": "uri",
        "label": "action",
        "uri": "mailto:${vcard.email}"
      }
    },
    `;
  } else {
    vcardEmail = "";
  }

  // 名片發送

  let card = `
    {
      "altText": "UTel電子名片",
      "type": "flex",
      "contents": 
      {
        "type": "bubble",
        "size": "giga",
        "body": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "image",
              "url": "https://369cycle.zltest.com.tw/tggo/template/bg-02.png",
              "size": "full",
              "position": "absolute",
              "aspectMode": "cover"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "box",
                  "layout": "horizontal",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.name}",
                              "size": "xl",
                              "weight": "bold",
                              "color": "#ffffff",
                              "margin": "sm"
                            }
                          ],
                          "backgroundColor": "#bf4c32",
                          "paddingStart": "10px",
                          "paddingEnd": "5px"
                        },
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.title}",
                              "size": "md",
                              "weight": "regular",
                              "color": "#ffffff",
                              "action": {
                                "type": "uri",
                                "label": "action",
                                "uri": "${vcard.nfcurl}&cardid=1"
                              } 
                            }
                          ],
                          "backgroundColor": "#e5b164",
                          "paddingStart": "xxl",
                          "paddingEnd": "5px",
                          "offsetEnd": "5px",
                          "margin": "sm",
                          "paddingBottom": "xs",
                          "paddingTop": "2px"
                        },
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [${vcardPhone}],
                          "backgroundColor": "#7aa567",
                          "margin": "xs",
                          "paddingStart": "5px",
                          "paddingEnd": "5px"
                        }
                      ],
                      "alignItems": "flex-end",
                      "width": "50%",
                      "paddingEnd": "xl"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [${vcardAvatar}],
                      "cornerRadius": "150px",
                      "borderWidth": "bold",
                      "borderColor": "#ffffff",
                      "margin": "none",
                      "width": "30%"
                    }
                  ],
                  "alignItems": "center",
                  "paddingTop": "3%",
                  "justifyContent": "center"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "horizontal",
                      "contents": [
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            ${vcardTel}
                            ${vcardLink}
                            ${vcardEmail}
                            ${vcardAddr}                             
                          ],
                          "alignItems": "flex-end",
                          "paddingEnd": "xl"
                        },
                        {
                          "type": "box",
                          "layout": "vertical",
                          "justifyContent": "space-between",
                          "contents": [
                            {
                              "type": "button",
                              "action": {
                                "type": "uri",
                                "label": "加入好友",
                                "uri": "http://linecorp.com/"
                              },
                              "color": "#6c6664",
                              "height": "sm",
                              "style": "primary"
                            },
                            {
                              "type": "button",
                              "action": {
                                "type": "uri",
                                "label": "分享名片",
                                "uri": "http://linecorp.com/"
                              },
                              "color": "#6c6664",
                              "height": "sm",
                              "margin": "sm",
                              "style": "primary"
                            }
                          ],
                          "width": "30%"
                        }
                      ],
                      "alignItems": "flex-end"
                    }
                  ],
                  "justifyContent": "space-between"
                }
              ],
              "width": "95%",
              "height": "92%",
              "borderWidth": "light",
              "borderColor": "#bbbbbb",
              "paddingAll": "10px",
              "justifyContent": "space-between",
              "cornerRadius": "lg"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "text",
                  "text": "匯康科技",
                  "color": "#e5b164",
                  "size": "md"
                }
              ],
              "position": "absolute",
              "offsetTop": "sm",
              "offsetStart": "sm",
              "backgroundColor": "#ffffff",
              "cornerRadius": "15px",
              "paddingStart": "10px",
              "paddingEnd": "10px"
            }
          ],
          "paddingAll": "0px",
          "action": {
            "type": "uri",
            "label": "action",
            "uri": "https://utel.zltest.com.tw/card/?params=i7Kq7O59hPX1MJ%2Bqd8zQKBwuyc%2F%2BZ%2BZs%2BZXtXBy4zvg%3D&cardid=1"
          },
          "height": "280px",
          "justifyContent": "center",
          "alignItems": "center"
        }
      }
    }
    `;
  return { card };
}

export { genCard };
