<?php $__env->startSection('body'); ?>
    <div class="wrapper-content animated fadeInRight form-horizontal">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <a href="<?php echo e(url('/edit-team')); ?>" class="btn btn-outline btn-info pull-right"> <i
                                    class="fa fa-bars"></i>Lista</a>
                        <h2 class="ibox-title">Editarea datelor echipei</h2>
                        <div class="team-form">
                            <form method="post" id="user-profile" class="user-profile">
                                <input type="hidden" name="team_id" value="<?php echo e(isset($item->id) ? $item->id : ''); ?>">
                                <div class="form-group">
                                    <label for="name" class="col-sm-1 control-label">Nume:</label>
                                    <div class="col-sm-11">
                                        <input id="name" type="text" class="form-control"
                                               value="<?php echo e(isset($item->name) ? $item->name : ''); ?>" name="name">
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="btn-controls btn-inline-block-right">
                            <?php if(!is_null($item) && auth()->user()->is_admin == 3): ?>
                                <div class="btn btn-danger" onclick="destroyTeam()">Sterge</div>
                            <?php endif; ?>
                            <div class="btn btn-primary" onclick="saveTeam()">Salvează</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">

        function saveTeam() {
            var data = $('form#user-profile').serialize();

            var node = $('form#user-profile');
            clearErrorMsg(node);
            $.ajax({
                type: 'POST',
                url: '/edit-team/save',
                beforeSend: function () {
                    loader_list.fadeIn();
                },
                data: data,
                success: function (resp) {
                    loader_list.fadeOut();
                    if (resp.msg)
                        toastr[resp.msg.type](resp.msg.e);

                    if (resp.validator) addErrorMsg(node, resp.validator);

                    if (resp.status) {
                        $('form#user-profile [name="team_id"]').val(resp.item.team_id);

                        setTimeout(function () {
                            window.location.href = resp.url;
                        }, 1500);
                    }
                },
                error: function () {
                    loader_list.fadeOut();

                    setTimeout(function(){
                        window.location.reload();
                    }, 500)
                }
            });
        }

        function destroyTeam() {
            var team_id = $('input[name="team_id"]').val();

            $.ajax({
                type: 'POST',
                url: '/edit-team/destroy',
                beforeSend: function () {
                    loader_list.fadeIn();
                },
                data: {team_id: team_id},
                success: function (resp) {
                    loader_list.fadeOut();
                    toastr[resp.msg.type](resp.msg.e);

                    if (resp.status === true) {
                        setTimeout(function () {
                            window.location.href = resp.url;
                        }, 1500);
                    }
                },
                error: function () {
                    loader_list.fadeOut();

                    setTimeout(function(){
                        window.location.reload();
                    }, 500)
                }
            });

        }
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('tpl', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>