var z=Object.defineProperty;var N=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var S=(a,i,e)=>i in a?z(a,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[i]=e,o=(a,i)=>{for(var e in i||(i={}))v.call(i,e)&&S(a,e,i[e]);if(N)for(var e of N(i))I.call(i,e)&&S(a,e,i[e]);return a};import{b as g,z as s,_ as n,j as t,L as k}from"./main.2.8.10.js";import{b as Q}from"./react-router.DMwpH23k.js";import{u as j}from"./CopyIcn.BnhKHfEP.js";import{a9 as q}from"./Note.DalStCGz.js";const T=(a,i,e,d,u,l)=>{const r=o({},i),{name:p}=a.target;a.target.value!==""?r[p]=a.target.value:delete r[p],r[a.target.name]=a.target.value,e(o({},r))},F=(a,i,e,d)=>{e(!0),a.courseId,g({},"mslms_fetch_all_course").then(u=>{if(u&&u.success){const l=o({},a);l.default||(l.default={}),u.data&&(l.default.allCourse=u.data),i(o({},l)),e(!1),s.success(n("Course fetched successfully","bit-integrations"));return}e(!1),s.error(n("Course fetch failed. please try again","bit-integrations"))}).catch(()=>e(!1))},_=(a,i,e,d)=>{e(!0);const u={courseId:a.courseId};g(u,"msLms_fetch_all_lesson").then(l=>{if(l&&l.success){const r=o({},a);r.default||(r.default={}),l.data&&(r.default.allLesson=l.data),i(o({},r)),e(!1),s.success(n("Lesson fetched successfully","bit-integrations"));return}e(!1),s.error(n("Lesson fetch failed. please try again","bit-integrations"))}).catch(()=>e(!1))},f=(a,i,e,d)=>{e(!0);const u={courseId:a.courseId};g(u,"msLms_fetch_all_quiz").then(l=>{if(l&&l.success){const r=o({},a);r.default||(r.default={}),l.data&&(r.default.allQuiz=l.data),i(o({},r)),e(!1),s.success(n("Quiz fetched successfully","bit-integrations"));return}e(!1),s.error(n("Quiz fetch failed. please try again","bit-integrations"))}).catch(()=>e(!1))};function U({formFields:a,handleInput:i,msLmsConf:e,setMsLmsConf:d,isLoading:u,setIsLoading:l,setSnackbar:r,allIntegURL:p,isInfo:D,edit:E}){var y,A,w;Q.useEffect(()=>{["1","2","3","4","5"].includes(e.mainAction)&&F(e,d,l)},[e.mainAction]);const x=(c,h)=>{const b=o({},e);c!==""?(b[h]=c,(e.mainAction==="2"||e.mainAction==="5")&&_(b,d,l),e.mainAction==="3"&&f(b,d,l)):delete b[h],d(o({},b))};return t.jsxs(t.Fragment,{children:[t.jsx("br",{}),t.jsx("b",{className:"wdt-200 d-in-b",children:n("Actions:","bit-integrations")}),t.jsxs("select",{onChange:i,name:"mainAction",value:e.mainAction,className:"btcd-paper-inp w-5",children:[t.jsx("option",{value:"",children:n("Select Actions","bit-integrations")}),e.allActions&&e.allActions.map(({key:c,label:h})=>t.jsx("option",{value:c,children:h},c))]}),t.jsx("br",{}),t.jsx("br",{}),["1","2","3","4","5"].includes(e.mainAction)&&t.jsxs("div",{className:"flx mt-4",children:[t.jsx("b",{className:"wdt-200 d-in-b",children:n("Select a Course:","bit-integrations")}),t.jsx(j,{className:"w-5",singleSelect:!0,defaultValue:e==null?void 0:e.courseId,options:((y=e==null?void 0:e.default)==null?void 0:y.allCourse)&&e.default.allCourse.map(c=>({label:c.post_title,value:c.ID.toString()})),onChange:c=>x(c,"courseId")}),t.jsx("button",{onClick:()=>fetchAllCourse(e,d,l,r),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${n("Fetch course list","bit-integrations")}'`},type:"button",disabled:u,children:"↻"})]}),(e.mainAction==="2"||e.mainAction==="5")&&(e==null?void 0:e.courseId)&&t.jsxs("div",{className:"flx mt-4",children:[t.jsx("b",{className:"wdt-200 d-in-b",children:n("Select Lesson:","bit-integrations")}),t.jsx(j,{className:"w-5",singleSelect:!0,defaultValue:e==null?void 0:e.lessonId,options:((A=e==null?void 0:e.default)==null?void 0:A.allLesson)&&e.default.allLesson.map(c=>({label:c.post_title,value:c.ID.toString()})),onChange:c=>x(c,"lessonId")}),t.jsx("button",{onClick:()=>_(e,d,l),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${n("Fetch lesson list","bit-integrations")}'`},type:"button",disabled:u,children:"↻"})]}),e.mainAction==="3"&&(e==null?void 0:e.courseId)&&t.jsxs("div",{className:"flx mt-4",children:[t.jsx("b",{className:"wdt-200 d-in-b",children:n("Select Quiz:","bit-integrations")}),t.jsx(j,{className:"w-5",singleSelect:!0,defaultValue:e==null?void 0:e.quizId,options:((w=e==null?void 0:e.default)==null?void 0:w.allQuiz)&&e.default.allQuiz.map(c=>({label:c.post_title,value:c.ID.toString()})),onChange:c=>x(c,"quizId")}),t.jsx("button",{onClick:()=>f(e,d,l),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${n("Fetch quiz list","bit-integrations")}'`},type:"button",disabled:u,children:"↻"})]}),t.jsx("br",{}),t.jsx("br",{}),u&&t.jsx(k,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}}),t.jsx(q,{note:n("This integration will only work for logged-in users.","bit-integrations")})]})}export{U as M,T as h};
