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": "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 }
}

export { genCard }