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": "sm"
          }
        ]
      },
      `;
    } 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": "sm",
            "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": "sm",
            "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": "sm",
            "action": {
              "type": "uri",
              "label": "action",
              "uri": "tel:${vcard.tel}"
            }
          }
        ]
      },      
    `;
  } else {
    vcardTel = "";
  }

  let vcardPhone;

  if (vcard.phone.trim().length > 0) {
    vcardPhone = `
    {
      "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.phone}",
          "size": "sm",
          "color": "#6c6664",
          "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",
          "height": "290px",
          "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"
                }
              ],
              "position": "absolute",
              "width": "100%",
              "justifyContent": "flex-end",
              "height": "100%",
              "action": {
                "type": "uri",
                "label": "action",
                "uri": "${vcard.nfcurl}"
              }
            },
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        ${vcardAvatar}
                      ],
                      "width": "90px",
                      "cornerRadius": "xl"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "justifyContent": "space-between",
                      "width": "80%",
                      "contents": [
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "加入好友",
                            "uri": "https://line.naver.jp/ti/p/~${vcard.line}"
                          },
                          "color": "#755483",
                          "height": "sm",
                          "style": "primary",
                          "margin": "xs"
                        },
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "分享名片",
                            "uri": "${import.meta.env.VITE_APP_SEND_URL}/?userid=${vcard.user_id}&cardid=1&tpl=1"
                          },
                          "color": "#93476e",
                          "height": "sm",
                          "style": "primary",
                          "margin": "xs"
                        },
                        {
                          "type": "button",
                          "action": {
                            "type": "uri",
                            "label": "其他連結",
                            "uri": "http://linecorp.com/"
                          },
                          "color": "#c73f6d",
                          "height": "sm",
                          "style": "primary",
                          "margin": "xs"
                        }
                      ],
                      "margin": "xxl"
                    }
                  ],
                  "paddingTop": "5%",
                  "paddingBottom": "5%",
                  "justifyContent": "space-between",
                  "width": "35%",
                  "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",
                          "offsetBottom": "sm",
                        "offsetEnd": "md"
                        },
                        {
                          "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",
                          "position": "absolute",
                          "offsetTop": "xxl"
                        }
                      ],
                      "cornerRadius": "15px",
                      "alignItems": "flex-end",
                      "position": "relative"
                    },
                    {
                      "type": "box",
                      "layout": "vertical",
                      "contents": [
                        {
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "text",
                              "text": "${vcard.title}",
                              "size": "md",
                              "weight": "bold",
                              "color": "#888888"
                            }
                          ]
                        },
                        {
                          "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": [
                        ${vcardTel}     
                        ${vcardPhone}
                        ${vcardLink} 
                        ${vcardEmail}
                        ${vcardAddr}  
                        {
                          "position": "absolute",
                          "width": "1px",
                          "height": "1px",
                          "backgroundColor": "#333333",
                          "type": "box",
                          "layout": "vertical",
                          "contents": [
                            {
                              "type": "separator"
                            }
                          ]
                        }
                      ],
                      "margin": "xs",
                      "backgroundColor": "#ffffff95",
                      "paddingTop": "sm",
                      "paddingBottom": "lg"
                    }
                  ],
                  "height": "100%",
                  "position": "relative",
                  "width": "65%",
                  "paddingStart": "lg",
                  "paddingEnd": "md",
                  "paddingBottom": "lg"
                }
              ],
              "height": "100%",
              "alignItems": "flex-start"
            }
          ],
          "paddingAll": "0px",
          "justifyContent": "center",
          "alignItems": "center",
          "action": {
            "type": "uri",
            "label": "action",
            "uri": "${vcard.nfcurl}&cardid=2"
          }    
        }
      }
    }
    `;
  return { card };
}

export { genCard };
