function genCard(vcard) {
  // 名片預覽
  let vcardLink;
  if (vcard.url.trim().length > 0) {
    if (vcard.nc_func.indexOf("nourl") !== -1) {
      vcardLink = `
      {
        "type": "box",
        "layout": "baseline",
        "margin": "md",
        "paddingStart": "lg",
        "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"
          }
        ]
      },
      `;
    } else {
      vcardLink = `
      {
        "type": "box",
        "layout": "baseline",
        "margin": "md",
        "paddingStart": "lg",
        "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}"
            }
          }
        ]
      },
      `;
    }
  } else {
    vcardLink = "";
  }

  let vcardAddr;
  if (vcard.address.trim().length > 0) {
    vcardAddr = `
      {
        "type": "box",
        "layout": "baseline",
        "margin": "md",
        "paddingStart": "lg",
        "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",
            "wrap": true,
            "action": {
              "type": "uri",
              "label": "action",
              "uri": "https://www.google.com.tw/maps/place/${encodeURIComponent(
                vcard.address
              )}"
            }
          }
        ]
      }
      `;
  } else {
    vcardAddr = "";
  }

  let vcardTel;

  if (vcard.tel.trim().length > 0) {
    vcardTel = `
      {
        "type": "box",
        "layout": "baseline",
        "margin": "md",
        "paddingStart": "lg",
        "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}"
            }
          }
        ]
      },      
    `;
  } 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",
      "align": "center",
      "gravity": "center",
      "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",
      "margin": "md",
      "paddingStart": "lg",
      "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}"
          }
        }
      ]
    },
    `;
  } 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": "image",
                  "size": "full",
                  "position": "relative",
                  "url": "https://369cycle.zltest.com.tw/tggo/template/bg-03h.png",
                  "aspectRatio": "4:1",
                  "aspectMode": "cover"
                }
              ],
              "height": "100%",
              "position": "absolute",
              "width": "100%",
              "justifyContent": "flex-end"
            },
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        ${vcardAvatar}
                      ],
                      "width": "90%",
                      "cornerRadius": "xxl"
                    },
                    {
                      "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": "8%",
                  "paddingBottom": "8%",
                  "justifyContent": "flex-start",
                  "width": "30%",
                  "alignItems": "center",
                  "height": "100%",
                  "position": "relative"
                },
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        {
                          "type": "text",
                          "text": "Company",
                          "size": "3xl",
                          "weight": "bold",
                          "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": "md"
                        }
                      ],
                      "cornerRadius": "15px",
                      "alignItems": "flex-end",
                      "position": "relative"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "前端布魯",
                              "size": "md",
                              "weight": "bold",
                              "color": "#888888",
                              "action": {
                                "type": "uri",
                                "label": "action",
                                "uri": "https://utel.zltest.com.tw/card/?params=TE%2BoyUn0Yl7Vj76pKdp9VaL0LtXOVTpMx5BbbOvd1yM%3D&cardid=1"
                              }
                            }
                          ]
                        },
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.name}",
                              "size": "xxl",
                              "weight": "bold"
                            }
                          ]
                        }
                      ],
                      "alignItems": "flex-start",
                      "justifyContent": "space-between"
                    },
                    {
                      "type": "separator",
                      "color": "#93476e",
                      "margin": "sm"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        ${vcardPhone}
                        ${vcardTel}     
                        ${vcardLink} 
                        ${vcardEmail}
                        ${vcardAddr}  
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "separator"
                            }
                          ]
                        }
                      ],
                      "margin": "xs",
                      "backgroundColor": "#ffffff95",
                      "paddingTop": "sm",
                      "paddingBottom": "lg"
                    }
                  ],
                  "height": "100%",
                  "position": "relative",
                  "width": "70%",
                  "paddingStart": "lg",
                  "paddingEnd": "md",
                  "paddingBottom": "lg"
                }
              ],
              "height": "100%",
              "alignItems": "flex-start"
            }
          ],
          "paddingAll": "0px",
          "justifyContent": "center",
          "alignItems": "center"
        }
      }
    }
    `;
  return { card };
}

export { genCard };
