1import{i2 as e,r as Z,u as Te,iE as m,v as g,G as Be,H as Qe,c0 as J,kO as Ke,kQ as Ve,j as Ge,ad as He,bO as oe,ac as We,l4 as Xe}from"./index-m0nIusX2.js";import{as as Ze,at as Je}from"./main-B-Q_hDbY.js";import{bR as Ye,c9 as he,bH as Ie,bQ as es,c7 as ss,bV as ts}from"./training-Csqk5WXx.js";import{a as le}from"./useDebouncedValue-ICJsIdDe.js";import{d as rs}from"./useNavigate-CjRXjgJ2.js";import{p as ns,r as as}from"./scorm-BfYZ-tBo.js";import{B as D}from"./badge-BCMxaEMg.js";import{I as O}from"./input-19-b3r-T.js";import{L}from"./label-CDX2fXz3.js";import{M as fe}from"./multi-select-D97MmYDa.js";import{S as is,f as os,g as ls,a as ds,c as cs}from"./select-gOil4l5w.js";import{S as Q}from"./skeleton-CNdnTm6N.js";import{a as us,C as pe,L as ge}from"./LessonEditor-C_SZcS_B.js";import{D as ms}from"./data-table-DhOn_5Ve.js";import{D as ve,b as je,e as Ne,f as be,c as ye,d as xs}from"./dialog-CFYhFcS7.js";import{a as hs,c as we,b as fs}from"./CourseEnrollmentsDialog-DZdJnPuj.js";import{y as ps}from"./prm-BsIZLOY9.js";import{q as gs}from"./queryKeys-B45qGzbE.js";import{R as vs,a as js}from"./radio-group-C08LUop7.js";import{t as w}from"./toast-DVMkOnGB.js";import{i as Ns,e as bs}from"./externalLms-4JOv-73x.js";import{S as ys}from"./share-2-DgN7CuUZ.js";import{C as ws}from"./clipboard-list-C6ymJgJs.js";import{U as Cs}from"./users-D74et90S.js";import{S as Ss}from"./send-C4aWHj_v.js";import{F as ks,a as Ps}from"./folder-plus-FI-4Umwi.js";import"./NewVersionNotice-CrTFp0hf.js";import"./useBrandTheme-sQQ09a9X.js";import"./MultiChannelRevenueApp-DUnEa3zZ.js";import"./revenue-Bu8mA0KS.js";import"./partnerLogo-BXvhM4ZD.js";import"./mdi-3HaUydhU.js";import"./entitlement-CyHOcwOn.js";import"./usePostHog-CRYHY6ir.js";import"./checkbox-G2vka5Hu.js";import"./index-uEVxYnCT.js";import"./index-B44nOmpW.js";import"./popover-CGlOkWc4.js";import"./index-BXR6F2tF.js";import"./table-CrmSJbvH.js";import"./card-GJzlNXrB.js";import"./native-date-input-DI2oKHvG.js";import"./info-tooltip-XXnoIbIR.js";import"./react-apexcharts.esm-DfsHi1ot.js";import"./useQueries-DPzJKR8R.js";import"./tabs-CkSvPL9R.js";import"./index-vDSVTUCl.js";import"./index-B6ksRBvq.js";import"./index-MnGK8kX1.js";import"./index-B5SjYlct.js";import"./textarea-DQD8e6_8.js";import"./alert-dialog-xuEC_uzA.js";import"./index-CiNTbKJG.js";import"./SearchBox-BlgUqEeD.js";import"./JsonViewer-CRlhcjkI.js";import"./StatusChip-DIPkyc-U.js";import"./purify.es-DCSLj_Qk.js";import"./command-QbbEZl6d.js";import"./index-CL1vzYPC.js";import"./with-selector-GRmPFr_4.js";import"./index-BeoYln4u.js";import"./index-BRn12YI3.js";import"./index-BdQq_4o_.js";import"./chevrons-up-down-CDydpTXX.js";import"./PrmKpiTooltip-axfO09X9.js";import"./usePrmTracking-C-RjCWeW.js";import"./progress-BnQsWDkD.js";import"./index-B-YO4kT9.js";import"./lock-CPIAZmx2.js";import"./index-XPwPOg3t.js";import"./index-BGOBajrD.js";import"./index-C7yKKq-w.js";import"./index-Vcq4gwWv.js";import"./cosell-D_8W5V4v.js";import"./partner-relationship-management-CL914no1.js";function de(s){if(!s)return"â";const t=new Date(s);return Number.isNaN(t.getTime())?"â":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function z(s,t=""){const d=we(s)==="Renewed";return[t,d?"opacity-60":""].filter(Boolean).join(" ")}function Ls(s){return new Set(s.map(t=>t.userId??t.id)).size}function Ms(s){const t=new Map;for(const d of s){const a=d.organizationId??"â",u=t.get(a);u?u.rows.push(d):t.set(a,{orgId:a,orgName:d.organizationName??"Unknown organization",rows:[d]})}return[...t.values()]}const Es=[{title:"Learner",key:"__learner"},{title:"Certificate",key:"__certificate"},{title:"Version",key:"__version"},{title:"Issued",key:"__issued"},{title:"Expires",key:"__expires"},{title:"Status",key:"__status"}];function Os({open:s,onOpenChange:t,orgId:d,courseId:a,courseName:u}){const j=Ye(d,a,{query:{enabled:s&&!!d&&!!a}}),N=j.data,x=N?.status===200?N.data??[]:[],o=Ms(x),f=j.error?.status,l=j.isError&&f!==404,y={__learner:n=>e.jsx("span",{className:z(n,"font-medium text-foreground"),children:n.userName??n.userId??"â"}),__certificate:n=>e.jsx("span",{className:z(n,"text-muted-foreground"),children:n.snapshot?.name??"â"}),__version:n=>e.jsx("span",{className:z(n,"text-muted-foreground"),children:n.courseVersionNo?`v${n.courseVersionNo}`:"â"}),__issued:n=>e.jsx("span",{className:z(n,"tabular-nums text-muted-foreground"),children:de(n.issuedAt)}),__expires:n=>e.jsx("span",{className:z(n,"tabular-nums text-muted-foreground"),children:n.expiresAt?de(n.expiresAt):"Never"}),__status:n=>e.jsx("span",{className:z(n),children:e.jsx(hs,{status:we(n)})})};return e.jsx(ve,{open:s,onOpenChange:t,children:e.jsxs(je,{className:"sm:max-w-2xl",children:[e.jsxs(Ne,{children:[e.jsx(be,{children:"Certified learners"}),e.jsxs(ye,{children:["Partners who have earned a certificate from",u?` "${u}"`:" this course",".",o.length>0?` ${o.length} certified partner${o.length===1?"":"s"}.`:""]})]}),j.isLoading?e.jsx(Q,{className:"h-48 w-full"}):l?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border py-12 text-center",children:[e.jsx("div",{className:"mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-muted text-muted-foreground",children:e.jsx(Z,{className:"h-6 w-6"})}),e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Couldn't load certified learners"}),e.jsx("div",{className:"mt-1 max-w-sm text-sm text-muted-foreground",children:"Something went wrong â please try again."})]}):o.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border py-12 text-center",children:[e.jsx("div",{className:"mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-muted text-muted-foreground",children:e.jsx(Z,{className:"h-6 w-6"})}),e.jsx("div",{className:"text-sm font-medium text-foreground",children:"No certified learners yet"}),e.jsx("div",{className:"mt-1 max-w-sm text-sm text-muted-foreground",children:"Learners who pass this course will appear here once a certificate is issued."})]}):e.jsx("div",{className:"max-h-[60vh] overflow-y-auto scrollbar-visible",children:e.jsx("div",{className:"space-y-5",children:o.map(n=>e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:n.orgName}),e.jsx(D,{variant:"secondary",children:Ls(n.rows)})]}),e.jsx("div",{className:"rounded-xl border border-border/60 bg-card overflow-hidden",children:e.jsx(ms,{tableData:n.rows,selectedHeaders:Es,loading:!1,rowsPerPage:n.rows.length||1,ifShowPagination:!1,columnTemplates:y})})]},n.orgId))})})]})})}function ce({orgId:s,courseId:t,courseName:d,modules:a,onClose:u}){const j=a.map(n=>({id:n.id,title:n.title,lessons:n.lessons.map(C=>({id:C.id,title:C.title,content:C.content}))})),N=j.flatMap(n=>n.lessons),[x,o]=m.useState(N[0]?.id??null),f=N.findIndex(n=>n.id===x),l=n=>{const C=N[n];C&&o(C.id)},y=m.useMemo(()=>({orgId:s,courseId:t}),[s,t]);return e.jsx("div",{className:"fixed inset-0 z-50",children:e.jsx(us,{eyebrow:"Learner preview",courseTitle:d,statusBadge:e.jsx(D,{variant:"secondary",children:"Preview"}),headerAction:e.jsxs(g,{variant:"outline",onClick:u,children:[e.jsx(J,{className:"mr-1.5 h-4 w-4"})," Close preview"]}),progressPercent:0,previewMode:!0,modules:j,selectedLessonId:x,onSelectLesson:o,renderBody:n=>e.jsx(pe.Provider,{value:y,children:e.jsx(ge,{initialContent:n.content,onChange:()=>{},editable:!1},n.id)}),footer:e.jsxs(e.Fragment,{children:[e.jsxs(g,{variant:"ghost",size:"sm",disabled:f<=0,onClick:()=>l(f-1),children:[e.jsx(Be,{className:"mr-1 h-4 w-4"})," Previous"]}),e.jsxs(g,{variant:"outline",size:"sm",disabled:f<0||f>=N.length-1,onClick:()=>l(f+1),children:["Next lesson ",e.jsx(Qe,{className:"ml-1 h-4 w-4"})]})]})})})}const Rs="/scorm-host.html";function Ce({orgId:s,courseId:t,versionNo:d}){const[a,u]=m.useState(null),[j,N]=m.useState(!1),[x,o]=m.useState(""),f=m.useRef(null);m.useEffect(()=>{let v=!0;return ns(s,t,d).then(R=>{v&&(u(R),o(R.activeScoId))}).catch(()=>v&&N(!0)),()=>{v=!1}},[s,t,d]);const l=m.useMemo(()=>
1{if(!a?.launchUrl)return"";try{return new URL(a.launchUrl).origin}catch{return""}},[a?.launchUrl]),y=m.useMemo(()=>!l||!a?.servingGrant?"":`${l}/_scorm_auth?g=${encodeURIComponent(a.servingGrant)}&to=${encodeURIComponent(Rs)}`,[l,a?.servingGrant]),n=a?.scos.find(v=>v.id===x)??a?.scos[0];function C(){const v=f.current?.contentWindow;!v||!a||!n||!l||v.postMessage({type:"scorm:init",token:"",scormVersion:a.scormVersion,packageUrl:n.launchUrl,scoId:n.id,commitUrl:"",stateUrl:""},l)}const[S,M]=m.useState(!1);return m.useEffect(()=>{S&&C()},[x,a,l,S]),j?e.jsx("div",{className:"flex h-full items-center justify-center rounded-lg border border-border bg-muted/40 p-6 text-center text-sm text-muted-foreground",children:"Preview unavailable â the SCORM runtime may not be configured for this environment."}):!a||!y?e.jsx(Q,{className:"h-full w-full rounded-lg"}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[a.scos.length>1?e.jsx("div",{className:"flex flex-wrap gap-1",children:a.scos.map(v=>e.jsx(g,{variant:v.id===x?"secondary":"ghost",size:"sm",onClick:()=>o(v.id),children:e.jsx("span",{className:"max-w-48 truncate",children:v.title||`SCO ${v.order+1}`})},v.id))}):null,e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-card shadow-sm",children:e.jsx("iframe",{ref:f,title:"SCORM preview",src:y,onLoad:()=>M(!0),className:"h-full w-full border-0",allow:"fullscreen"})})]})}const _s=[{value:"Private",title:"Private",desc:"Only your organization can see this course."},{value:"All Partners",title:"All partners",desc:"Every active partner organization can discover and enroll."},{value:"Specific Partners",title:"Specific partners",desc:"Only the partner organizations you choose below."}],ue=s=>s.replace(/\s+/g,"-").toLowerCase();function zs({open:s,onOpenChange:t,orgId:d,courseId:a,initialMode:u,initialTargets:j,onSaved:N}){const[x,o]=m.useState("Private"),[f,l]=m.useState([]);m.useEffect(()=>{if(!s)return;const p=u;o(p==="All Partners"||p==="Specific Partners"?p:"Private"),l(j??[])},[s,u,j]);const{data:y,isLoading:n}=Ke({queryKey:gs.prmConnectedPartners(d),queryFn:()=>ps(d,{limit:200,filter:"(is_not_null partner_org_id)"}),enabled:s&&!!d}),S=(y?.data??[]).map(p=>({label:p.info?.name||p.partnerOrgId,value:p.partnerOrgId})),M=he({mutation:{onSuccess:p=>{p.status===200?(w.success("Sharing updated"),N?.(),t(!1)):w.error(typeof p.data=="string"?p.data:"Failed to update sharing")},onError:()=>w.error("Failed to update sharing")}}),v=x!=="Specific Partners"||f.length>0,R=()=>M.mutate({orgId:d,courseId:a,data:{sharingMode:x,targetOrgId:x==="Specific Partners"?f:void 0}});return e.jsx(ve,{open:s,onOpenChange:t,children:e.jsxs(je,{className:"sm:max-w-lg",children:[e.jsxs(Ne,{children:[e.jsx(be,{children:"Share course"}),e.jsx(ye,{children:"Choose who can discover and enroll in this course. Partners only see published courses while your partnership is active."})]}),e.jsx(vs,{value:x,onValueChange:p=>o(p),className:"gap-3",children:_s.map(p=>e.jsxs(L,{htmlFor:`share-${ue(p.value)}`,className:"flex cursor-pointer items-start gap-3 rounded-md border border-border p-3 font-normal hover:bg-muted/50",children:[e.jsx(js,{value:p.value,id:`share-${ue(p.value)}`,className:"mt-0.5"}),e.jsxs("span",{className:"space-y-0.5",children:[e.jsx("span",{className:"block text-sm font-medium text-foreground",children:p.title}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:p.desc})]})]},p.value))}),x==="Specific Partners"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(fe,{value:f,options:S,onChange:l,placeholder:n?"Loading partnersâ¦":S.length===0?"No partner organizations to share with yet":"Search partnersâ¦",disabled:n||S.length===0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Search and select the partner organizations that can discover and enroll."})]}):null,e.jsxs(xs,{children:[e.jsx(g,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(g,{onClick:R,disabled:!v||M.isPending,children:M.isPending?"Savingâ¦":"Save sharing"})]})]})})}const X="A quiz is required to publish a course that grants a certificate.";function Se(s){if(!Array.isArray(s))return!1;for(const t of s)if(t&&typeof t=="object"){const d=t;if(d.type==="quiz"||Se(d.children))return!0}return!1}function Ds(s){return s.some(t=>t.lessons.some(d=>d.isRequired&&Se(d.content)))}function B(){return crypto.randomUUID()}function As(s){return s?.archivedAt?"Archived":s?.currentPublishedVersionId?"Published":"Draft"}function Us({orgId:s,courseId:t,onReplaced:d}){const[a,u]=m.useState(!1),[j,N]=m.useState(0),x=m.useRef(null);async function o(f){if(f){if(!f.name.toLowerCase().endsWith(".zip")){w.error("A SCORM package must be a .zip file");return}u(!0);try{await as(s,t,f),w.success("Package replaced â publish to make it live"),N(l=>l+1),d()}catch(l){const y=l?.response?.data;w.error(typeof y=="string"?y:"Failed to replace package")}finally{u(!1),x.current&&(x.current.value="")}}}return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 p-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Preview"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Exactly what learners see (draft). Content is managed by the SCORM package â to change it, replace the package, then publish."})]}),e.jsx("input",{ref:x,id:"scorm-replace-input",type:"file",accept:".zip,application/zip",hidden:!0,disabled:a,onChange:f=>o(f.target.files?.[0]??null)}),a?e.jsx(g,{variant:"outline",size:"sm",className:"shrink-0",disabled:!0,children:"Replacingâ¦"}):e.jsx(g,{asChild:!0,variant:"outline",size:"sm",className:"shrink-0",children:e.jsx(L,{htmlFor:"scorm-replace-input",className:"cursor-pointer",children:"Replace package"})})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Ce,{orgId:s,courseId:t},j)})]})}function me({orgId:s,courseId:t,courseName:d,versionNo:a,onClose:u}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:d}),e.jsx(D,{variant:"secondary",children:"Preview"}),a?e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",a]}):null]}),e.jsxs(g,{variant:"outline",onClick:u,children:[e.jsx(J,{className:"mr-1.5 h-4 w-4"})," Close preview"]})]}),e.jsx("div",{className:"min-h-0 flex-1 p-4",children:e.jsx(Ce,{orgId:s,courseId:t,versionNo:a})})]})}function xe({courseName:s,external:t,onClose:d}){const a=bs(t.provider),u=t.url?.trim();return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:s}),e.jsx(D,{variant:"secondary",children:"Preview"})]}),e.jsxs(g,{variant:"outline",onClick:d,children:[e.jsx(J,{className:"mr-1.5 h-4 w-4"})," Close preview"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-6",children:e.jsxs("div",{className:"mx-auto max-w-xl rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:["External · ",a]}),e.jsx("h2",{className:"mt-1 text-lg font-semibold text-foreground",children:s}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["Progress tracked in ",a]}),e.jsxs("dl",{className:"mt-4 space-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Destination"}),e.jsx("dd",{className:"break-all font-mono text-xs text-foreground",children:u||e.jsx("span",{className:"font-sans italic text-muted-foreground",children:"Not set"})})]}),t.category?.trim()?e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Category"}),e.jsx("dd",{className:"text-foreground",children:t.category})]}):null,t.durationMin?e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Est. minutes"}),e.jsx("dd",{className:"text-foreground",children:t.durationMin}
1)]}):null]}),e.jsxs(g,{className:"mt-5",disabled:!u,onClick:()=>{u&&window.open(u,"_blank","noopener,noreferrer")},children:[e.jsx(We,{className:"mr-1.5 h-4 w-4"})," Open in ",a]}),e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:["Opening from this preview is not recorded as a learner open, and"," ",a==="external LMS"?"the LMS":a," may ask you to sign in separately."]})]})})]})}function $s({orgId:s,courseId:t,initialPreview:d,previewVersionNo:a}){const u=Ve(),j=rs(),N=a?String(a):"draft",{data:x,isLoading:o}=Ie(s,t,{version:N});m.useEffect(()=>{s&&!o&&(!x||x.status!==200)&&j({to:"/prm",search:{tab:"training"},replace:!0})},[s,o,x,j]);const f=m.useMemo(()=>({orgId:s,courseId:t}),[s,t]),[l,y]=m.useState(null),[n,C]=m.useState(""),[S,M]=m.useState("Draft"),[v,R]=m.useState(),[p,Y]=m.useState(),[U,I]=m.useState([]),[K,$]=m.useState(null),[ke,ee]=m.useState(!1),[Pe,F]=m.useState(!!d),[Le,se]=m.useState(!1),[Me,te]=m.useState(!1),q=m.useRef(null),V=m.useRef(!1),T=x?.status===200?x.data.course:void 0,k=T?.kind==="scorm",P=Ns(T?.kind),re=es(s).data,G=(re?.status===200?re.data??[]:[]).map(r=>({label:r.name??"Untitled",value:r.id??""}));m.useEffect(()=>{if(x?.status!==200)return;const r=x.data,i=r.version;if(!i||q.current===i.id)return;q.current=i.id??null;const h={continueButton:i.info?.continueButton??{label:"Continue",type:"Next",alignment:"center"},external:i.info?.external,modules:(i.info?.modules??[]).map(c=>({id:c.id??B(),title:c.title??"",position:c.position??0,lessons:(c.lessons??[]).map(b=>({id:b.id??B(),title:b.title??"",position:b.position??0,estimatedMinutes:b.estimatedMinutes,isRequired:b.
1isRequired??!0,content:b.content}))}))};y(h),C(r.course?.name??""),M(As(r.course)),R(i.versionNo),I(r.course?.certificateIds??[]),Y(i.lastUpdateTime),$(h.modules.find(c=>c.lessons.length>0)?.lessons[0]?.id??null)},[x]);const A=he({mutation:{onSuccess:r=>{r.status===200?(Y(r.data.version?.lastUpdateTime),V.current||w.success("Draft saved"),u.invalidateQueries({queryKey:[`/org/${s}/prm/course`]})):w.error(typeof r.data=="string"?r.data:"Failed to save")},onError:r=>{if(r?.status===409){const h=r?.data,c=typeof h?.message=="string"?h.message:"";w.error(c||"This draft changed elsewhere â reloading latest."),q.current=null,u.invalidateQueries({queryKey:[`/org/${s}/prm/course/${t}`]});return}w.error("Failed to save draft")}}}),H=ss({mutation:{onSuccess:r=>{r.status===200?(w.success("Course published"),q.current=null,u.invalidateQueries({queryKey:[`/org/${s}/prm/course/${t}`]}),u.invalidateQueries({queryKey:[`/org/${s}/prm/course`]})):w.error(typeof r.data=="string"?r.data:"Failed to publish")},onError:r=>{if(r?.status===409){const h=r?.data,c=typeof h?.message=="string"?h.message:"";w.error(c||X);return}w.error("Failed to publish")}}});function E(r){y(i=>i&&r(i))}function Ee(){E(r=>({...r,modules:[...r.modules,{id:B(),title:"New Module",position:r.modules.length,lessons:[]}]}))}function Oe(r){const i=B();E(h=>({...h,modules:h.modules.map(c=>c.id===r?{...c,lessons:[...c.lessons,{id:i,title:"New Lesson",position:c.lessons.length,isRequired:!0}]}:c)})),$(i)}function Re(r,i){E(h=>({...h,modules:h.modules.map(c=>c.id===r?{...c,title:i}:c)}))}function _e(r){const i=l?.modules.find(c=>c.id===r),h=i?.lessons.length??0;window.confirm(`Delete module "${i?.title||"Untitled"}"${h?` and its ${h} lesson(s)`:""}?`)&&E(c=>({...c,modules:c.modules.filter(b=>b.id!==r)}))}function ze(r,i){E(h=>({...h,modules:h.modules.map(c=>({...c,lessons:c.lessons.map(b=>b.id===r?{...b,title:i}:b)}))}))}function De(r){const i=l?.modules.flatMap(h=>h.lessons).find(h=>h.id===r);window.confirm(`Delete lesson "${i?.title||"Untitled lesson"}"?`)&&(E(h=>({...h,modules:h.modules.map(c=>({...c,lessons:c.lessons.filter(b=>b.id!==r)}))}
1)),K===r&&$(null))}function Ae(r,i){E(h=>({...h,modules:h.modules.map(c=>({...c,lessons:c.lessons.map(b=>b.id===r?{...b,content:i}:b)}))}))}function Ue(){l&&A.mutate({orgId:s,courseId:t,data:{name:n.trim()||void 0,info:k?void 0:l,lastUpdateTime:p,certificateIds:U}})}async function $e(){if(l){V.current=!0;try{await A.mutateAsync({orgId:s,courseId:t,data:{name:n.trim()||void 0,info:k?void 0:l,lastUpdateTime:p,certificateIds:U}})}catch{return}finally{V.current=!1}H.mutate({orgId:s,courseId:t,data:{action:"publish"}})}}const _=l?.modules.flatMap(r=>r.lessons).find(r=>r.id===K);if(!o&&(!x||x.status!==200))return e.jsxs("div",{className:"flex h-[calc(100vh-3.5rem)] flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"This course couldn't be opened"}),e.jsx("div",{className:"max-w-sm text-sm text-muted-foreground",children:"It may have been deleted, or you don't have access to edit it."}),e.jsx(g,{asChild:!0,variant:"outline",children:e.jsx(le,{to:"/prm",search:{tab:"training"},children:"Back to Training"})})]});if(o||!l)return e.jsxs("div",{className:"px-10 py-6",children:[e.jsx(Q,{className:"h-8 w-64"}),e.jsx(Q,{className:"mt-4 h-96 w-full"})]});if(a){const r=()=>j({to:"/prm",search:{tab:"training"}});return k?e.jsx(me,{orgId:s,courseId:t,courseName:n,versionNo:a,onClose:r}):P?e.jsx(xe,{courseName:n,external:l.external??{},onClose:r}):e.jsx(ce,{orgId:s,courseId:t,courseName:n,modules:l.modules,onClose:r})}const ne=l.modules.some(r=>r.lessons.length>0),ae=S==="Published"&&v?v-1:v,Fe=U.length>0,W=!k&&!P&&Fe&&!Ds(l.modules),ie=P&&!l.external?.url?.trim(),qe=S==="Draft";return e.jsxs("div",{className:"flex h-[calc(100vh-3.5rem)] flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{to:"/prm",search:{tab:"training"},className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"h-5 w-5"})}),e.jsx(O,{value:n,onChange:r=>C(r.target.value),placeholder:"Course name",className:"w-80 text-base font-semibold"}),e.jsx(D,{variant:S==="Published"?"default":"secondary",children:S}),ae?e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",ae]}):null,S==="Published"&&v?e.jsxs(D,{variant:"outline",className:"text-xs font-normal text-muted-foreground",children:["editing draft v",v]}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k?null:e.jsxs(g,{variant:"ghost",onClick:()=>F(!0),children:[e.jsx(He,{className:"mr-1.5 h-4 w-4"})," Preview"]}),qe?null:e.jsxs(e.Fragment,{children:[e.jsxs(g,{variant:"ghost",onClick:()=>ee(!0),children:[e.jsx(ys,{className:"mr-1.5 h-4 w-4"})," Share"]}),e.jsxs(g,{variant:"ghost",onClick:()=>te(!0),children:[e.jsx(ws,{className:"mr-1.5 h-4 w-4"})," Enrollments"]}),e.jsxs(g,{variant:"ghost",onClick:()=>se(!0),children:[e.jsx(Cs,{className:"mr-1.5 h-4 w-4"})," Certified"]})]}),e.jsx(g,{variant:"outline",onClick:Ue,disabled:A.isPending,children:A.isPending?"Savingâ¦":"Save draft"}),e.jsxs(g,{onClick:$e,disabled:H.isPending||A.isPending||!k&&!P&&!ne||ie||W,title:ie?"Add a destination link before publishing":!k&&!P&&!ne?"Add at least one lesson before publishing":W?X:void 0,children:[e.jsx(Ss,{className:"mr-1.5 h-4 w-4"}),H.isPending?"Publishingâ¦":"Publish"]})]})]}),e.jsxs("div",{className:"border-b border-border px-6 py-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs(L,{className:"flex items-center gap-1.5 whitespace-nowrap text-sm text-foreground",children:[e.jsx(Z,{className:"h-4 w-4 text-muted-foreground"}),"Certificate(s) granted on completion"]}),e.jsx("div",{className:"min-w-0 flex-1 sm:max-w-md",children:e.jsx(fe,{value:U,options:G,onChange:I,placeholder:G.length===0?"No certificates defined yet":"Select certificatesâ¦",disabled:G.length===0})})]}),W?e.jsx("p",{className:"mt-2 text-xs text-destructive",children:X}):null]}),P?e.jsx(Fs,{orgId:s,value:l.external??{},onChange:r=>y(i=>i&&{...i,external:r})}):k?e.jsx(Us,{orgId:s,courseId:t,onReplaced:()=>u.invalidateQueries({queryKey:[`/org/${s}/prm/course/${t}`]})}):e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsxs("div",{className:"w-72 shrink-0 overflow-y-auto border-r border-border p-3",children:[l.modules.map(r=>e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{value:r.title,onChange:i=>Re(r.id,i.target.value),className:"h-8 text-sm font-medium"}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>_e(r.id),children:e.jsx(oe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-1 space-y-1 pl-2",children:[r.lessons.map(i=>e.jsxs("div",{className:`flex items-center gap-1 rounded px-2 py-1 ${K===i.id?"bg-muted":"hover:bg-muted/50"}`,children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>$(i.id),className:"h-auto flex-1 justify-start truncate px-2 py-1 text-left text-sm font-normal text-foreground",children:i.title||"Untitled lesson"}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>De(i.id),children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]},i.id)),e.jsxs(g,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>Oe(r.id),children:[e.jsx(ks,{className:"mr-1.5 h-4 w-4"})," Add lesson"]})]})]},r.id)),e.jsxs(g,{variant:"outline",size:"sm",className:"w-full",onClick:Ee,children:[e.jsx(Ps,{className:"mr-1.5 h-4 w-4"})," Add module"]})]}),e.jsx("div",{className:"min-w-0 flex-1 overflow-y-auto p-6",children:_?e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsx(O,{value:_.title,onChange:r=>ze(_.id,r.target.value),placeholder:"Lesson title",className:"mb-4 border-0 px-0 text-2xl font-semibold focus-visible:ring-0"}),e.jsx(pe.Provider,{value:f,children:e.jsx(ge,{initialContent:_.content,onChange:r=>Ae(_.id,r)},_.id)})]}):e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select or add a lesson to start authoring."})})]}),e.jsx(zs,{open:ke,onOpenChange:ee,orgId:s,courseId:t,initialMode:T?.sharingMode,initialTargets:T?.targetOrgId,onSaved:()=>
1{u.invalidateQueries({queryKey:[`/org/${s}/prm/course/${t}`]}),u.invalidateQueries({queryKey:[`/org/${s}/prm/course`]})}}),e.jsx(fs,{open:Me,onOpenChange:te,orgId:s,courseId:t,courseName:n,course:{kind:P?"external":k?"scorm":void 0,externalProvider:l.external?.provider,lessonCount:l.modules.reduce((r,i)=>r+i.lessons.length,0)},showLearnerOrg:!0}),e.jsx(Os,{open:Le,onOpenChange:se,orgId:s,courseId:t,courseName:n}),Pe?k?e.jsx(me,{orgId:s,courseId:t,courseName:n,onClose:()=>F(!1)}):P?e.jsx(xe,{courseName:n,external:l.external??{},onClose:()=>F(!1)}):e.jsx(ce,{orgId:s,courseId:t,courseName:n,modules:l.modules,onClose:()=>F(!1)}):null]})}function Fs({orgId:s,value:t,onChange:d}){const a=o=>d({...t,...o}),j=ts(s,{query:{retry:!1,staleTime:3e5}}).data?.data,N=Array.isArray(j)?j:[],x=!!t.externalCourseId?.trim();return e.jsxs("div",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"External course"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The content lives in your LMS. Suger records who opened it and when â not their progress or completion â so this course never shows a completion percentage."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"external-destination",children:"Destination link"}),e.jsx(O,{id:"external-destination",value:t.url??"",placeholder:"https://partnertraining.example.com/page/onboarding",onChange:o=>a({url:o.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Where the learner lands. Must be a full https:// address. Changing it applies to the next published version â learners already enrolled keep the link they started with."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(L,{htmlFor:"external-course-link",children:["Course in your LMS",x?null:e.jsx("span",{className:"ml-2 rounded border border-warning/40 bg-warning/5 px-1.5 py-0.5 text-[10px] font-normal text-warning",children:"Not linked"})]}),N.length>0?e.jsxs(is,{value:t.externalCourseId??"",onValueChange:o=>a({externalCourseId:o,externalCourseGroupId:N.find(f=>f.id===o)?.groupId??""}),children:[e.jsx(os,{id:"external-course-link",children:e.jsx(ls,{placeholder:"Link it so completions sync back"})}),e.jsx(ds,{children:N.map(o=>e.jsx(cs,{value:o.id??"",children:o.title??o.id},o.id))})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect your LMS under Settings â Partner â Training / LMS to pick the course this mirrors."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x?"Completions for this course flow back from your LMS. Changing the link applies to the next published version.":"Until this is linked, the course reports zero completions no matter who finishes it in your LMS."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"external-lms-name",children:"LMS"}),e.jsx(O,{id:"external-lms-name",value:t.provider??"",placeholder:"Skilljar",onChange:o=>a({provider:o.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"external-cat",children:"Category"}),e.jsx(O,{id:"external-cat",value:t.category??"",placeholder:"Onboarding",onChange:o=>a({category:o.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"external-dur",children:"Est. minutes"}),e.jsx(O,{id:"external-dur",type:"number",min:1,value:t.durationMin??"",onChange:o=>{const f=Number.parseInt(o.target.value,10);a({durationMin:Number.isFinite(f)&&f>0?f:void 0})}})]})]})]})}function lr(){const{courseId:s}=Ze({strict:!1}),{preview:t,version:d}=Je({strict:!1}),a=Xe(u=>u.currentOrganization?.id??"");return e.jsx($s,{orgId:a,courseId:s,initialPreview:t,previewVersionNo:d})}export{lr as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.