<script>
import { ref } from 'vue'
import { editOrderNotes } from "@/components/shop/Orders.vue";
import Swal from "sweetalert2";

//

export const showEditOrderNotesForm = async (id, notes) => {
  await Swal.fire({
    title: 'Edit order note',
    html: `
        <div class="field">
          <label>Noter (Sendes til kunden på faktura)</label>
          <div class="control">
            <textarea class="textarea is-dark" type="text" id="notes">${notes}</textarea>
          </div>
        </div>
      </form>
    `,
    showCancelButton: true,
    confirmButtonText: 'Save',
    preConfirm: () => {
      // Show loading
      Swal.showLoading();
      editOrderNotes(id, document.getElementById('notes').value)
          .then(() => {
            // Close the modal
            Swal.close();
          })
          .catch((e) => {
            Swal.fire('Error', e.response.data.error ?? e.response, 'error');
          });
    }
  });
}

</script>