(()=>{"use strict";var t={};// The module cache
var n={};// The require function
function e(r){// Check if module is in cache
var i=n[r];if(i!==undefined){return i.exports}// Create a new module (and put it into the cache)
var s=n[r]={exports:{}};// Execute the module function
t[r](s,s.exports,e);// Return the exports of the module
return s.exports}// webpack/runtime/rspack_version
(()=>{e.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{e.ruid="bundler=rspack@1.6.5"})();// UNUSED EXPORTS: initAssignment
;// CONCATENATED MODULE: external "wp.i18n"
const r=wp.i18n;// CONCATENATED MODULE: ./addons/tutor-assignments/assets/src/js/assignment-submission.ts
var i=t=>{var{query:n,toast:e,modal:i,endpoints:s}=window.TutorCore;var{wpPost:o}=window.TutorCore.api;var{convertToErrorMessage:a}=window.TutorCore.error;return{query:n,startAssignmentMutation:null,submitAssignmentMutation:null,removeAttachmentMutation:null,removeAssignmentAttemptMutation:null,init(){this.startAssignmentMutation=this.query.useMutation(this.startAssignment,{onSuccess:t=>{if(t.success){window.location.href=typeof t.data==="string"?t.data:""}else{e.error(typeof t.data==="string"?t.data:(0,r.__)("Something went wrong","tutor-pro"))}},onError:t=>{e.error(a(t))}});this.submitAssignmentMutation=this.query.useMutation(this.submitAssignment,{onSuccess:n=>{i.closeModal(t);window.location.href=typeof n.data==="string"?n.data:""},onError:t=>{e.error(a(t))}});this.removeAttachmentMutation=this.query.useMutation(this.removeAttachment,{onSuccess:t=>{e.success(t.message)},onError:t=>{e.error(a(t))}});this.removeAssignmentAttemptMutation=this.query.useMutation(this.removeAssignmentAttempt,{onSuccess:t=>{window.location.href=typeof t.data==="string"?t.data:""},onError:t=>{e.error(a(t))}})},startAssignment(t){return o("tutor_start_assignment",{assignment_id:t})},handleStart(t){return{":disabled":()=>{var t;return(t=this.startAssignmentMutation)===null||t===void 0?void 0:t.isPending},":class":()=>{var t;return{"tutor-btn-loading":(t=this.startAssignmentMutation)===null||t===void 0?void 0:t.isPending}},"@click":()=>{var n;return(n=this.startAssignmentMutation)===null||n===void 0?void 0:n.mutate(t)}}},submitAssignment(t){return o(s.ASSIGNMENT_SUBMIT,t)},handleAssignmentSubmit(t){var n;(n=this.submitAssignmentMutation)===null||n===void 0?void 0:n.mutate(t)},removeAttachment(t){return o(s.REMOVE_ATTACHMENT,t)},handleRemoveAssignmentAttachment(t){var n;if("submitted"!==t.status){return}(n=this.removeAttachmentMutation)===null||n===void 0?void 0:n.mutate(t)},removeAssignmentAttempt(t){return o(s.REMOVE_ASSIGNMENT_ATTEMPT,t)},handleRemoveAssignmentAttempt(t){var n;(n=this.removeAssignmentAttemptMutation)===null||n===void 0?void 0:n.mutate(t)}}};var s=()=>{window.TutorComponentRegistry.register({type:"component",meta:{name:"assignment",component:i}});window.TutorComponentRegistry.initWithAlpine(window.Alpine)};document.addEventListener("alpine:init",s)})();