import '../../vendor/murph/murph-core/src/core/Resources/assets/js/admin.js'

require('./admin_modules/simplemde')()

const $ = require('jquery')
const Sortable = require('sortablejs').Sortable

const gallerySorting = () => {
  $('div[data-collection^="collection-stlfiles"]').each((i, list) => {
    const element = $(list)

    return new Sortable(list, {
      handle: '*[data-collection-item]',
      sort: true,
      animation: 150,
      fallbackTolerance: 3,
      onEnd: (e) => {
        const positions = element.find('*[data-collection-item] input[type=hidden]')

        positions.each((order, v) => {
          $(v).val(order)
        })
      }
    })
  })
}

gallerySorting()
