// ลิงค์ liff id
// const btn = document.getElementById('btn');
const liffId = '1656372900-VM6wDmam';
let userId = '';

function main(){
    liff.init({liffId: liffId});
    // login
    liff.ready.then(() => {
        if(!liff.isLoggedIn()){
            liff.login();
        }
        // profile
        liff.getProfile().then(profile => {
            console.log(profile);
            // console.log(profile.userId);
            // console.log(profile.displayName);
            // console.log(profile.pictureUrl);
            // document.getElementById("userId").var(profile.userId);
            document.getElementById("pictureUrl").src = profile.pictureUrl;
            document.getElementById("userId").value = profile.userId;
            document.getElementById("displayName").value = profile.displayName;
            document.getElementById("statusMessage").value =  profile.statusMessage;

            // สร้างตัวแปร
            var userId = profile.userId;
            console.log(userId);

            // ส่งข้อมูล ผ่าน ajax
            $.ajax({
            url: '_index_linejson.php?lineid='+profile.userId,
            type: 'GET',
            // data: { 
            //     "lineid": $("#userId").val()
            // },
            // data: {'brids' : $("#brbr").attr("value")}
            dataType: 'JSON',
            // แสดงข้อมูล
            success: function(response){
                var len = response.length;
                for(var i=0; i<len; i++){
                var ct_no = response[i].ct_no;
                var ps_name = response[i].ps_name;
                var ct_mobileno = response[i].ct_mobileno;
                var lineid = response[i].lineid;

                var tr_str = "<tr>" +
                    "<td align=''>" + (i+1) + ".</td>" +
                    "<td align=''>" + ct_no + "</td>" +
                    "<td align=''>" + ps_name + "</td>" +
                    "<td align='center'> <a href='_index_selectline.php?lineid="+ lineid +"&ct_no="+ ct_no +"' style='text-decoration: none; color:black;'>" + "<i class='fa fa-search-plus'></i>" + "</a></td>" +
                    "</tr>";
                $("#table_1 tbody").append(tr_str);
                }
            } 
        });  
        })
    });
}
main()
