<script>

    (function ($) {
        "use strict";

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

                    });
                }
            }
        });


        $(document).on('click', '.changePopular', function () {
            let id = $(this).data('id');
            let status = $(this).data('status');

            let data = {
                '_token': '{{ csrf_token() }}',
                'status': status,
                'id': id,
            }
            $.post("{{route('changePlanPopular')}}", data, function (data) {

            });

        });
        $(document).on('click', '.editplan', function () {

            let plan = $(this).data('item');
            $('#planId').val(plan.id);
            $('#editTitle').val(plan.title);
            $('#category_id_edit').val(plan.category_id);
            $('#editPrice').val(plan.price);
            $('#editAbout').val(plan.about);
            $('#editBtnTxt').val(plan.btn_txt);
            $('#editDays').val(plan.days);
            $('#category_id_edit').niceSelect('update');
            $('input[name="is_recurring"][value="' + plan.is_recurring + '"]').prop('checked', true);
            $("#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('');
            $('#addPrice').val('');
            $('#addAbout').val('');
            $('#addDays').val('');
            $('#addBtn').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
<script type="application/javascript">
    (function ($) {
        "use strict";

        dataTableOptions = updateColumnExportOption(dataTableOptions, [1, 2, 3, 4, 5, 6]);

        $('#lms_table').DataTable(dataTableOptions);
    })(jQuery);

</script>
