<div style="display: none;">
    <div id="kitchenTxtContent">
        <div class="popup-header toolbar-header">
            <div class="popup-title">Send a text at kitchen #ref:120</div>
            <div class="popup-close-btn" onclick="zamanEposPopupcloser()"><span class="icon icon-cancel"></span></div>
        </div>
        <div class="popup-content">
            <p><textarea class="form-control" id="zamanOrderKitchenText" rows="3" placeholder="you type here"></textarea></p>
            <div class="tab-group keypad">
                <div class="tab-item zaman-epos-nav quantity-digit keypad-key" onclick="sentKtcMessage()"><span class="icon icon-air"></span>&nbsp;Send</div>
            </div>
            <div class="order-kitchen-keyboard"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function zamanOrderKitchenTextControllerPopup() {
        zamanEposDb.epos_order.get({orderId: Number(zamanEposCart.getEposCurrentId())}).then(function (anOrder) {
            if (typeof (anOrder) !== 'undefined' && anOrder.status >= 2 ) {
                if ($('#Keyboard').length > 0) {
                    $('#Keyboard').empty();
                    $('#Keyboard').removeAttr('id');
                }
                $('.order-kitchen-keyboard').attr('id', 'Keyboard');
                keyboard('Keyboard');
                $.colorbox({
                    inline: true,
                    scrolling: false,
                    href: "#kitchenTxtContent",
                    width: '100%',
                    height: 'auto',
                    maxWidth: "100%",
                    open: true,
                    closeButton: false,
                    transition: 'none',
                    overlayClose: false,
                    className: 'transparent-overlay',
                    onOpen: function () {
                        playBeepSound();
                    },
                    onLoad: function () {
                        jsKeyboard.currentElement = $('#zamanOrderKitchenText');
                    },
                    onComplete: function () {
                        playBeepSound();
                    },
                    onCleanup: function () {
                    },
                    onClosed: function () {
                        $('#zamanOrderKitchenText').val('');
                    }
                });
            }
        });
    }

    function sentKtcMessage(){
        var msg = $('#zamanOrderKitchenText').val();
        if($.trim(msg)){
            if(/^[\w\-\s]+$/i.test(msg)){
                if(checkInternetConnection()){
                    zamanEposDb.epos_order.get({orderId: Number(zamanEposCart.getEposCurrentId())}).then(function (anOrder) {
                            $.ajax({
                            url: '<?php echo site_url('api/sentktchmsg')?>',
                            type: 'POST',
                            data:{msg:$.trim(msg),sid:anOrder.sid,lid:anOrder.orderId,branch:anOrder.branch,team:anOrder.team},
                            beforeSend: function () {
                                $('.page-loader').show();
                            },
                            success: function (response) {
                                zamanEposPopupcloser()
                                $('.page-loader').hide();
                                console.log(response);
                            }
                        });
                    });
                }
            }else{
                warning('<?php echo $this->lang->line('warning')?>','Only number and characters allowed with message','<?php echo $this->lang->line('ok')?>');
            }
        }else{
            warning('<?php echo $this->lang->line('warning')?>','Please write your text and send','<?php echo $this->lang->line('ok')?>');
        }
    }
</script>