import { alert, confirm } from '../js/dialogs.js'

export default {
  methods: {
    array_move: function (arr, old_index, new_index) {
        if (new_index >= arr.length) {
            var k = new_index - arr.length + 1;
            while (k--) {
                arr.push(undefined);
            }
        }
        arr.splice(new_index, 0, arr.splice(old_index, 1)[0])
      },
      rowUp(array, row) {
        let index = array.indexOf(row)
        if (index > 0) {
            this.array_move(array, index, index-1)
        }
      },
      rowDown(array, row) {
        let index = array.indexOf(row)
        if (index < array.length-1) {
            this.array_move(array, index, index+1)
        }
      },
      rowDelete(array, row) {
        confirm('Do you really want to delete?', 'Confirm').then((res)=> {
          if (res == true) {
            let index = array.indexOf(row)
            array.splice(index, 1)
          }
        })
      },
  }
}
