<script>
    (function ($) {
        "use strict";
        $(document).ready(function () {
            var InputsWrapper = $("tfoot");
            var AddButton = $("#add_plan_btn");
            $('.main-title').on('click', AddButton, function (e) {
                e.preventDefault();
                $('#AddFeatureSection').toggle();
                // $(InputsWrapper).append('');
            });
        });

        $('tbody').sortable({
            cursor: "move",
            update: function (event, ui) {
                let ids = $(this).sortable('toArray', {attribute: 'data-id'});
                console.log(ids);
                if (ids.length > 0) {
                    let data = {
                        '_token': '{{ csrf_token() }}',
                        'ids': ids,
                    }
                    $.post("{{route('changePlanFeaturePosition')}}", data, function (data) {

                    });
                }
            }
        });


        $(document).on('click', '.editplan', function () {
            let plan = $(this).data('item');
            $('#planId').val(plan.id);
            $('#editTitle').val(plan.title);
            $('#editOrder').val(plan.order);
            $("#editplan").modal('show');
        });


        $(document).on('click', '.deleteplan', function () {
            let id = $(this).data('id');
            $('#planDeleteId').val(id);
            $("#deleteplan").modal('show');
        });


        $(document).on('click', '#add_plan_btn', function () {
            $('#addTitle').val('');
        });

    })(jQuery);
</script>

@if ($errors->any())
    <script>
        (function ($) {
            "use strict";
            @if(Session::has('type'))
            @if(Session::get('type')=="store")
            $('#add_plan').modal('show');
            @else
            $('#editplan').modal('show');
            @endif
            @endif
        })(jQuery);
    </script>
@endif
