$(function() {
    document.addEventListener('DOMContentLoaded', function () {
        var elems = document.querySelectorAll('select');
        var instances = M.FormSelect.init(elems, options);
    });


    $(document).on("click", ".btn-delete", function(e){
        console.log('clicou')
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        console.log(confirmSubmit);
        if (confirmSubmit) {
          return true;
        } else {
            e.stopPropagation();
            return false;
        }
        
    });



    // Or with jQuery

    $(document).ready(function () {
        $('select').formSelect();
        
    });

    $('.alteraStatus').click(function (ev){
        ev.preventDefault();
        var id = $(this).attr('data-id');
        var secao = $(this).attr('data-secao')+'/change-status';
        var idlink = $(this).attr('id');
        console.log(idlink);
        console.log($('meta[name="_token"]').attr('content'));
        $.ajax({
            type:'POST',
            url:secao,
            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
            data: {id:id},
            success:function(data){
                if (data == 'true') {
                    console.log(data+"true");
                    $('#'+idlink).removeClass('btn-inverse-info');
                    $('#'+idlink).addClass('btn-inverse-success');
                    $('#iconStatus').removeClass('mdi mdi-eye-off');
                    $('#iconStatus').addClass('mdi mdi-eye');
                } else {
                    console.log(data);
                    $('#'+idlink).removeClass('btn-inverse-success');
                    $('#'+idlink).addClass('btn-inverse-info');
                    $('#iconStatus').removeClass('mdi mdi-eye');                    
                    $('#iconStatus').addClass('mdi mdi-eye-off');
                    console.log('fez');
                }
               
            }
         });

        //$.post(secao, {id:id}, function() {
            
    });

        
    $('#filter-btn').on('click', function (e){
        e.preventDefault();
        var bscCategory = $('#bscCategory').val();
        var bscTitle = $('#bscTitle').val();
        var posts = $('#post_id');
        posts.html('');
        $.ajax({
            type:'POST',
            url: host+'/admin/blog-post/find-category',
            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
            data: {bscCategory:bscCategory, bscTitle: bscTitle},
            dataType: "json",
            success:function(data){
                posts.html(data.html)
            }
        });
        
        return false;
    });

    $('#itemBeneficio').on('submit', function(e) {
        e.preventDefault(); 
        console.log(host+'produto/beneficio-item');

        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/produto/beneficio-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensBeneficios').html(data.output);
                $( ".sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids_items[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model_items']").val();
                        var parent_id = $("input[name='parent_id_items']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( ".sortable tbody" ).disableSelection();
            }
        });
    });

    $('body').on('click','.itemBeneficioDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var produto = $(this).data("produto");
            var beneficio = $(this).data("beneficio");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/produto-beneficio-item-del',
                data: {produto:produto, beneficio:beneficio, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensBeneficios').html(data.output);
                    $( ".sortable tbody" ).sortable({
                        update : function (){
                            var values = [];
                            $("input[name='ids_items[]']").each(function() {
                                values.push($(this).val());
                            });
                            var token =  token;
                            var model = $("input[name='model_items']").val();
                            var parent_id = $("input[name='parent_id_items']").val();
                            $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                            });
                        }
                    });
                    $( ".sortable tbody" ).disableSelection();
                }
            });
            return false;
        }
    });


    
    $('#itemFeature').on('submit', function(e) {
        e.preventDefault(); 
        console.log(host+'produto/feature-item');
        
    
        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/produto/feature-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensFeatures').html(data.output);
                $( "#sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model']").val();
                        var parent_id = $("input[name='parent_id']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( "#sortable tbody" ).disableSelection();
            }
        });
        
    });

    $('body').on('click','.itemFeatureDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var produto = $(this).data("produto");
            var feature = $(this).data("feature");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/produto-feature-item-del',
                data: {produto:produto, feature:feature, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensFeatures').html(data.output);
                    $( "#sortable tbody" ).sortable({
                        update : function (){
                            var values = [];
                            $("input[name='ids[]']").each(function() {
                                values.push($(this).val());
                            });
                            var token =  token;
                            var model = $("input[name='model']").val();
                            var parent_id = $("input[name='parent_id']").val();
                            $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                            });
                        }
                    });
                    $( "#sortable tbody" ).disableSelection();
                }
            });
            return false;
        }
    });

    $('body').on('click','.noticiaProdutoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var produto = $(this).data("produto");
            var noticia = $(this).data("noticia");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/produto-noticia-del',
                data: {produto:produto, noticia:noticia, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listNoticiasProduto').html(data.output);
                }
            });
            return false;
        }
    });

    

    $('body').on('click','.caseProdutoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var produto = $(this).data("produto");
            var cases = $(this).data("case");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/produto-case-del',
                data: {produto:produto, case:cases, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listCasesProduto').html(data.output);
                }
            });
            return false;
        }
    });

    $('body').on('click','.caseSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var cases = $(this).data("case");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-case-del',
                data: {solucao:solucao, case:cases, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listCasesSolucao').html(data.output);
                }
            });
            return false;
        }
    });

    $('body').on('click','.segmentoSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var segmentos = $(this).data("segmento");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-segmento-del',
                data: {solucao:solucao, segmento:segmentos, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listSegmentosSolucao').html(data.output);
                }
            });
            return false;
        }
    });

    $('body').on('click','.noticiaSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var noticias = $(this).data("noticia");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-noticia-del',
                data: {solucao:solucao, noticia:noticias, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listNoticiasSolucao').html(data.output);
                }
            });
            return false;
        }
    });

    $('#itemBeneficioSolucao').on('submit', function(e) {
        e.preventDefault(); 
        console.log(host+'solucao/beneficio-item');
        
        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/solucao/beneficio-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensBeneficiosSolucao').html(data.output);
                $( ".sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids_items[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model_items']").val();
                        var parent_id = $("input[name='parent_id_items']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( ".sortable tbody" ).disableSelection();
            }
        });
    });

    
    $('body').on('click','.itemBeneficioSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var beneficio = $(this).data("beneficio");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-beneficio-item-del',
                data: {solucao:solucao, beneficio:beneficio, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensBeneficiosSolucao').html(data.output);
                    $( ".sortable tbody" ).sortable({
                        update : function (){
                            var values = [];
                            $("input[name='ids_items[]']").each(function() {
                                values.push($(this).val());
                            });
                            var token =  token;
                            var model = $("input[name='model_items']").val();
                            var parent_id = $("input[name='parent_id_items']").val();
                            $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                            });
                        }
                    });
                    $( ".sortable tbody" ).disableSelection();
                }
            });
            return false;
        }
    });

    

    $('#itemFeatureSolucao').on('submit', function(e) {
        e.preventDefault(); 
        console.log(host+'solucao/feature-item');

        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/solucao/feature-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensFeaturesSolucao').html(data.output);
                $( "#sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model']").val();
                        var parent_id = $("input[name='parent_id']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( "#sortable tbody" ).disableSelection();
            }
        });
    });

    
    $('body').on('click','.itemFeatureSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var feature = $(this).data("feature");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-feature-item-del',
                data: {solucao:solucao, feature:feature, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensFeaturesSolucao').html(data.output);
                    $( "#sortable tbody" ).sortable({
                        update : function (){
                            var values = [];
                            $("input[name='ids[]']").each(function() {
                                values.push($(this).val());
                            });
                            var token =  token;
                            var model = $("input[name='model']").val();
                            var parent_id = $("input[name='parent_id']").val();
                            $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                            });
                        }
                    });
                    $( "#sortable tbody" ).disableSelection();
                }
            });
            return false;
        }
    });

    $('#itemDificuldadeSolucao').on('submit', function(e) {
        e.preventDefault(); 
        console.log(host+'solucao/dificuldade-item');

        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/solucao/dificuldade-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensDificuldadesSolucao').html(data.output);
            }
        });
    });

    
    $('body').on('click','.itemDificuldadeSolucaoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var solucao = $(this).data("solucao");
            var dificuldade = $(this).data("dificuldade");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            
            $.ajax({
                type: "DELETE",
                url: host+'/admin/solucao-dificuldade-item-del',
                data: {solucao:solucao, dificuldade:dificuldade, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensDificuldadesSolucao').html(data.output);
                }
            });
            return false;
        }
    });
    
    
    $('body').on('click','.produtoDepoimentoDel', function(e) {
        e.preventDefault(); 
        
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
            var depoimento = $(this).data("depoimento");
            var itemId = $(this).data("produto");
            var token = $(this).data("token");

            $.ajax({
                type: "DELETE",
                url: host+'/admin/depoimento-produto-del',
                data: {depoimento:depoimento, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listProdutosDepoimento').html(data.output);
                }
            });
            return false;
        }
    });
    
    $('body').on('click','.solucaoDepoimentoDel', function(e) {
        e.preventDefault(); 
        
        
        var depoimento = $(this).data("depoimento");
        var itemId = $(this).data("solucao");
        var token = $(this).data("token");

        $.ajax({
            type: "DELETE",
            url: host+'/admin/depoimento-solucao-del',
            data: {depoimento:depoimento, item:itemId, "_method": 'DELETE', "_token": token},
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listSolucaoDepoimento').html(data.output);
            }
        });
        return false;
    });

    
    $('#itemFeatureSegmento').on('submit', function(e) {
        e.preventDefault(); 
    
        console.log(host+'segmento/feature-item');

        var item_icom = $('#item_icon').val();
        var item_titulo = $('#item_titulo').val();
        var item_description = $('#item_description').val();
        var benId = $('#benId').val();
        $.ajax({
            type: "POST",
            url: host+'/admin/segmento/feature-item',
            data: $(this).serialize(),
            dataType: "json",
            success: function( data ) {
                // console.log(data.output);
                $('#listItensFeaturesSegmento').html(data.output);
                $( "#sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model']").val();
                        var parent_id = $("input[name='parent_id']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( "#sortable tbody" ).disableSelection();
            }
        });
         
    });

    
    $('body').on('click','.itemFeatureSegmentoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
        
            var segmento = $(this).data("segmento");
            var feature = $(this).data("feature");
            var itemId = $(this).data("item");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/segmento-feature-item-del',
                data: {segmento:segmento, feature:feature, item:itemId, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listItensFeaturesSegmento').html(data.output);
                    $( "#sortable tbody" ).sortable({
                        update : function (){
                            var values = [];
                            $("input[name='ids[]']").each(function() {
                                values.push($(this).val());
                            });
                            var token =  token;
                            var model = $("input[name='model']").val();
                            var parent_id = $("input[name='parent_id']").val();
                            $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                            });
                        }
                    });
                    $( "#sortable tbody" ).disableSelection();
                }
            });
            return false;
        }
    });

    $('body').on('click','.clienteSegmentoDel', function(e) {
        e.preventDefault(); 
        
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
            var segmento = $(this).data("segmento");
            var clientes = $(this).data("cliente");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/segmento-cliente-del',
                data: {segmento:segmento, cliente:clientes, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listClientesSegmento').html(data.output);
                }
            });
            return false;
        }
    });

    $('body').on('click','.faqSegmentoDel', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
            var segmento = $(this).data("segmento");
            var faqs = $(this).data("faq");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/segmento-faq-del',
                data: {segmento:segmento, faq:faqs, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    // console.log(data.output);
                    $('#listFaqsSegmento').html(data.output);
                }
            });
            return false;
        }
    });
    

    $('.c-tipo__blog').on('change', function (ev){
        $('.background').toggle('on');
        
    });

    // $('form').on('submit', function (ev){
        
    //     //$('.btn-block').prop("disabled",true);
        
    // });

    $('body').on('click','.bt-excluir-img', function(e) {
        e.preventDefault(); 
        const confirmSubmit = confirm('Tem certeza de que deseja excluir?');
        if (!confirmSubmit) {
            return false
        } else { 
            var pagina = $(this).data("pagina");
            var id = $(this).data("id");
            var campo = $(this).data("campo");
            var token = $(this).data("token");
            $.ajax({
                type: "DELETE",
                url: host+'/admin/images-del',
                data: {id:id, pagina:pagina, campo:campo, "_method": 'DELETE', "_token": token},
                dataType: "json",
                success: function( data ) {
                    $('.content-img-'+campo).html('');
                }
            });
            return false;
        }
    });


    $('.editItem').on('click', function(){
        var item = $(this).data("item");
        var textarea = $('#item_'+item);
        var acoes_edita = $('.acoes_edit_'+item);
        var acoes_salvar = $('.acoes_salvar_'+item);
        
        textarea.removeAttr("disabled");
        textarea.css("background","#fff");

        acoes_edita.addClass('hide');
        acoes_salvar.removeClass('hide');
        
    });

    $('.cancelItem').on('click', function(){
        var item = $(this).data("item");
        var textarea = $('#item_'+item);

        var acoes_edita = $('.acoes_edit_'+item);
        var acoes_salvar = $('.acoes_salvar_'+item);

        textarea.attr("disabled","disabled");
        textarea.css("background","none");
        
        acoes_edita.removeClass('hide');
        acoes_salvar.addClass('hide');

    });

    $( ".formItem" ).on( "submit", function( event ) {
        event.preventDefault();
        var data = $( this ).serialize();
        var list = $('#modal_list').val();
        console.log( data );

        $.ajax({
            type: "PUT",
            url: host+'/admin/edit-itens',
            data: data,
            dataType: "json",
            success: function( data ) {
                $('#'+list).html(data.output);
                modal.addClass('hide')
                $( ".sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids_items[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model_items']").val();
                        var parent_id = $("input[name='parent_id_items']").val();
                        $.ajax({
                        type: "PUT",
                        url: host+'/admin/orders',
                        headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                        data: {ids:values, model:model, parent_id:parent_id},
                        dataType: "json",
                        success: function( data ) {
                            
                        }
                        });
                    }
                });
                $( ".sortable tbody" ).disableSelection();
                $( "#sortable tbody" ).sortable({
                    update : function (){
                        var values = [];
                        $("input[name='ids[]']").each(function() {
                            values.push($(this).val());
                        });
                        var token =  token;
                        var model = $("input[name='model']").val();
                        var parent_id = $("input[name='parent_id']").val();
                        
                        $.ajax({
                            type: "PUT",
                            url: host+'/admin/orders',
                            headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            data: {ids:values, model:model, parent_id:parent_id},
                            dataType: "json",
                            success: function( data ) {
                                
                            }
                        });
                    }
                });
                $( "#sortable tbody" ).disableSelection();
            }
        });
        return false;
    });
    

    var modal = $("#myModal");


    $('body').on('click','.myBtn', function(){
        console.log('clicou');
        var id = $(this).data('item');
        var pagina = $(this).data('pagina');

        var icon = $(this).data('icon');
        var descricao = $(this).data('descricao');
        var titulo = $(this).data('titulo');
        
        var list = $(this).data('list');
        var obj = $(this).data('obj');

        $('#modal_id_item').val(id);
        $('#modal_pagina').val(pagina);

        $('#modal_icon_item').val(icon);
        $('#modal_titulo_item ').val(titulo);
        $('#modal_descricao_item').val(descricao);
        
        $('#modal_list').val(list);
        $('#modal_obj').val(obj);

        modal.removeClass('hide')
    });

    

    $('.close').on('click', function(){
        modal.addClass('hide')
    });

    $('.close-modal').on('click', function(){
        modal.addClass('hide')
    });



    
});



