import{__awaiter as e,__generator as t,__assign as r}from"tslib";import{jsx as i,jsxs as n,Fragment as o}from"react/jsx-runtime";import{useMemo as l,useCallback as a}from"react";import{Loader2 as s,Lock as u}from"lucide-react";import{useLearningTemplateStore as d}from"../store/useLearningTemplateStore.js";import{findNodeById as c}from"../utils/treeUtils.js";import m from"./RuleHeader.js";import f from"../components/EmptyLearningState.js";import p from"./RuleTierList.js";import{getRuleOverrideHistory as g}from"../apis/scopeApis.js";import{usePermissionsStore as h}from"../store/usePermissionsStore.js";import{dt as v}from"../store/useLMSConfigStore.js";var S=function(S){var y,x=S.onAddRule,R=S.onDeleteRule,b=S.onEditRule,D=S.onEditVariant,E=S.onDeleteVariant,j=S.onExportRule,C=S.isExporting,T=S.emptyStateTitle,L=void 0===T?v("emptyStateLearning.title","No learnings have been added !"):T,w=S.emptyStateDesc,I=void 0===w?v("emptyStateLearning.desc","Start by adding learnings that should apply across all stations."):w,N=S.emptyStateButtonText,A=void 0===N?v("emptyStateLearning.createNewLearning","Create New Learning"):N,V=S.onToggleSuccess,B=S.onReorderRules,F=S.onRefreshRuleSets,G=S.setDeleteConfirmationUsedFor,H=S.onCopyToTier,z=d(function(e){return e.currentRules}),k=d(function(e){return e.toggleRuleTier}),U=d(function(e){return e.scopeTreeData}),W=d(function(e){return e.selectedRuleSetId}),M=d(function(e){return e.createdVariantInfo}),O=d(function(e){return e.urlVariantId}),P=h(function(e){return e.isLoading}),_=h(function(e){return e.hasPermission}),Y=W?c((null==U?void 0:U.data)||null,W):null,q=null==Y?void 0:Y.id,J="GLOBAL"===(null==Y?void 0:Y.type)||"Global"===(null==Y?void 0:Y.name),K=Y?{ruleSetId:Y.id,ruleSetName:Y.name,ruleSetDesc:"",ruleCount:null===(y=null==Y?void 0:Y.metrics)||void 0===y?void 0:y.learningsCount}:void 0,Q=_("ilotj.rule.create",q)||_("ilotj.rule.variant.create",q),X=_("ilotj.rule.view",q),Z=l(function(){var e=new Map;return M&&M.forEach(function(t){t.variants.forEach(function(t){return e.set(t.id,t.action)})}),O&&e.set(O,"existing"),e.size>0?e:void 0},[M,O]),$=l(function(){if(M&&z){var e={tier1:"1",tier2:"2",tier_1:"1",tier_2:"2"},t={};return z.forEach(function(e){t[e.id]=e.name}),M.map(function(r){return t[e[r.tierName]]}).filter(Boolean)}},[M,z]),ee=a(function(r,i){return e(void 0,void 0,void 0,function(){var e,r;return t(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,g(i||"")];case 1:return(e=t.sent())&&e.data?[2,e.data]:[2,null];case 2:throw r=t.sent(),console.error("Failed to fetch override history",r),r;case 3:return[2]}})})},[]);return P?i("div",r({style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center",backgroundColor:"#f9fafb",fontFamily:"Helvetica, Arial, sans-serif"}},{children:n("div",r({style:{display:"flex",flexDirection:"column",alignItems:"center",color:"#4b5563"}},{children:[i(s,{style:{marginBottom:"1rem",height:"3rem",width:"3rem",color:"#007aff",animation:"spin 1s linear infinite"}}),i("p",r({style:{fontSize:"1rem",fontWeight:500,color:"#4b5563"}},{children:"Loading your permissions…"}))]}))})):X?z&&0!==(null==z?void 0:z.length)?n(o,{children:[i(m,{onAddRule:x,onExport:j,isExporting:C,ruleSetName:null==K?void 0:K.ruleSetName,ruleSetDescription:null==K?void 0:K.ruleSetDesc,isGlobal:J,ruleSetId:q}),i(p,{tiers:z,ruleSetId:(null==K?void 0:K.ruleSetId)||"",onToggleTier:k,onDeleteRule:R,isGlobalScope:J,onFetchOverrideHistory:ee,onEditRule:b,onEditVariant:D,onDeleteVariant:E,highlightedVariants:Z,highlightedTierNames:$,onToggleSuccess:V,onReorderRules:B,onRefreshRuleSets:F,setDeleteConfirmationUsedFor:G,onCopyToTier:H})]}):n(o,{children:[i(m,{onAddRule:x,onExport:j,isExporting:C,ruleSetName:null==K?void 0:K.ruleSetName,ruleSetDescription:null==K?void 0:K.ruleSetDesc,isGlobal:J}),i(f,{onCreate:x,title:L,desc:I,button:A,canCreateRule:Q})]}):n(o,{children:[i(m,{onAddRule:x,onExport:j,isExporting:C,ruleSetName:null==K?void 0:K.ruleSetName,ruleSetDescription:null==K?void 0:K.ruleSetDesc,isGlobal:J,ruleSetId:q}),n("div",r({style:{display:"flex",height:"80vh",width:"100%",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2rem",textAlign:"center",backgroundColor:"#f0f2f5",fontFamily:"Helvetica, Arial, sans-serif"}},{children:[i("div",r({style:{marginBottom:"1.5rem",height:"4rem",width:"4rem",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",background:"linear-gradient(145deg, #e0e0e0, #ffffff)",boxShadow:"4px 4px 12px rgba(0,0,0,0.05), -4px -4px 12px rgba(255,255,255,0.7)"}},{children:i(u,{style:{height:"2rem",width:"2rem",color:"#8e8e93"}})})),i("h3",r({style:{fontSize:"1.25rem",fontWeight:600,color:"#1c1c1e"}},{children:"Access Denied"})),i("p",r({style:{maxWidth:"22rem",fontSize:"1rem",color:"#636366",lineHeight:1.6,marginBottom:"1rem"}},{children:"You do not have permission to view learnings for this scope."}))]}))]})};export{S as default};
//# sourceMappingURL=ContentLogic.js.map
