<script>
import { ref } from 'vue'
import { createDepartment } from "@/components/session/Session.vue";
import Swal from "sweetalert2";

//

export const showCreateDepartmentForm = async () => {
  await Swal.fire({
    title: 'Create Department',
    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">Description</label>
          <div class="control">
            <input class="input" type="text" id="description" />
          </div>
        </div>
      </form>
    `,
    showCancelButton: true,
    confirmButtonText: 'Create Department',
    preConfirm: () => {
      createDepartment(document.getElementById('name').value, document.getElementById('description').value)
          .then(() => {
            Swal.fire('Department created successfully');
          })
          .catch((e) => {
            Swal.fire('Error', e.response.data.error ?? e.response, 'error');
          });
    }
  });
}

</script>