function genCard(vcard) {
  // 名片預覽
  let vcardLink;
  if (vcard.url.trim().length > 0) {
    if (vcard.nc_func.indexOf("nourl") !== -1) {
      vcardLink = `
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://369cycle.zltest.com.tw/tggo/template/icon/link.png",
            "size": "sm",
            "offsetTop": "xs",
            "offsetEnd": "md"
          },
          {
            "type": "text",
            "text": "${vcard.url}",
            "color": "#6c6664",
            "size": "md"
          }
        ],
        "margin": "md",
        "paddingStart": "lg"
      },
      `;
    } else {
      vcardLink = `
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://369cycle.zltest.com.tw/tggo/template/icon/link.png",
            "size": "sm",
            "offsetTop": "xs",
            "offsetEnd": "md"
          },
          {
            "type": "text",
            "text": "${vcard.url}",
            "color": "#6c6664",
            "size": "md",
            "action": {
              "type": "uri",
              "label": "yahoo",
              "uri": "${vcard.url}"
            }
          }
        ],
        "margin": "md",
        "paddingStart": "lg"
      },
      `;
    }
  } else {
    vcardLink = "";
  }

  let vcardAddr;
  if (vcard.address.trim().length > 0) {
    vcardAddr = `
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://369cycle.zltest.com.tw/tggo/template/icon/map.png",
            "size": "sm",
            "offsetTop": "xs",
            "offsetEnd": "md"
          },
          {
            "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
          }
        ],
        "margin": "md",
        "paddingStart": "lg"
      }
      `;
  } else {
    vcardAddr = "";
  }

  let vcardTel;

  if (vcard.tel.trim().length > 0) {
    vcardTel = `
      {
        "type": "box",
        "layout": "baseline",
        "contents": [
          {
            "type": "icon",
            "url": "https://369cycle.zltest.com.tw/tggo/template/icon/phone.png",
            "size": "sm",
            "offsetTop": "xs",
            "offsetEnd": "md"
          },
          {
            "type": "text",
            "text": "${vcard.tel}",
            "color": "#6c6664",
            "size": "md",
            "action": {
              "type": "uri",
              "label": "action",
              "uri": "tel:${vcard.tel}"
            }
          }
        ],
        "margin": "md",
        "paddingStart": "lg"
      },      
    `;
  } else {
    vcardTel = "";
  }

  let vcardPhone;

  if (vcard.phone.trim().length > 0) {
    vcardPhone = `
    {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "${vcard.phone}",
          "size": "xxl",
          "color": "#93476e",
          "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": "box",
      "layout": "baseline",
      "contents": [
        {
          "type": "icon",
          "url": "https://369cycle.zltest.com.tw/tggo/template/icon/mail.png",
          "size": "sm",
          "offsetTop": "xs",
          "offsetEnd": "md"
        },
        {
          "type": "text",
          "text": "${vcard.email}",
          "color": "#6c6664",
          "size": "md",
          "action": {
            "type": "uri",
            "label": "action",
            "uri": "mailto:${vcard.email}"
          }
        }
      ],
      "margin": "md",
      "paddingStart": "lg"
    },
    `;
  } else {
    vcardEmail = "";
  }

  // 名片發送

  let card = `
    {
      "altText": "UTel電子名片",
      "type": "flex",
      "contents": 
      {
        "type": "bubble",
        "size": "giga",
        "body": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [],
                  "height": "45%"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "image",
                      "size": "full",
                      "position": "relative",
                      "url": "https://369cycle.zltest.com.tw/tggo/template/bg-03h.png"
                    }
                  ],
                  "height": "55%"
                }
              ],
              "height": "100%",
              "position": "absolute",
              "width": "100%"
            },
            {
              "type": "box",
              "layout": "vertical",
              "contents": [
                {
                  "type": "text",
                  "text": "Company",
                  "size": "3xl",
                  "weight": "bold",
                  "offsetBottom": "md",
                  "color": "#c6b0c9"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "${vcard.company}",
                      "color": "#ffffff",
                      "size": "md"
                    }
                  ],
                  "backgroundColor": "#6c6d8b",
                  "paddingTop": "sm",
                  "paddingBottom": "sm",
                  "paddingStart": "lg",
                  "cornerRadius": "xxl",
                  "paddingEnd": "lg",
                  "offsetBottom": "xl"
                }
              ],
              "cornerRadius": "15px",
              "paddingStart": "10px",
              "paddingEnd": "10px",
              "alignItems": "flex-end",
              "offsetEnd": "none",
              "position": "absolute",
              "offsetTop": "none"
            },
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [${vcardAvatar}],
                      "cornerRadius": "10px",
                      "margin": "none",
                      "width": "100%"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "justifyContent": "space-between",
                      "contents": [
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "加入好友",
                            "uri": "http://linecorp.com/"
                          },
                          "color": "#755483",
                          "height": "sm",
                          "style": "primary",
                          "margin": "md"
                        },
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "分享名片",
                            "uri": "http://linecorp.com/"
                          },
                          "color": "#93476e",
                          "height": "sm",
                          "style": "primary",
                          "margin": "md"
                        },
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "其他連結",
                            "uri": "http://linecorp.com/"
                          },
                          "color": "#c73f6d",
                          "height": "sm",
                          "style": "primary",
                          "margin": "md"
                        }
                      ],
                      "margin": "xxl"
                    }
                  ],
                  "paddingTop": "5%",
                  "paddingBottom": "8%",
                  "justifyContent": "flex-start",
                  "width": "30%",
                  "alignItems": "center",
                  "height": "95%"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "horizontal",
                      "contents": [
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.name}",
                              "size": "xxl",
                              "weight": "bold"
                            }
                          ]
                        },
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.title}",
                              "size": "md",
                              "weight": "bold",
                              "color": "#888888",
                              "action": {
                                "type": "uri",
                                "label": "action",
                                "uri": "${vcard.nfcurl}&cardid=1"
                              }
                            }
                          ]
                        }
                      ],
                      "alignItems": "center"
                    },
                    {
                      "type": "separator",
                      "color": "#93476e",
                      "margin": "sm"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        ${vcardPhone}
                        ${vcardTel}     
                        ${vcardLink} 
                        ${vcardEmail}   
                        ${vcardAddr}
                      ],
                      "margin": "xs"
                    }
                  ],
                  "height": "84%",
                  "paddingStart": "xxl"
                }
              ],
              "paddingAll": "xl",
              "height": "100%",
              "alignItems": "flex-end"
            }
          ],
          "paddingAll": "0px",
          "action": {
            "type": "uri",
            "label": "action",
            "uri": "https://utel.zltest.com.tw/card/?params=i7Kq7O59hPX1MJ%2Bqd8zQKBwuyc%2F%2BZ%2BZs%2BZXtXBy4zvg%3D&cardid=1"
          },
          "justifyContent": "center",
          "alignItems": "center",
          "height": "420px"
        }
      }
    }
    `;
  return { card };
}

export { genCard };
