<script>
import { ref } from 'vue'
import { editScanner } from '@/components/numberplatescanners/Scanners.vue'
import Swal from "sweetalert2";

//

export const showEditNumberPlateScannerForm = async (id, department_id, name, notes) => {
  await Swal.fire({
    title: 'Edit Number Plate Scanner',
    html: `
      <form id="editNumberPlateScannerForm">
        <div class="field">
          <label class="label">Department ID</label>
          <div class="control">
            <input class="input" type="text" id="department_id" value="${department_id}" />
          </div>
        </div>
        <div class="field">
          <label class="label">Name</label>
          <div class="control">
            <input class="input" type="text" id="name" value="${name}" />
          </div>
        </div>
        <div class="field">
          <label class="label">Notes</label>
          <div class="control">
            <input class="input" type="text" id="notes" value="${notes}" />
          </div>
        </div>
      </form>
    `,
    showCancelButton: true,
    confirmButtonText: 'Edit Scanner',
    preConfirm: () => {
      editScanner(id, document.getElementById('department_id').value, document.getElementById('name').value, document.getElementById('notes').value)
          .then(() => {
            Swal.fire('Scanner edited successfully');
          })
          .catch((e) => {
            Swal.fire('Error', e.response.data.error ?? e.response, 'error');
          });
    }
  });
}

</script>