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

//

export const showCreateNumberPlateScannerForm = async () => {
  await Swal.fire({
    title: 'Create Number Plate Scanner',
    html: `
      <form id="createUserForm">
        <div class="field">
          <label class="label">Name</label>
          <div class="control">
            <input class="input" type="text" id="name" />
          </div>
        </div>
        <div class="field">
          <label class="label">Department Id</label>
          <div class="control">
            <input class="input" type="number" id="department_id" />
          </div>
        </div>
        <div class="field">
          <label class="label">Notes</label>
          <div class="control">
            <input class="input" type="text" id="notes" />
          </div>
        </div>
      </form>
    `,
    showCancelButton: true,
    confirmButtonText: 'Create Number Plate Scanner',
    preConfirm: () => {
      const name = document.getElementById('name').value;
      const department_id = document.getElementById('department_id').value;
      const notes = document.getElementById('notes').value;
      createScanner(department_id, name, notes).then((response) => {
        Swal.fire({
          title: 'Number Plate Scanner created',
          icon: 'success'
        });
      }).catch((error) => {
        Swal.fire({
          title: 'Error',
          icon: 'error'
        });
      });
    }
  });
};

</script>