<?php

echo "<ul data-role='listview' data-inset='false'>";
$this->renderMobilePhoneSwitcher($phonesCurrentDataProvider);
echo"</ul>";

echo "<ul data-role='listview' data-inset='false'>";
$this->renderMobileQueueSwitcher($queueDataProvider);
echo"</ul>";

echo "<ul data-role='listview' data-inset='false'>";
if (count(app()->user->realUserInstance->getForwardingSets()) !== 0) {
    echo "<li>";
    $this->renderMobileCallForwardList();
    echo "</li>";
}
echo"</ul>";

echo "<ul data-role='listview' data-inset='false'>";
echo "<li>";
$this->renderLanguageSelect();
echo "</li>";
echo"</ul>";
?>

<script>
    $('div[data-role="content"]').on("change", "input", function()
    {
        var input = $(this);
        var data = {};
        data.modelID = input.data("model-id");
        data.action = input.data("action");
        sendCommand(data);
        
        var newAction; 
        if (data.action.indexOf("in") >= 0) {
            newAction = data.action.replace("in", "out");
        } else {
            newAction = data.action.replace("out", "in");
        }
        input.data("action", newAction);
    });
    
    function sendCommand(data)
    {
        ws.command({
            name:data.action,
            type:"command",
            data: {
                "phoneId" :data.modelID, //to login/logout phone
                "id" :data.modelID       //to login/logout from queue and setActiveForwardPreset
            },
            uuid: ws.generateUUID()
        });
    }
    
    $('div[data-role="content"]').on("change", "select", function()
    {
        var select = $(this);
        var acceptedLanguages = <?php echo json_encode(app()->params->languages); ?>;

        if (this.id === "select-custom-1" )
        {
            if (select.val() in acceptedLanguages) {
                //setLanguage(select.val());
                $.ajax({
                   url: "#",
                   data: {
                       
                       language:select.val()
                   },
                   error:function() {
                       alert("error");
                   },
                   success: function() {
                       window.location.reload();
                   }
                });
            }
        }
        
    });
</script>