@e-llm-studio/instant-learning 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),r=require("react"),o=require("@mui/material"),t=require("lucide-react"),i=require("primereact/toast"),s=require("uuid"),a=require("../../apis/scopeApis.js"),l=require("./StationAutocomplete.js"),u=require("../CardSkeleton.js"),c=require("./OnboardingLoader.js"),d=require("./TemplateCard.js"),p=require("../../styles/StationOnboardModal.module.css.js"),x=require("./InputField.js"),g=require("../../store/useAuthStore.js"),f=require("../../store/useConfigStore.js"),h=require("../../store/useLearningTemplateStore.js"),_=require("../../config.js"),m=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],S=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],v=[{label:"None",value:"None"},{label:"Distribute spots evenly across all breaks in the hour",value:"Distribute spots evenly across all breaks in the hour"}];exports.default=function(y){var b,j=y.isOpen,w=y.onClose,C=y.onBoardStation,T=y.app_integration_id,B=y.token,F=r.useState(null),E=F[0],O=F[1],k=r.useState([]),M=k[0],A=k[1],N=r.useState(0),D=N[0],z=N[1],R=r.useState(!0),q=R[0],I=R[1],L=r.useState(!1),P=L[0],W=L[1],G=r.useState([]),Y=G[0],U=G[1],H=r.useState(""),K=H[0],X=H[1],J=r.useState(""),Q=J[0],V=J[1],Z=r.useState(!1),$=Z[0],ee=Z[1],ne=r.useState(!1),re=ne[0],oe=ne[1],te=r.useState(null),ie=te[0],se=te[1],ae=r.useState(null);ae[0],ae[1];var le=r.useState(!1),ue=le[0],ce=le[1],de=r.useState(0),pe=de[0],xe=de[1],ge=r.useState(""),fe=ge[0],he=ge[1],_e=g.default().user,me=r.useRef(null),Se=r.useRef(null),ve=r.useRef(null),ye=r.useRef(null);f.useConfigStore().configuration;var be=h.useLearningTemplateStore(function(e){return e.stationNameParam}),je=r.useState({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),we=je[0],Ce=je[1],Te=function(e,n){return e.find(function(e){return e.value===n})||null},Be=r.useMemo(function(){return M.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[M]),Fe=r.useMemo(function(){var e,n,r;if(!we.genre)return null;var o=M.find(function(e){return e.scope_name===we.genre});return o?{id:o.id,title:o.scope_name||"Unnamed Template",description:(null===(e=o.description)||void 0===e?void 0:e.trim())||"No description available.",inheritedText:(null===(n=o.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:o.rules_count||0,tiersCount:o.tier_count||0,isCopy:null!==(r=o.is_copy)&&void 0!==r&&r}:null},[we.genre,M]);r.useEffect(function(){return function(){ve.current&&clearTimeout(ve.current)}},[]);var Ee=function(n){return e.__awaiter(void 0,void 0,void 0,function(){var r,o,t;return e.__generator(this,function(i){switch(i.label){case 0:if(P)return[2];W(!0),i.label=1;case 1:return i.trys.push([1,3,4,5]),[4,a.retrieveGenreScopes({limit:"20",offset:String(n)})];case 2:return"success"===(null==(r=i.sent())?void 0:r.status)&&Array.isArray(null==r?void 0:r.data)?(o=r.data,A(function(r){if(0===n)return o;var t=new Set(r.map(function(e){return e.id})),i=o.filter(function(e){return!t.has(e.id)});return e.__spreadArray(e.__spreadArray([],r,!0),i,!0)}),o.length<20?I(!1):I(!0),z(n+20)):I(!1),[3,5];case 3:return t=i.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",t),I(!1),[3,5];case 4:return W(!1),[7];case 5:return[2]}})})};r.useEffect(function(){if(j&&(A([]),z(0),I(!0),Ee(0),be)){he(be);e.__awaiter(void 0,void 0,void 0,function(){var n,r,o;return e.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,a.fetchStationsByKeyword(be,!0)];case 1:return!0===(null==(n=e.sent())?void 0:n.success)&&Array.isArray(null==n?void 0:n.data)&&(r=n.data.find(function(e){var n;return(null===(n=e.station_name)||void 0===n?void 0:n.toLowerCase())===be.toLowerCase()&&!e.ruleset_id}),r&&O(r)),[3,3];case 2:return o=e.sent(),console.error("[StationOnboard] Error auto-selecting station:",o),[3,3];case 3:return[2]}})})}},[j,be]);r.useEffect(function(){Ce(E?function(n){var r;return e.__assign(e.__assign({},n),{region:null!==(r=E.market)&&void 0!==r?r:""})}:{region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""})},[E]),r.useEffect(function(){var e=setTimeout(function(){V(K)},500);return function(){return clearTimeout(e)}},[K]),r.useEffect(function(){e.__awaiter(void 0,void 0,void 0,function(){var n,r,o,t;return e.__generator(this,function(e){switch(e.label){case 0:if(!Q.trim())return U([]),[2];ee(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,a.searchScopes({search_string:Q.trim()})];case 2:return"success"===(null==(n=e.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(r=n.data.filter(function(e){var n,r=null!==(n=e.inheritance)&&void 0!==n?n:[],o=r.indexOf(e.scope_name);return!(o<=0)&&r[o-1]===we.genre}),o=r.map(function(e){var n,r,o;return{id:e.id,title:e.scope_name||"Unnamed Template",description:(null===(n=e.description)||void 0===n?void 0:n.trim())||"No description available.",inheritedText:(null===(r=e.inheritance)||void 0===r?void 0:r[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(o=e.is_copy)&&void 0!==o&&o}}),U(o)):U([]),[3,5];case 3:return t=e.sent(),console.error("[StationOnboard] Error searching scopes:",t),U([]),[3,5];case 4:return ee(!1),[7];case 5:return[2]}})})},[Q,we.genre]),r.useEffect(function(){!Q.trim()&&Fe&&se(Fe.id)},[Q,Fe]);var Oe=function(){setTimeout(function(){ye.current&&ye.current.scrollTo({top:ye.current.scrollHeight,behavior:"smooth"})},100)},ke=function(){he(""),O(null),Ce({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),U([]),X(""),se(null),w()},Me=function(n,r){var o;if("primeTime"!==n){var t=null!==(o=null==r?void 0:r.value)&&void 0!==o?o:"";Ce(function(r){var o;return e.__assign(e.__assign({},r),((o={})[n]=String(t),o))}),"genre"===n&&(oe(!0),ve.current&&clearTimeout(ve.current),ve.current=setTimeout(function(){var e=M.find(function(e){return e.scope_name===t});se(e?e.id:null),oe(!1)},800))}else{var i=(null==r?void 0:r.value)?String(r.value):"";Ce(function(n){return e.__assign(e.__assign({},n),{primeTime:i?[i]:[]})})}},Ae=Boolean(E&&we.region&&we.primeTime.length>0&&we.genre);return n.jsxs(o.Dialog,e.__assign({open:j,onClose:ke,maxWidth:!1,disableEscapeKeyDown:!0,PaperProps:{sx:{width:"90vw",height:"90vh",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"sans-serif"}}},{children:[n.jsx(i.Toast,{ref:me}),n.jsxs(o.Box,e.__assign({sx:{p:"20px 20px 20px 27px",borderBottom:"1px solid #F0F2F5",display:"flex",justifyContent:"space-between",alignItems:"center",bgcolor:"#fff"}},{children:[n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),n.jsx(o.IconButton,e.__assign({onClick:ke,disabled:ue,sx:{color:"#19213D"}},{children:n.jsx(t.X,{size:24})}))]})),n.jsxs(o.DialogContent,e.__assign({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[n.jsx(c.default,{isLoading:ue,currentStep:pe,onComplete:function(){ce(!1);var e=Se.current;ke(),C(e||void 0),Se.current=null}}),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[n.jsxs(o.Box,e.__assign({ref:ye,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[n.jsxs(o.Box,e.__assign({className:p.default.formGroup},{children:[n.jsxs("label",e.__assign({className:p.default.label},{children:[n.jsx("span",e.__assign({className:p.default.asterisk},{children:"*"})),"Station Name/Call Letters"]})),n.jsx(l.default,{value:fe,onChange:he,onStationSelect:function(e){return O(e)}})]})),n.jsx(x.default,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:we.region||void 0,isSearchable:!1}),n.jsx(x.default,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:m,value:Te(m,(null===(b=we.primeTime)||void 0===b?void 0:b[0])||""),onOptionChange:function(e){return Me("primeTime",e)},isSearchable:!1}),n.jsx(o.Box,e.__assign({onClick:Oe,sx:{width:"100%"}},{children:n.jsx(x.default,{label:"Station Sellout Type",placeholder:"None",options:S,value:Te(S,we.type),onOptionChange:function(n){Me("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Ce(function(n){return e.__assign(e.__assign({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===we.type&&n.jsx(o.Box,e.__assign({onClick:Oe,sx:{width:"100%"}},{children:n.jsx(x.default,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:v,value:Te(v,we.lowSelloutConfig),onOptionChange:function(e){return Me("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),n.jsxs(o.Box,e.__assign({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:[n.jsxs(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:[n.jsx("span",e.__assign({style:{color:"#E53E3E",marginRight:"2px"}},{children:"*"})),"Select a scope for your station"]})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:"16px"}},{children:"Your station will inherit the rules from the selected scope."})),n.jsx(o.Box,e.__assign({sx:{mb:2}},{children:n.jsx(x.default,{required:!0,label:"",placeholder:"Select Genre",options:Be,value:Te(Be,we.genre),onOptionChange:function(e){return Me("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!P&&q&&Ee(D)},isLoadingOptions:P,hasMoreOptions:q})})),n.jsx(o.Box,e.__assign({sx:{mb:3}},{children:re?n.jsx(u.default,{}):Fe?n.jsxs(o.Box,e.__assign({sx:{border:"1.5px solid #2563EB",borderRadius:"10px",p:"14px 16px",bgcolor:"#EFF6FF",display:"flex",alignItems:"flex-start",gap:"12px"}},{children:[n.jsx(o.Box,e.__assign({sx:{width:36,height:36,borderRadius:"8px",bgcolor:"#DBEAFE",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0}},{children:n.jsxs("svg",e.__assign({width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[n.jsx("circle",{cx:"12",cy:"12",r:"2"}),n.jsx("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]}))})),n.jsxs(o.Box,e.__assign({sx:{flex:1,minWidth:0}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.875rem",fontWeight:600,color:"#1E3A5F",mb:"2px"}},{children:Fe.title})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#2563EB",mb:"8px"}},{children:Fe.description})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"}},{children:[Fe.inheritedText&&n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px",display:"inline-flex",alignItems:"center",gap:"4px"}},{children:[n.jsxs("svg",e.__assign({width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("path",{d:"M21 3L9 15"}),n.jsx("path",{d:"M3 21l6-6"})]})),Fe.inheritedText]})),n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Fe.rulesCount," rules"]})),n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Fe.tiersCount," Tiers"]}))]}))]}))]})):we.genre?null:n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.4,py:6,gap:1}},{children:[n.jsx(t.Brush,{size:28}),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#94A3B8"}},{children:"Select a genre to load the matching scope"}))]}))})),we.genre&&n.jsxs(n.Fragment,{children:[n.jsxs(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:["Select an Existing Station from the “",we.genre,"” Scope"," ",n.jsx(o.Typography,e.__assign({component:"span",sx:{fontSize:"1rem",fontWeight:400,color:"#64748B"}},{children:"(Optional)"}))]})),n.jsxs(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:"12px"}},{children:["Please select an existing station under the “",we.genre,"” category to copy its learnings."]})),n.jsxs("div",e.__assign({className:p.default.searchWrapper,style:{marginBottom:"12px"}},{children:[n.jsx("input",{type:"text",value:K,onChange:function(e){return X(e.target.value)},placeholder:"Search for station...",className:p.default.searchInput}),n.jsx(t.Search,{className:p.default.searchIcon,size:16})]})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[$&&n.jsx(u.default,{}),!$&&0===Y.length&&Q.trim()&&n.jsxs(o.Typography,e.__assign({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',Q,'".']})),!$&&Y.map(function(r){return n.jsx(d.default,e.__assign({},r,{isSelected:ie===r.id,onSelect:function(e){var n;se(ie===e?null!==(n=null==Fe?void 0:Fe.id)&&void 0!==n?n:null:e)}}),r.id)})]}))]})]}))]}))]})),n.jsxs(o.Box,e.__assign({sx:{p:"12px 20px",borderTop:"1px solid #F0F2F5",display:"flex",justifyContent:"flex-end",gap:2,bgcolor:"#fff"}},{children:[n.jsx("button",e.__assign({onClick:ke,disabled:ue,style:{padding:"7px 10px",borderRadius:"6px",color:"#64748B",border:"1px solid #E2E8F0",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px",fontWeight:500}},{children:"Cancel"})),n.jsx("button",e.__assign({onClick:function(){return e.__awaiter(void 0,void 0,void 0,function(){var n,r,o,t,i,l,u,c,d,p,x,g,f,m;return e.__generator(this,function(S){switch(S.label){case 0:if(!E||!ie)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=Fe?e.__spreadArray([Fe],Y,!0):Y,r=n.find(function(e){return e.id===ie}),null==r?void 0:r.isCopy,ce(!0),xe(0),o=null,S.label=1;case 1:return S.trys.push([1,3,,4]),t=h.useLearningTemplateStore.getState().backwardCompatibility,i=t?{topic:"customRuleSet",customScopeGroupName:_.IL_CONFIG_CONSTANTS.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:E.station_name||"New Station",parentScopeId:null,customScopeName:E.station_name||"New Station",customScopeId:s.v4(),createByName:(null==_e?void 0:_e.firstname)||"System",createdBy:(null==_e?void 0:_e.email)||"system@audacy.com",scopeType:"Station",audacyStationMetadata:{genre:we.genre,low_sellout_configurations:"Low Sellout"===we.type?we.lowSelloutConfig:null,market:E.market,primetime_windows:we.primeTime,region:E.region,station_guid:E.station_guid,station_type:""===we.type?null:we.type}}:{topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:E.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:T},console.log("[StationOnboard] Step 1: Creating rule set with payload:",i),[4,a.createRuleSet(i,B)];case 2:if(l=S.sent(),!(o=null===(x=null==l?void 0:l.data)||void 0===x?void 0:x.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",o),xe(1),[3,4];case 3:return u=S.sent(),console.error("[StationOnboard] Error creating rule set:",u),null===(g=me.current)||void 0===g||g.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ce(!1),xe(0),[2];case 4:return S.trys.push([4,6,,7]),c=null!==ie&&ie!==(null==Fe?void 0:Fe.id),d={source_scope_id:c?ie:null!==(f=null==Fe?void 0:Fe.id)&&void 0!==f?f:ie,target_scope_id:o,is_copy_parent_variant_id:c},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",d),[4,a.inheritScopeBackwardCompatible(d)];case 5:return S.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),xe(3),[3,7];case 6:return p=S.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",p),null===(m=me.current)||void 0===m||m.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ce(!1),xe(0),[2];case 7:return Se.current=o,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Ae||ue,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Ae?"#2563EB":"#BFDBFE",color:"#fff",cursor:Ae&&!ue?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:ue?n.jsxs(n.Fragment,{children:[n.jsx(o.CircularProgress,{size:16,color:"inherit"}),n.jsx("span",{children:"Onboarding..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"Onboard Station"}),n.jsx(t.ArrowRight,{size:16})]})}))]}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),r=require("react"),o=require("@mui/material"),t=require("lucide-react"),i=require("primereact/toast"),s=require("uuid"),a=require("../../apis/scopeApis.js"),l=require("./StationAutocomplete.js"),u=require("../CardSkeleton.js"),c=require("./OnboardingLoader.js"),d=require("./TemplateCard.js"),p=require("../../styles/StationOnboardModal.module.css.js"),x=require("./InputField.js"),g=require("../../store/useAuthStore.js"),f=require("../../store/useConfigStore.js"),h=require("../../store/useLearningTemplateStore.js"),_=require("../../config.js"),m=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],S=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],v=[{label:"None",value:"None"},{label:"Distribute spots evenly across all breaks in the hour",value:"Distribute spots evenly across all breaks in the hour"}];exports.default=function(y){var b,j=y.isOpen,w=y.onClose,C=y.onBoardStation,T=y.app_integration_id,B=y.token,F=r.useState(null),E=F[0],O=F[1],k=r.useState([]),M=k[0],A=k[1],N=r.useState(0),D=N[0],z=N[1],q=r.useState(!0),I=q[0],L=q[1],R=r.useState(!1),P=R[0],W=R[1],G=r.useState([]),Y=G[0],U=G[1],H=r.useState(""),K=H[0],X=H[1],J=r.useState(""),Q=J[0],V=J[1],Z=r.useState(!1),$=Z[0],ee=Z[1],ne=r.useState(!1),re=ne[0],oe=ne[1],te=r.useState(null),ie=te[0],se=te[1],ae=r.useState(null);ae[0],ae[1];var le=r.useState(!1),ue=le[0],ce=le[1],de=r.useState(0),pe=de[0],xe=de[1],ge=r.useState(""),fe=ge[0],he=ge[1],_e=g.default().user,me=r.useRef(null),Se=r.useRef(null),ve=r.useRef(null),ye=r.useRef(null);f.useConfigStore().configuration;var be=h.useLearningTemplateStore(function(e){return e.stationNameParam}),je=r.useState({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),we=je[0],Ce=je[1],Te=function(e,n){return e.find(function(e){return e.value===n})||null},Be=r.useMemo(function(){return M.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[M]),Fe=r.useMemo(function(){var e,n,r;if(!we.genre)return null;var o=M.find(function(e){return e.scope_name===we.genre});return o?{id:o.id,title:o.scope_name||"Unnamed Template",description:(null===(e=o.description)||void 0===e?void 0:e.trim())||"No description available.",inheritedText:(null===(n=o.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:o.rules_count||0,tiersCount:o.tier_count||0,isCopy:null!==(r=o.is_copy)&&void 0!==r&&r}:null},[we.genre,M]);r.useEffect(function(){return function(){ve.current&&clearTimeout(ve.current)}},[]);var Ee=function(n){return e.__awaiter(void 0,void 0,void 0,function(){var r,o,t;return e.__generator(this,function(i){switch(i.label){case 0:if(P)return[2];W(!0),i.label=1;case 1:return i.trys.push([1,3,4,5]),[4,a.retrieveGenreScopes({limit:"20",offset:String(n)})];case 2:return"success"===(null==(r=i.sent())?void 0:r.status)&&Array.isArray(null==r?void 0:r.data)?(o=r.data,A(function(r){if(0===n)return o;var t=new Set(r.map(function(e){return e.id})),i=o.filter(function(e){return!t.has(e.id)});return e.__spreadArray(e.__spreadArray([],r,!0),i,!0)}),o.length<20?L(!1):L(!0),z(n+20)):L(!1),[3,5];case 3:return t=i.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",t),L(!1),[3,5];case 4:return W(!1),[7];case 5:return[2]}})})};r.useEffect(function(){if(j&&(A([]),z(0),L(!0),Ee(0),be)){he(be);e.__awaiter(void 0,void 0,void 0,function(){var n,r,o;return e.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,a.fetchStationsByKeyword(be,!0)];case 1:return!0===(null==(n=e.sent())?void 0:n.success)&&Array.isArray(null==n?void 0:n.data)&&(r=n.data.find(function(e){var n;return(null===(n=e.station_name)||void 0===n?void 0:n.toLowerCase())===be.toLowerCase()&&!e.ruleset_id}),r&&O(r)),[3,3];case 2:return o=e.sent(),console.error("[StationOnboard] Error auto-selecting station:",o),[3,3];case 3:return[2]}})})}},[j,be]);r.useEffect(function(){Ce(E?function(n){var r;return e.__assign(e.__assign({},n),{region:null!==(r=E.market)&&void 0!==r?r:""})}:{region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""})},[E]),r.useEffect(function(){var e=setTimeout(function(){V(K)},500);return function(){return clearTimeout(e)}},[K]),r.useEffect(function(){e.__awaiter(void 0,void 0,void 0,function(){var n,r,o,t;return e.__generator(this,function(e){switch(e.label){case 0:if(!Q.trim())return U([]),[2];ee(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,a.searchScopes({search_string:Q.trim()})];case 2:return"success"===(null==(n=e.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(r=n.data.filter(function(e){var n,r=null!==(n=e.inheritance)&&void 0!==n?n:[],o=r.indexOf(e.scope_name);return!(o<=0)&&r[o-1]===we.genre}),o=r.map(function(e){var n,r,o;return{id:e.id,title:e.scope_name||"Unnamed Template",description:(null===(n=e.description)||void 0===n?void 0:n.trim())||"No description available.",inheritedText:(null===(r=e.inheritance)||void 0===r?void 0:r[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(o=e.is_copy)&&void 0!==o&&o}}),U(o)):U([]),[3,5];case 3:return t=e.sent(),console.error("[StationOnboard] Error searching scopes:",t),U([]),[3,5];case 4:return ee(!1),[7];case 5:return[2]}})})},[Q,we.genre]),r.useEffect(function(){!Q.trim()&&Fe&&se(Fe.id)},[Q,Fe]);var Oe=function(){setTimeout(function(){ye.current&&ye.current.scrollTo({top:ye.current.scrollHeight,behavior:"smooth"})},100)},ke=function(){he(""),O(null),Ce({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),U([]),X(""),se(null),w()},Me=function(n,r){var o;if("primeTime"!==n){var t=null!==(o=null==r?void 0:r.value)&&void 0!==o?o:"";Ce(function(r){var o;return e.__assign(e.__assign({},r),((o={})[n]=String(t),o))}),"genre"===n&&(oe(!0),ve.current&&clearTimeout(ve.current),ve.current=setTimeout(function(){var e=M.find(function(e){return e.scope_name===t});se(e?e.id:null),oe(!1)},800))}else{var i=(null==r?void 0:r.value)?String(r.value):"";Ce(function(n){return e.__assign(e.__assign({},n),{primeTime:i?[i]:[]})})}},Ae=Boolean(E&&we.region&&we.primeTime.length>0&&we.genre);return n.jsxs(o.Dialog,e.__assign({open:j,onClose:ke,maxWidth:!1,disableEscapeKeyDown:!0,PaperProps:{sx:{width:"90vw",height:"90vh",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"sans-serif"}}},{children:[n.jsx(i.Toast,{ref:me}),n.jsxs(o.Box,e.__assign({sx:{p:"20px 20px 20px 27px",borderBottom:"1px solid #F0F2F5",display:"flex",justifyContent:"space-between",alignItems:"center",bgcolor:"#fff"}},{children:[n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),n.jsx(o.IconButton,e.__assign({onClick:ke,disabled:ue,sx:{color:"#19213D"}},{children:n.jsx(t.X,{size:24})}))]})),n.jsxs(o.DialogContent,e.__assign({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[n.jsx(c.default,{isLoading:ue,currentStep:pe,onComplete:function(){ce(!1);var e=Se.current;ke(),C(e||void 0),Se.current=null}}),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[n.jsxs(o.Box,e.__assign({ref:ye,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[n.jsxs(o.Box,e.__assign({className:p.default.formGroup},{children:[n.jsxs("label",e.__assign({className:p.default.label},{children:[n.jsx("span",e.__assign({className:p.default.asterisk},{children:"*"})),"Station Name/Call Letters"]})),n.jsx(l.default,{value:fe,onChange:he,onStationSelect:function(e){return O(e)}})]})),n.jsx(x.default,{required:!0,disabled:!0,label:"Market",placeholder:"Select Market",value:we.region||void 0,isSearchable:!1}),n.jsx(x.default,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:m,value:Te(m,(null===(b=we.primeTime)||void 0===b?void 0:b[0])||""),onOptionChange:function(e){return Me("primeTime",e)},isSearchable:!1}),n.jsx(o.Box,e.__assign({onClick:Oe,sx:{width:"100%"}},{children:n.jsx(x.default,{label:"Station Sellout Type",placeholder:"None",options:S,value:Te(S,we.type),onOptionChange:function(n){Me("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Ce(function(n){return e.__assign(e.__assign({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===we.type&&n.jsx(o.Box,e.__assign({onClick:Oe,sx:{width:"100%"}},{children:n.jsx(x.default,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:v,value:Te(v,we.lowSelloutConfig),onOptionChange:function(e){return Me("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),n.jsxs(o.Box,e.__assign({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:[n.jsxs(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:[n.jsx("span",e.__assign({style:{color:"#E53E3E",marginRight:"2px"}},{children:"*"})),"Select a scope for your station"]})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:"16px"}},{children:"Your station will inherit the rules from the selected scope."})),n.jsx(o.Box,e.__assign({sx:{mb:2}},{children:n.jsx(x.default,{required:!0,label:"",placeholder:"Select Genre",options:Be,value:Te(Be,we.genre),onOptionChange:function(e){return Me("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!P&&I&&Ee(D)},isLoadingOptions:P,hasMoreOptions:I})})),n.jsx(o.Box,e.__assign({sx:{mb:3}},{children:re?n.jsx(u.default,{}):Fe?n.jsxs(o.Box,e.__assign({sx:{border:"1.5px solid #2563EB",borderRadius:"10px",p:"14px 16px",bgcolor:"#EFF6FF",display:"flex",alignItems:"flex-start",gap:"12px"}},{children:[n.jsx(o.Box,e.__assign({sx:{width:36,height:36,borderRadius:"8px",bgcolor:"#DBEAFE",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0}},{children:n.jsxs("svg",e.__assign({width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[n.jsx("circle",{cx:"12",cy:"12",r:"2"}),n.jsx("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]}))})),n.jsxs(o.Box,e.__assign({sx:{flex:1,minWidth:0}},{children:[n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.875rem",fontWeight:600,color:"#1E3A5F",mb:"2px"}},{children:Fe.title})),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#2563EB",mb:"8px"}},{children:Fe.description})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"}},{children:[Fe.inheritedText&&n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px",display:"inline-flex",alignItems:"center",gap:"4px"}},{children:[n.jsxs("svg",e.__assign({width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("path",{d:"M21 3L9 15"}),n.jsx("path",{d:"M3 21l6-6"})]})),Fe.inheritedText]})),n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Fe.rulesCount," rules"]})),n.jsxs(o.Box,e.__assign({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Fe.tiersCount," Tiers"]}))]}))]}))]})):we.genre?null:n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.4,py:6,gap:1}},{children:[n.jsx(t.Brush,{size:28}),n.jsx(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#94A3B8"}},{children:"Select a genre to load the matching scope"}))]}))})),we.genre&&n.jsxs(n.Fragment,{children:[n.jsxs(o.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:["Select an Existing Station from the “",we.genre,"” Scope"," ",n.jsx(o.Typography,e.__assign({component:"span",sx:{fontSize:"1rem",fontWeight:400,color:"#64748B"}},{children:"(Optional)"}))]})),n.jsxs(o.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:"12px"}},{children:["Please select an existing station under the “",we.genre,"” category to copy its learnings."]})),n.jsxs("div",e.__assign({className:p.default.searchWrapper,style:{marginBottom:"12px"}},{children:[n.jsx("input",{type:"text",value:K,onChange:function(e){return X(e.target.value)},placeholder:"Search for station...",className:p.default.searchInput}),n.jsx(t.Search,{className:p.default.searchIcon,size:16})]})),n.jsxs(o.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[$&&n.jsx(u.default,{}),!$&&0===Y.length&&Q.trim()&&n.jsxs(o.Typography,e.__assign({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',Q,'".']})),!$&&Y.map(function(r){return n.jsx(d.default,e.__assign({},r,{isSelected:ie===r.id,onSelect:function(e){var n;se(ie===e?null!==(n=null==Fe?void 0:Fe.id)&&void 0!==n?n:null:e)}}),r.id)})]}))]})]}))]}))]})),n.jsxs(o.Box,e.__assign({sx:{p:"12px 20px",borderTop:"1px solid #F0F2F5",display:"flex",justifyContent:"flex-end",gap:2,bgcolor:"#fff"}},{children:[n.jsx("button",e.__assign({onClick:ke,disabled:ue,style:{padding:"7px 10px",borderRadius:"6px",color:"#64748B",border:"1px solid #E2E8F0",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px",fontWeight:500}},{children:"Cancel"})),n.jsx("button",e.__assign({onClick:function(){return e.__awaiter(void 0,void 0,void 0,function(){var n,r,o,t,i,l,u,c,d,p,x,g,f,m;return e.__generator(this,function(S){switch(S.label){case 0:if(!E||!ie)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=Fe?e.__spreadArray([Fe],Y,!0):Y,r=n.find(function(e){return e.id===ie}),null==r?void 0:r.isCopy,ce(!0),xe(0),o=null,S.label=1;case 1:return S.trys.push([1,3,,4]),t=h.useLearningTemplateStore.getState().backwardCompatibility,i=t?{topic:"customRuleSet",customScopeGroupName:_.IL_CONFIG_CONSTANTS.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:E.station_name||"New Station",parentScopeId:null,customScopeName:E.station_name||"New Station",customScopeId:s.v4(),createByName:(null==_e?void 0:_e.firstname)||"System",createdBy:(null==_e?void 0:_e.email)||"system@audacy.com",scopeType:"Station",audacyStationMetadata:{genre:we.genre,low_sellout_configurations:"Low Sellout"===we.type?we.lowSelloutConfig:null,market:E.market,primetime_windows:we.primeTime,region:E.region,station_guid:E.station_guid,station_type:""===we.type?null:we.type}}:{topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:E.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:T},console.log("[StationOnboard] Step 1: Creating rule set with payload:",i),[4,a.createRuleSet(i,B)];case 2:if(l=S.sent(),!(o=null===(x=null==l?void 0:l.data)||void 0===x?void 0:x.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",o),xe(1),[3,4];case 3:return u=S.sent(),console.error("[StationOnboard] Error creating rule set:",u),null===(g=me.current)||void 0===g||g.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ce(!1),xe(0),[2];case 4:return S.trys.push([4,6,,7]),c=null!==ie&&ie!==(null==Fe?void 0:Fe.id),d={source_scope_id:c?ie:null!==(f=null==Fe?void 0:Fe.id)&&void 0!==f?f:ie,target_scope_id:o,is_copy_parent_variant_id:c},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",d),[4,a.inheritScopeBackwardCompatible(d)];case 5:return S.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),xe(3),[3,7];case 6:return p=S.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",p),null===(m=me.current)||void 0===m||m.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ce(!1),xe(0),[2];case 7:return Se.current=o,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Ae||ue,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Ae?"#2563EB":"#BFDBFE",color:"#fff",cursor:Ae&&!ue?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:ue?n.jsxs(n.Fragment,{children:[n.jsx(o.CircularProgress,{size:16,color:"inherit"}),n.jsx("span",{children:"Onboarding..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"Onboard Station"}),n.jsx(t.ArrowRight,{size:16})]})}))]}))]}))};
2
2
  //# sourceMappingURL=StationOnboardModal.js.map
@@ -1,2 +1,2 @@
1
- import{__assign as e,__awaiter as o,__generator as n,__spreadArray as r}from"tslib";import{jsxs as t,jsx as i,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s,useMemo as c,useEffect as u}from"react";import{Dialog as d,Box as p,Typography as f,IconButton as m,DialogContent as h,CircularProgress as g}from"@mui/material";import{X as x,Brush as v,Search as b,ArrowRight as S}from"lucide-react";import{Toast as y}from"primereact/toast";import{v4 as w}from"uuid";import{retrieveGenreScopes as C,fetchStationsByKeyword as F,searchScopes as _,inheritScopeBackwardCompatible as T,createRuleSet as E}from"../../apis/scopeApis.js";import O from"./StationAutocomplete.js";import k from"../CardSkeleton.js";import M from"./OnboardingLoader.js";import z from"./TemplateCard.js";import B from"../../styles/StationOnboardModal.module.css.js";import N from"./InputField.js";import D from"../../store/useAuthStore.js";import{useConfigStore as A}from"../../store/useConfigStore.js";import{useLearningTemplateStore as I}from"../../store/useLearningTemplateStore.js";import{IL_CONFIG_CONSTANTS as j}from"../../config.js";var L=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],R=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],W=[{label:"None",value:"None"},{label:"Distribute spots evenly across all breaks in the hour",value:"Distribute spots evenly across all breaks in the hour"}],P=function(P){var Y,q=P.isOpen,G=P.onClose,U=P.onBoardStation,H=P.app_integration_id,K=P.token,X=a(null),J=X[0],Q=X[1],V=a([]),Z=V[0],$=V[1],ee=a(0),oe=ee[0],ne=ee[1],re=a(!0),te=re[0],ie=re[1],le=a(!1),ae=le[0],se=le[1],ce=a([]),ue=ce[0],de=ce[1],pe=a(""),fe=pe[0],me=pe[1],he=a(""),ge=he[0],xe=he[1],ve=a(!1),be=ve[0],Se=ve[1],ye=a(!1),we=ye[0],Ce=ye[1],Fe=a(null),_e=Fe[0],Te=Fe[1],Ee=a(null);Ee[0],Ee[1];var Oe=a(!1),ke=Oe[0],Me=Oe[1],ze=a(0),Be=ze[0],Ne=ze[1],De=a(""),Ae=De[0],Ie=De[1],je=D().user,Le=s(null),Re=s(null),We=s(null),Pe=s(null);A().configuration;var Ye=I(function(e){return e.stationNameParam}),qe=a({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),Ge=qe[0],Ue=qe[1],He=function(e,o){return e.find(function(e){return e.value===o})||null},Ke=c(function(){return Z.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[Z]),Xe=c(function(){var e,o,n;if(!Ge.genre)return null;var r=Z.find(function(e){return e.scope_name===Ge.genre});return r?{id:r.id,title:r.scope_name||"Unnamed Template",description:(null===(e=r.description)||void 0===e?void 0:e.trim())||"No description available.",inheritedText:(null===(o=r.inheritance)||void 0===o?void 0:o[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(n=r.is_copy)&&void 0!==n&&n}:null},[Ge.genre,Z]);u(function(){return function(){We.current&&clearTimeout(We.current)}},[]);var Je=function(e){return o(void 0,void 0,void 0,function(){var o,t,i;return n(this,function(n){switch(n.label){case 0:if(ae)return[2];se(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,C({limit:"20",offset:String(e)})];case 2:return"success"===(null==(o=n.sent())?void 0:o.status)&&Array.isArray(null==o?void 0:o.data)?(t=o.data,$(function(o){if(0===e)return t;var n=new Set(o.map(function(e){return e.id})),i=t.filter(function(e){return!n.has(e.id)});return r(r([],o,!0),i,!0)}),t.length<20?ie(!1):ie(!0),ne(e+20)):ie(!1),[3,5];case 3:return i=n.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",i),ie(!1),[3,5];case 4:return se(!1),[7];case 5:return[2]}})})};u(function(){if(q&&($([]),ne(0),ie(!0),Je(0),Ye)){Ie(Ye);o(void 0,void 0,void 0,function(){var e,o,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,F(Ye,!0)];case 1:return!0===(null==(e=n.sent())?void 0:e.success)&&Array.isArray(null==e?void 0:e.data)&&(o=e.data.find(function(e){var o;return(null===(o=e.station_name)||void 0===o?void 0:o.toLowerCase())===Ye.toLowerCase()&&!e.ruleset_id}),o&&Q(o)),[3,3];case 2:return r=n.sent(),console.error("[StationOnboard] Error auto-selecting station:",r),[3,3];case 3:return[2]}})})}},[q,Ye]);u(function(){Ue(J?function(o){var n;return e(e({},o),{region:null!==(n=J.market)&&void 0!==n?n:""})}:{region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""})},[J]),u(function(){var e=setTimeout(function(){xe(fe)},500);return function(){return clearTimeout(e)}},[fe]),u(function(){o(void 0,void 0,void 0,function(){var e,o,r,t;return n(this,function(n){switch(n.label){case 0:if(!ge.trim())return de([]),[2];Se(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,_({search_string:ge.trim()})];case 2:return"success"===(null==(e=n.sent())?void 0:e.status)&&Array.isArray(null==e?void 0:e.data)?(o=e.data.filter(function(e){var o,n=null!==(o=e.inheritance)&&void 0!==o?o:[],r=n.indexOf(e.scope_name);return!(r<=0)&&n[r-1]===Ge.genre}),r=o.map(function(e){var o,n,r;return{id:e.id,title:e.scope_name||"Unnamed Template",description:(null===(o=e.description)||void 0===o?void 0:o.trim())||"No description available.",inheritedText:(null===(n=e.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),de(r)):de([]),[3,5];case 3:return t=n.sent(),console.error("[StationOnboard] Error searching scopes:",t),de([]),[3,5];case 4:return Se(!1),[7];case 5:return[2]}})})},[ge,Ge.genre]),u(function(){!ge.trim()&&Xe&&Te(Xe.id)},[ge,Xe]);var Qe=function(){setTimeout(function(){Pe.current&&Pe.current.scrollTo({top:Pe.current.scrollHeight,behavior:"smooth"})},100)},Ve=function(){Ie(""),Q(null),Ue({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),de([]),me(""),Te(null),G()},Ze=function(o,n){var r;if("primeTime"!==o){var t=null!==(r=null==n?void 0:n.value)&&void 0!==r?r:"";Ue(function(n){var r;return e(e({},n),((r={})[o]=String(t),r))}),"genre"===o&&(Ce(!0),We.current&&clearTimeout(We.current),We.current=setTimeout(function(){var e=Z.find(function(e){return e.scope_name===t});Te(e?e.id:null),Ce(!1)},800))}else{var i=(null==n?void 0:n.value)?String(n.value):"";Ue(function(o){return e(e({},o),{primeTime:i?[i]:[]})})}},$e=Boolean(J&&Ge.region&&Ge.primeTime.length>0&&Ge.genre);return t(d,e({open:q,onClose:Ve,maxWidth:!1,disableEscapeKeyDown:!0,PaperProps:{sx:{width:"90vw",height:"90vh",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"sans-serif"}}},{children:[i(y,{ref:Le}),t(p,e({sx:{p:"20px 20px 20px 27px",borderBottom:"1px solid #F0F2F5",display:"flex",justifyContent:"space-between",alignItems:"center",bgcolor:"#fff"}},{children:[t(p,e({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[i(f,e({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),i(f,e({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),i(m,e({onClick:Ve,disabled:ke,sx:{color:"#19213D"}},{children:i(x,{size:24})}))]})),t(h,e({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[i(M,{isLoading:ke,currentStep:Be,onComplete:function(){Me(!1);var e=Re.current;Ve(),U(e||void 0),Re.current=null}}),t(p,e({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[t(p,e({ref:Pe,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),i(f,e({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[t(p,e({className:B.formGroup},{children:[t("label",e({className:B.label},{children:[i("span",e({className:B.asterisk},{children:"*"})),"Station Name/Call Letters"]})),i(O,{value:Ae,onChange:Ie,onStationSelect:function(e){return Q(e)}})]})),i(N,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:Ge.region||void 0,isSearchable:!1}),i(N,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:L,value:He(L,(null===(Y=Ge.primeTime)||void 0===Y?void 0:Y[0])||""),onOptionChange:function(e){return Ze("primeTime",e)},isSearchable:!1}),i(p,e({onClick:Qe,sx:{width:"100%"}},{children:i(N,{label:"Station Sellout Type",placeholder:"None",options:R,value:He(R,Ge.type),onOptionChange:function(o){Ze("type",o),"Low Sellout"!==(null==o?void 0:o.value)&&Ue(function(o){return e(e({},o),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===Ge.type&&i(p,e({onClick:Qe,sx:{width:"100%"}},{children:i(N,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:W,value:He(W,Ge.lowSelloutConfig),onOptionChange:function(e){return Ze("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),t(p,e({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:[t(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:[i("span",e({style:{color:"#E53E3E",marginRight:"2px"}},{children:"*"})),"Select a scope for your station"]})),i(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:"16px"}},{children:"Your station will inherit the rules from the selected scope."})),i(p,e({sx:{mb:2}},{children:i(N,{required:!0,label:"",placeholder:"Select Genre",options:Ke,value:He(Ke,Ge.genre),onOptionChange:function(e){return Ze("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!ae&&te&&Je(oe)},isLoadingOptions:ae,hasMoreOptions:te})})),i(p,e({sx:{mb:3}},{children:we?i(k,{}):Xe?t(p,e({sx:{border:"1.5px solid #2563EB",borderRadius:"10px",p:"14px 16px",bgcolor:"#EFF6FF",display:"flex",alignItems:"flex-start",gap:"12px"}},{children:[i(p,e({sx:{width:36,height:36,borderRadius:"8px",bgcolor:"#DBEAFE",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0}},{children:t("svg",e({width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[i("circle",{cx:"12",cy:"12",r:"2"}),i("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]}))})),t(p,e({sx:{flex:1,minWidth:0}},{children:[i(f,e({sx:{fontSize:"0.875rem",fontWeight:600,color:"#1E3A5F",mb:"2px"}},{children:Xe.title})),i(f,e({sx:{fontSize:"0.75rem",color:"#2563EB",mb:"8px"}},{children:Xe.description})),t(p,e({sx:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"}},{children:[Xe.inheritedText&&t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px",display:"inline-flex",alignItems:"center",gap:"4px"}},{children:[t("svg",e({width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[i("polyline",{points:"15 3 21 3 21 9"}),i("path",{d:"M21 3L9 15"}),i("path",{d:"M3 21l6-6"})]})),Xe.inheritedText]})),t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Xe.rulesCount," rules"]})),t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Xe.tiersCount," Tiers"]}))]}))]}))]})):Ge.genre?null:t(p,e({sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.4,py:6,gap:1}},{children:[i(v,{size:28}),i(f,e({sx:{fontSize:"0.75rem",color:"#94A3B8"}},{children:"Select a genre to load the matching scope"}))]}))})),Ge.genre&&t(l,{children:[t(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:["Select an Existing Station from the “",Ge.genre,"” Scope"," ",i(f,e({component:"span",sx:{fontSize:"1rem",fontWeight:400,color:"#64748B"}},{children:"(Optional)"}))]})),t(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:"12px"}},{children:["Please select an existing station under the “",Ge.genre,"” category to copy its learnings."]})),t("div",e({className:B.searchWrapper,style:{marginBottom:"12px"}},{children:[i("input",{type:"text",value:fe,onChange:function(e){return me(e.target.value)},placeholder:"Search for station...",className:B.searchInput}),i(b,{className:B.searchIcon,size:16})]})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[be&&i(k,{}),!be&&0===ue.length&&ge.trim()&&t(f,e({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',ge,'".']})),!be&&ue.map(function(o){return i(z,e({},o,{isSelected:_e===o.id,onSelect:function(e){var o;Te(_e===e?null!==(o=null==Xe?void 0:Xe.id)&&void 0!==o?o:null:e)}}),o.id)})]}))]})]}))]}))]})),t(p,e({sx:{p:"12px 20px",borderTop:"1px solid #F0F2F5",display:"flex",justifyContent:"flex-end",gap:2,bgcolor:"#fff"}},{children:[i("button",e({onClick:Ve,disabled:ke,style:{padding:"7px 10px",borderRadius:"6px",color:"#64748B",border:"1px solid #E2E8F0",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px",fontWeight:500}},{children:"Cancel"})),i("button",e({onClick:function(){return o(void 0,void 0,void 0,function(){var e,o,t,i,l,a,s,c,u,d,p,f,m,h;return n(this,function(n){switch(n.label){case 0:if(!J||!_e)return console.error("[StationOnboard] Missing required data for onboarding"),[2];e=Xe?r([Xe],ue,!0):ue,o=e.find(function(e){return e.id===_e}),null==o?void 0:o.isCopy,Me(!0),Ne(0),t=null,n.label=1;case 1:return n.trys.push([1,3,,4]),i=I.getState().backwardCompatibility,l=i?{topic:"customRuleSet",customScopeGroupName:j.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:J.station_name||"New Station",parentScopeId:null,customScopeName:J.station_name||"New Station",customScopeId:w(),createByName:(null==je?void 0:je.firstname)||"System",createdBy:(null==je?void 0:je.email)||"system@audacy.com",scopeType:"Station",audacyStationMetadata:{genre:Ge.genre,low_sellout_configurations:"Low Sellout"===Ge.type?Ge.lowSelloutConfig:null,market:J.market,primetime_windows:Ge.primeTime,region:J.region,station_guid:J.station_guid,station_type:""===Ge.type?null:Ge.type}}:{topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:J.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:H},console.log("[StationOnboard] Step 1: Creating rule set with payload:",l),[4,E(l,K)];case 2:if(a=n.sent(),!(t=null===(p=null==a?void 0:a.data)||void 0===p?void 0:p.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",t),Ne(1),[3,4];case 3:return s=n.sent(),console.error("[StationOnboard] Error creating rule set:",s),null===(f=Le.current)||void 0===f||f.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),Me(!1),Ne(0),[2];case 4:return n.trys.push([4,6,,7]),c=null!==_e&&_e!==(null==Xe?void 0:Xe.id),u={source_scope_id:c?_e:null!==(m=null==Xe?void 0:Xe.id)&&void 0!==m?m:_e,target_scope_id:t,is_copy_parent_variant_id:c},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",u),[4,T(u)];case 5:return n.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),Ne(3),[3,7];case 6:return d=n.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",d),null===(h=Le.current)||void 0===h||h.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),Me(!1),Ne(0),[2];case 7:return Re.current=t,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!$e||ke,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:$e?"#2563EB":"#BFDBFE",color:"#fff",cursor:$e&&!ke?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:t(l,ke?{children:[i(g,{size:16,color:"inherit"}),i("span",{children:"Onboarding..."})]}:{children:[i("span",{children:"Onboard Station"}),i(S,{size:16})]})}))]}))]}))};export{P as default};
1
+ import{__assign as e,__awaiter as o,__generator as n,__spreadArray as r}from"tslib";import{jsxs as t,jsx as i,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s,useMemo as c,useEffect as u}from"react";import{Dialog as d,Box as p,Typography as f,IconButton as m,DialogContent as h,CircularProgress as g}from"@mui/material";import{X as x,Brush as v,Search as b,ArrowRight as S}from"lucide-react";import{Toast as y}from"primereact/toast";import{v4 as w}from"uuid";import{retrieveGenreScopes as C,fetchStationsByKeyword as F,searchScopes as _,inheritScopeBackwardCompatible as T,createRuleSet as E}from"../../apis/scopeApis.js";import O from"./StationAutocomplete.js";import k from"../CardSkeleton.js";import M from"./OnboardingLoader.js";import z from"./TemplateCard.js";import B from"../../styles/StationOnboardModal.module.css.js";import N from"./InputField.js";import D from"../../store/useAuthStore.js";import{useConfigStore as A}from"../../store/useConfigStore.js";import{useLearningTemplateStore as I}from"../../store/useLearningTemplateStore.js";import{IL_CONFIG_CONSTANTS as j}from"../../config.js";var L=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],W=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],P=[{label:"None",value:"None"},{label:"Distribute spots evenly across all breaks in the hour",value:"Distribute spots evenly across all breaks in the hour"}],R=function(R){var Y,q=R.isOpen,G=R.onClose,U=R.onBoardStation,H=R.app_integration_id,K=R.token,X=a(null),J=X[0],Q=X[1],V=a([]),Z=V[0],$=V[1],ee=a(0),oe=ee[0],ne=ee[1],re=a(!0),te=re[0],ie=re[1],le=a(!1),ae=le[0],se=le[1],ce=a([]),ue=ce[0],de=ce[1],pe=a(""),fe=pe[0],me=pe[1],he=a(""),ge=he[0],xe=he[1],ve=a(!1),be=ve[0],Se=ve[1],ye=a(!1),we=ye[0],Ce=ye[1],Fe=a(null),_e=Fe[0],Te=Fe[1],Ee=a(null);Ee[0],Ee[1];var Oe=a(!1),ke=Oe[0],Me=Oe[1],ze=a(0),Be=ze[0],Ne=ze[1],De=a(""),Ae=De[0],Ie=De[1],je=D().user,Le=s(null),We=s(null),Pe=s(null),Re=s(null);A().configuration;var Ye=I(function(e){return e.stationNameParam}),qe=a({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),Ge=qe[0],Ue=qe[1],He=function(e,o){return e.find(function(e){return e.value===o})||null},Ke=c(function(){return Z.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[Z]),Xe=c(function(){var e,o,n;if(!Ge.genre)return null;var r=Z.find(function(e){return e.scope_name===Ge.genre});return r?{id:r.id,title:r.scope_name||"Unnamed Template",description:(null===(e=r.description)||void 0===e?void 0:e.trim())||"No description available.",inheritedText:(null===(o=r.inheritance)||void 0===o?void 0:o[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(n=r.is_copy)&&void 0!==n&&n}:null},[Ge.genre,Z]);u(function(){return function(){Pe.current&&clearTimeout(Pe.current)}},[]);var Je=function(e){return o(void 0,void 0,void 0,function(){var o,t,i;return n(this,function(n){switch(n.label){case 0:if(ae)return[2];se(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,C({limit:"20",offset:String(e)})];case 2:return"success"===(null==(o=n.sent())?void 0:o.status)&&Array.isArray(null==o?void 0:o.data)?(t=o.data,$(function(o){if(0===e)return t;var n=new Set(o.map(function(e){return e.id})),i=t.filter(function(e){return!n.has(e.id)});return r(r([],o,!0),i,!0)}),t.length<20?ie(!1):ie(!0),ne(e+20)):ie(!1),[3,5];case 3:return i=n.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",i),ie(!1),[3,5];case 4:return se(!1),[7];case 5:return[2]}})})};u(function(){if(q&&($([]),ne(0),ie(!0),Je(0),Ye)){Ie(Ye);o(void 0,void 0,void 0,function(){var e,o,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,F(Ye,!0)];case 1:return!0===(null==(e=n.sent())?void 0:e.success)&&Array.isArray(null==e?void 0:e.data)&&(o=e.data.find(function(e){var o;return(null===(o=e.station_name)||void 0===o?void 0:o.toLowerCase())===Ye.toLowerCase()&&!e.ruleset_id}),o&&Q(o)),[3,3];case 2:return r=n.sent(),console.error("[StationOnboard] Error auto-selecting station:",r),[3,3];case 3:return[2]}})})}},[q,Ye]);u(function(){Ue(J?function(o){var n;return e(e({},o),{region:null!==(n=J.market)&&void 0!==n?n:""})}:{region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""})},[J]),u(function(){var e=setTimeout(function(){xe(fe)},500);return function(){return clearTimeout(e)}},[fe]),u(function(){o(void 0,void 0,void 0,function(){var e,o,r,t;return n(this,function(n){switch(n.label){case 0:if(!ge.trim())return de([]),[2];Se(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,_({search_string:ge.trim()})];case 2:return"success"===(null==(e=n.sent())?void 0:e.status)&&Array.isArray(null==e?void 0:e.data)?(o=e.data.filter(function(e){var o,n=null!==(o=e.inheritance)&&void 0!==o?o:[],r=n.indexOf(e.scope_name);return!(r<=0)&&n[r-1]===Ge.genre}),r=o.map(function(e){var o,n,r;return{id:e.id,title:e.scope_name||"Unnamed Template",description:(null===(o=e.description)||void 0===o?void 0:o.trim())||"No description available.",inheritedText:(null===(n=e.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),de(r)):de([]),[3,5];case 3:return t=n.sent(),console.error("[StationOnboard] Error searching scopes:",t),de([]),[3,5];case 4:return Se(!1),[7];case 5:return[2]}})})},[ge,Ge.genre]),u(function(){!ge.trim()&&Xe&&Te(Xe.id)},[ge,Xe]);var Qe=function(){setTimeout(function(){Re.current&&Re.current.scrollTo({top:Re.current.scrollHeight,behavior:"smooth"})},100)},Ve=function(){Ie(""),Q(null),Ue({region:"",primeTime:["06:00 AM - 7:00 PM"],genre:"Music",type:"",lowSelloutConfig:""}),de([]),me(""),Te(null),G()},Ze=function(o,n){var r;if("primeTime"!==o){var t=null!==(r=null==n?void 0:n.value)&&void 0!==r?r:"";Ue(function(n){var r;return e(e({},n),((r={})[o]=String(t),r))}),"genre"===o&&(Ce(!0),Pe.current&&clearTimeout(Pe.current),Pe.current=setTimeout(function(){var e=Z.find(function(e){return e.scope_name===t});Te(e?e.id:null),Ce(!1)},800))}else{var i=(null==n?void 0:n.value)?String(n.value):"";Ue(function(o){return e(e({},o),{primeTime:i?[i]:[]})})}},$e=Boolean(J&&Ge.region&&Ge.primeTime.length>0&&Ge.genre);return t(d,e({open:q,onClose:Ve,maxWidth:!1,disableEscapeKeyDown:!0,PaperProps:{sx:{width:"90vw",height:"90vh",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"sans-serif"}}},{children:[i(y,{ref:Le}),t(p,e({sx:{p:"20px 20px 20px 27px",borderBottom:"1px solid #F0F2F5",display:"flex",justifyContent:"space-between",alignItems:"center",bgcolor:"#fff"}},{children:[t(p,e({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[i(f,e({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),i(f,e({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),i(m,e({onClick:Ve,disabled:ke,sx:{color:"#19213D"}},{children:i(x,{size:24})}))]})),t(h,e({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[i(M,{isLoading:ke,currentStep:Be,onComplete:function(){Me(!1);var e=We.current;Ve(),U(e||void 0),We.current=null}}),t(p,e({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[t(p,e({ref:Re,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),i(f,e({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[t(p,e({className:B.formGroup},{children:[t("label",e({className:B.label},{children:[i("span",e({className:B.asterisk},{children:"*"})),"Station Name/Call Letters"]})),i(O,{value:Ae,onChange:Ie,onStationSelect:function(e){return Q(e)}})]})),i(N,{required:!0,disabled:!0,label:"Market",placeholder:"Select Market",value:Ge.region||void 0,isSearchable:!1}),i(N,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:L,value:He(L,(null===(Y=Ge.primeTime)||void 0===Y?void 0:Y[0])||""),onOptionChange:function(e){return Ze("primeTime",e)},isSearchable:!1}),i(p,e({onClick:Qe,sx:{width:"100%"}},{children:i(N,{label:"Station Sellout Type",placeholder:"None",options:W,value:He(W,Ge.type),onOptionChange:function(o){Ze("type",o),"Low Sellout"!==(null==o?void 0:o.value)&&Ue(function(o){return e(e({},o),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===Ge.type&&i(p,e({onClick:Qe,sx:{width:"100%"}},{children:i(N,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:P,value:He(P,Ge.lowSelloutConfig),onOptionChange:function(e){return Ze("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),t(p,e({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:[t(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:[i("span",e({style:{color:"#E53E3E",marginRight:"2px"}},{children:"*"})),"Select a scope for your station"]})),i(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:"16px"}},{children:"Your station will inherit the rules from the selected scope."})),i(p,e({sx:{mb:2}},{children:i(N,{required:!0,label:"",placeholder:"Select Genre",options:Ke,value:He(Ke,Ge.genre),onOptionChange:function(e){return Ze("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!ae&&te&&Je(oe)},isLoadingOptions:ae,hasMoreOptions:te})})),i(p,e({sx:{mb:3}},{children:we?i(k,{}):Xe?t(p,e({sx:{border:"1.5px solid #2563EB",borderRadius:"10px",p:"14px 16px",bgcolor:"#EFF6FF",display:"flex",alignItems:"flex-start",gap:"12px"}},{children:[i(p,e({sx:{width:36,height:36,borderRadius:"8px",bgcolor:"#DBEAFE",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0}},{children:t("svg",e({width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[i("circle",{cx:"12",cy:"12",r:"2"}),i("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]}))})),t(p,e({sx:{flex:1,minWidth:0}},{children:[i(f,e({sx:{fontSize:"0.875rem",fontWeight:600,color:"#1E3A5F",mb:"2px"}},{children:Xe.title})),i(f,e({sx:{fontSize:"0.75rem",color:"#2563EB",mb:"8px"}},{children:Xe.description})),t(p,e({sx:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"}},{children:[Xe.inheritedText&&t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px",display:"inline-flex",alignItems:"center",gap:"4px"}},{children:[t("svg",e({width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},{children:[i("polyline",{points:"15 3 21 3 21 9"}),i("path",{d:"M21 3L9 15"}),i("path",{d:"M3 21l6-6"})]})),Xe.inheritedText]})),t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Xe.rulesCount," rules"]})),t(p,e({component:"span",sx:{fontSize:"0.7rem",color:"#475569",bgcolor:"#F1F5F9",border:"1px solid #E2E8F0",borderRadius:"4px",px:"6px",py:"2px"}},{children:[Xe.tiersCount," Tiers"]}))]}))]}))]})):Ge.genre?null:t(p,e({sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.4,py:6,gap:1}},{children:[i(v,{size:28}),i(f,e({sx:{fontSize:"0.75rem",color:"#94A3B8"}},{children:"Select a genre to load the matching scope"}))]}))})),Ge.genre&&t(l,{children:[t(f,e({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:["Select an Existing Station from the “",Ge.genre,"” Scope"," ",i(f,e({component:"span",sx:{fontSize:"1rem",fontWeight:400,color:"#64748B"}},{children:"(Optional)"}))]})),t(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:"12px"}},{children:["Please select an existing station under the “",Ge.genre,"” category to copy its learnings."]})),t("div",e({className:B.searchWrapper,style:{marginBottom:"12px"}},{children:[i("input",{type:"text",value:fe,onChange:function(e){return me(e.target.value)},placeholder:"Search for station...",className:B.searchInput}),i(b,{className:B.searchIcon,size:16})]})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[be&&i(k,{}),!be&&0===ue.length&&ge.trim()&&t(f,e({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',ge,'".']})),!be&&ue.map(function(o){return i(z,e({},o,{isSelected:_e===o.id,onSelect:function(e){var o;Te(_e===e?null!==(o=null==Xe?void 0:Xe.id)&&void 0!==o?o:null:e)}}),o.id)})]}))]})]}))]}))]})),t(p,e({sx:{p:"12px 20px",borderTop:"1px solid #F0F2F5",display:"flex",justifyContent:"flex-end",gap:2,bgcolor:"#fff"}},{children:[i("button",e({onClick:Ve,disabled:ke,style:{padding:"7px 10px",borderRadius:"6px",color:"#64748B",border:"1px solid #E2E8F0",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px",fontWeight:500}},{children:"Cancel"})),i("button",e({onClick:function(){return o(void 0,void 0,void 0,function(){var e,o,t,i,l,a,s,c,u,d,p,f,m,h;return n(this,function(n){switch(n.label){case 0:if(!J||!_e)return console.error("[StationOnboard] Missing required data for onboarding"),[2];e=Xe?r([Xe],ue,!0):ue,o=e.find(function(e){return e.id===_e}),null==o?void 0:o.isCopy,Me(!0),Ne(0),t=null,n.label=1;case 1:return n.trys.push([1,3,,4]),i=I.getState().backwardCompatibility,l=i?{topic:"customRuleSet",customScopeGroupName:j.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:J.station_name||"New Station",parentScopeId:null,customScopeName:J.station_name||"New Station",customScopeId:w(),createByName:(null==je?void 0:je.firstname)||"System",createdBy:(null==je?void 0:je.email)||"system@audacy.com",scopeType:"Station",audacyStationMetadata:{genre:Ge.genre,low_sellout_configurations:"Low Sellout"===Ge.type?Ge.lowSelloutConfig:null,market:J.market,primetime_windows:Ge.primeTime,region:J.region,station_guid:J.station_guid,station_type:""===Ge.type?null:Ge.type}}:{topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:J.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:H},console.log("[StationOnboard] Step 1: Creating rule set with payload:",l),[4,E(l,K)];case 2:if(a=n.sent(),!(t=null===(p=null==a?void 0:a.data)||void 0===p?void 0:p.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",t),Ne(1),[3,4];case 3:return s=n.sent(),console.error("[StationOnboard] Error creating rule set:",s),null===(f=Le.current)||void 0===f||f.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),Me(!1),Ne(0),[2];case 4:return n.trys.push([4,6,,7]),c=null!==_e&&_e!==(null==Xe?void 0:Xe.id),u={source_scope_id:c?_e:null!==(m=null==Xe?void 0:Xe.id)&&void 0!==m?m:_e,target_scope_id:t,is_copy_parent_variant_id:c},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",u),[4,T(u)];case 5:return n.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),Ne(3),[3,7];case 6:return d=n.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",d),null===(h=Le.current)||void 0===h||h.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),Me(!1),Ne(0),[2];case 7:return We.current=t,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!$e||ke,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:$e?"#2563EB":"#BFDBFE",color:"#fff",cursor:$e&&!ke?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:t(l,ke?{children:[i(g,{size:16,color:"inherit"}),i("span",{children:"Onboarding..."})]}:{children:[i("span",{children:"Onboard Station"}),i(S,{size:16})]})}))]}))]}))};export{R as default};
2
2
  //# sourceMappingURL=StationOnboardModal.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-llm-studio/instant-learning",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "author": "Devesh Patel",
5
5
  "description": "",
6
6
  "license": "MIT",