@e-llm-studio/instant-learning 0.1.1-alpha.37 → 0.1.1-alpha.38

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"),t=require("react"),r=require("@mui/material"),o=require("lucide-react"),i=require("primereact/toast"),s=require("../../apis/scopeApis.js"),a=require("./StationAutocomplete.js"),l=require("../CardSkeleton.js"),u=require("./OnboardingLoader.js"),c=require("./TemplateCard.js"),d=require("../../styles/StationOnboardModal.module.css.js"),p=require("./InputField.js"),f=require("../../store/useAuthStore.js"),g=require("../../store/useConfigStore.js"),x=[{label:"PT - Pacific Time",value:"Pacific Time"},{label:"MT - Mountain Time",value:"Mountain Time"},{label:"CT - Central Time",value:"Central Time"},{label:"ET - Eastern Time",value:"Eastern Time"}],m=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],h=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],_=[{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(v){var S,b=v.isOpen,y=v.onClose,j=v.onBoardStation,C=v.app_integration_id,w=v.token,T=t.useState(null),O=T[0],F=T[1],B=t.useState([]),z=B[0],E=B[1],D=t.useState(0),k=D[0],q=D[1],A=t.useState(!0),M=A[0],N=A[1],R=t.useState(!1),I=R[0],P=R[1],W=t.useState([]),L=W[0],G=W[1],Y=t.useState(""),H=Y[0],U=Y[1],X=t.useState(""),Z=X[0],K=X[1],J=t.useState(!1),Q=J[0],V=J[1],$=t.useState(!1),ee=$[0],ne=$[1],te=t.useState(null),re=te[0],oe=te[1],ie=t.useState(!1),se=ie[0],ae=ie[1],le=t.useState(0),ue=le[0],ce=le[1],de=t.useState(""),pe=de[0],fe=de[1];f.default().user;var ge=t.useRef(null),xe=t.useRef(null),me=t.useRef(null),he=t.useRef(null);g.useConfigStore().configuration;var _e=t.useState({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),ve=_e[0],Se=_e[1],be=function(e,n){return e.find(function(e){return e.value===n})||null},ye=t.useMemo(function(){return z.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[z]),je=t.useMemo(function(){var e,n,t;if(!ve.genre)return null;var r=z.find(function(e){return e.scope_name===ve.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===(n=r.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(t=r.is_copy)&&void 0!==t&&t}:null},[ve.genre,z]);t.useEffect(function(){return function(){me.current&&clearTimeout(me.current)}},[]);var Ce=function(n){return e.__awaiter(void 0,void 0,void 0,function(){var t,r,o;return e.__generator(this,function(i){switch(i.label){case 0:if(I)return[2];P(!0),i.label=1;case 1:return i.trys.push([1,3,4,5]),[4,s.retrieveGenreScopes({limit:"20",offset:String(n)})];case 2:return"success"===(null==(t=i.sent())?void 0:t.status)&&Array.isArray(null==t?void 0:t.data)?(r=t.data,E(function(t){if(0===n)return r;var o=new Set(t.map(function(e){return e.id})),i=r.filter(function(e){return!o.has(e.id)});return e.__spreadArray(e.__spreadArray([],t,!0),i,!0)}),r.length<20?N(!1):N(!0),q(n+20)):N(!1),[3,5];case 3:return o=i.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",o),N(!1),[3,5];case 4:return P(!1),[7];case 5:return[2]}})})};t.useEffect(function(){b&&(E([]),q(0),N(!0),Ce(0))},[b]);t.useEffect(function(){Se(O?function(n){var t;return e.__assign(e.__assign({},n),{region:null!==(t=O.market)&&void 0!==t?t:""})}:{region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""})},[O]),t.useEffect(function(){var e=setTimeout(function(){K(H)},500);return function(){return clearTimeout(e)}},[H]),t.useEffect(function(){e.__awaiter(void 0,void 0,void 0,function(){var n,t,r;return e.__generator(this,function(e){switch(e.label){case 0:if(!Z.trim())return G([]),[2];V(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,s.searchScopes({search_string:Z})];case 2:return"success"===(null==(n=e.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(t=n.data.map(function(e){var n,t,r;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===(t=e.inheritance)||void 0===t?void 0:t[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),G(t)):G([]),[3,5];case 3:return r=e.sent(),console.error("[StationOnboard] Error searching scopes:",r),G([]),[3,5];case 4:return V(!1),[7];case 5:return[2]}})})},[Z]),t.useEffect(function(){!Z.trim()&&je&&oe(je.id)},[Z,je]);var we=function(){setTimeout(function(){he.current&&he.current.scrollTo({top:he.current.scrollHeight,behavior:"smooth"})},100)},Te=function(){fe(""),F(null),Se({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),G([]),U(""),oe(null),y()},Oe=function(n,t){var r;if("primeTime"!==n){var o=null!==(r=null==t?void 0:t.value)&&void 0!==r?r:"";Se(function(t){var r;return e.__assign(e.__assign({},t),((r={})[n]=String(o),r))}),"genre"===n&&(ne(!0),me.current&&clearTimeout(me.current),me.current=setTimeout(function(){var e=z.find(function(e){return e.scope_name===o});oe(e?e.id:null),ne(!1)},800))}else{var i=(null==t?void 0:t.value)?String(t.value):"";Se(function(n){return e.__assign(e.__assign({},n),{primeTime:i?[i]:[]})})}},Fe=Boolean(O&&ve.region&&ve.timezone&&ve.primeTime.length>0&&ve.genre);return n.jsxs(r.Dialog,e.__assign({open:b,onClose:Te,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:ge}),n.jsxs(r.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(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),n.jsx(r.IconButton,e.__assign({onClick:Te,disabled:se,sx:{color:"#19213D"}},{children:n.jsx(o.X,{size:24})}))]})),n.jsxs(r.DialogContent,e.__assign({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[n.jsx(u.default,{isLoading:se,currentStep:ue,onComplete:function(){ae(!1);var e=xe.current;Te(),j(e||void 0),xe.current=null}}),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[n.jsxs(r.Box,e.__assign({ref:he,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[n.jsxs(r.Box,e.__assign({className:d.default.formGroup},{children:[n.jsxs("label",e.__assign({className:d.default.label},{children:[n.jsx("span",e.__assign({className:d.default.asterisk},{children:"*"})),"Station Name/Call Letters"]})),n.jsx(a.default,{value:pe,onChange:fe,onStationSelect:function(e){return F(e)}})]})),n.jsx(p.default,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:ve.region||void 0,isSearchable:!1}),n.jsx(p.default,{required:!0,label:"TimeZone",placeholder:"Select TimeZone",options:x,value:be(x,ve.timezone),onOptionChange:function(e){return Oe("timezone",e)},isSearchable:!1}),n.jsx(p.default,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:m,value:be(m,(null===(S=ve.primeTime)||void 0===S?void 0:S[0])||""),onOptionChange:function(e){return Oe("primeTime",e)},isSearchable:!1}),n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{required:!0,label:"Genre",placeholder:"Select Genre",options:ye,value:be(ye,ve.genre),onOptionChange:function(e){return Oe("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!I&&M&&Ce(k)},isLoadingOptions:I,hasMoreOptions:M})})),n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{label:"Station Type",placeholder:"None",options:h,value:be(h,ve.type),onOptionChange:function(n){Oe("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Se(function(n){return e.__assign(e.__assign({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===ve.type&&n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:_,value:be(_,ve.lowSelloutConfig),onOptionChange:function(e){return Oe("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),n.jsx(r.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:ve.genre?n.jsxs(n.Fragment,{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Matching scope for your station"})),n.jsx(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2,mb:4}},{children:ee?n.jsx(l.default,{}):je?n.jsx(c.default,e.__assign({},je,{isSelected:re===je.id,onSelect:oe}),je.id):null})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Other available stations"})),n.jsxs("div",e.__assign({className:d.default.searchWrapper},{children:[n.jsx("input",{type:"text",value:H,onChange:function(e){return U(e.target.value)},placeholder:"Search for station...",className:d.default.searchInput}),n.jsx(o.Search,{className:d.default.searchIcon,size:16})]})),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[Q&&n.jsx(l.default,{}),!Q&&0===L.length&&Z.trim()&&n.jsxs(r.Typography,e.__assign({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',Z,'".']})),!Q&&L.map(function(t){return n.jsx(c.default,e.__assign({},t,{isSelected:re===t.id,onSelect:oe}),t.id)})]}))]}):n.jsxs(n.Fragment,{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Fill in the station details to load AI recommended scopes"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:3}},{children:"AI will recommend the most relevant scope for this station."})),n.jsx(r.Box,e.__assign({sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.5,py:10}},{children:n.jsx(o.BrushCleaning,{})}))]})}))]}))]})),n.jsxs(r.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:Te,disabled:se,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,t,r,o,i,a,l,u,c,d,p,f,g,x,m,h,_,v;return e.__generator(this,function(S){switch(S.label){case 0:if(!O||!re)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=je?e.__spreadArray([je],L,!0):L,t=n.find(function(e){return e.id===re}),r=null!==(g=null==t?void 0:t.isCopy)&&void 0!==g&&g,ae(!0),ce(0),o=null,S.label=1;case 1:return S.trys.push([1,3,,4]),i={topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:O.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:C},console.log("[StationOnboard] Step 1: Creating rule set with payload:",i),[4,s.createRuleSet(i,w)];case 2:if(a=S.sent(),!(o=null===(x=null==a?void 0:a.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),ce(1),[3,4];case 3:return l=S.sent(),console.error("[StationOnboard] Error creating rule set:",l),null===(m=ge.current)||void 0===m||m.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ae(!1),ce(0),[2];case 4:return S.trys.push([4,6,,11]),u={market:O.market,region:O.region,timezone:ve.timezone,primetime_windows:ve.primeTime,genre:ve.genre,station_type:""===ve.type?null:ve.type,low_sellout_configurations:"Low Sellout"===ve.type?ve.lowSelloutConfig:null,ruleset_id:o,station_guid:O.station_guid,station_name:O.station_name||"New Station"},console.log("[StationOnboard] Step 2: Updating station with payload:",u),[4,s.updateStation(u)];case 5:return S.sent(),console.log("[StationOnboard] Step 2 Complete: Station updated"),ce(2),[3,11];case 6:c=S.sent(),console.error("[StationOnboard] Error updating station, rolling back rule set:",c),409===c.status?(null===(h=ge.current)||void 0===h||h.show({severity:"error",life:2500,summary:"Error updating station",detail:"Station already Onboarded."}),F(null),oe(null),fe(""),Se(function(n){return e.__assign(e.__assign({},n),{region:""})})):null===(_=ge.current)||void 0===_||_.show({severity:"error",life:2500,summary:"Error updating station",detail:"Please try again."}),S.label=7;case 7:return S.trys.push([7,9,,10]),[4,s.deleteRuleSet(o,w)];case 8:return S.sent(),console.log("[StationOnboard] Rollback complete: Deleted rule set",o),[3,10];case 9:return d=S.sent(),console.error("[StationOnboard] Failed to rollback rule set deletion:",d),[3,10];case 10:return ae(!1),ce(0),[2];case 11:return S.trys.push([11,13,,14]),p={source_scope_id:re,target_scope_id:o,is_copy_parent_variant_id:r},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",p),[4,s.inheritScope(p)];case 12:return S.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),ce(3),[3,14];case 13:return f=S.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",f),null===(v=ge.current)||void 0===v||v.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ae(!1),ce(0),[2];case 14:return xe.current=o,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Fe||se,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Fe?"#2563EB":"#BFDBFE",color:"#fff",cursor:Fe&&!se?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:se?n.jsxs(n.Fragment,{children:[n.jsx(r.CircularProgress,{size:16,color:"inherit"}),n.jsx("span",{children:"Onboarding..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"Onboard Station"}),n.jsx(o.ArrowRight,{size:16})]})}))]}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),t=require("react"),r=require("@mui/material"),o=require("lucide-react"),i=require("primereact/toast"),s=require("../../apis/scopeApis.js"),a=require("./StationAutocomplete.js"),l=require("../CardSkeleton.js"),u=require("./OnboardingLoader.js"),c=require("./TemplateCard.js"),d=require("../../styles/StationOnboardModal.module.css.js"),p=require("./InputField.js"),f=require("../../store/useAuthStore.js"),g=require("../../store/useConfigStore.js"),x=[{label:"PT - Pacific Time",value:"Pacific Time"},{label:"MT - Mountain Time",value:"Mountain Time"},{label:"CT - Central Time",value:"Central Time"},{label:"ET - Eastern Time",value:"Eastern Time"}],m=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],h=[{label:"Low Sellout",value:"Low Sellout"},{label:"High Sellout",value:"High Sellout"},{label:"None",value:""}],_=[{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(v){var S,b=v.isOpen,y=v.onClose,j=v.onBoardStation,C=v.app_integration_id,w=v.token,T=t.useState(null),O=T[0],F=T[1],B=t.useState([]),z=B[0],E=B[1],D=t.useState(0),k=D[0],q=D[1],A=t.useState(!0),M=A[0],N=A[1],R=t.useState(!1),I=R[0],P=R[1],W=t.useState([]),L=W[0],G=W[1],Y=t.useState(""),H=Y[0],U=Y[1],X=t.useState(""),Z=X[0],K=X[1],J=t.useState(!1),Q=J[0],V=J[1],$=t.useState(!1),ee=$[0],ne=$[1],te=t.useState(null),re=te[0],oe=te[1],ie=t.useState(!1),se=ie[0],ae=ie[1],le=t.useState(0),ue=le[0],ce=le[1],de=t.useState(""),pe=de[0],fe=de[1];f.default().user;var ge=t.useRef(null),xe=t.useRef(null),me=t.useRef(null),he=t.useRef(null);g.useConfigStore().configuration;var _e=t.useState({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),ve=_e[0],Se=_e[1],be=function(e,n){return e.find(function(e){return e.value===n})||null},ye=t.useMemo(function(){return z.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[z]),je=t.useMemo(function(){var e,n,t;if(!ve.genre)return null;var r=z.find(function(e){return e.scope_name===ve.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===(n=r.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(t=r.is_copy)&&void 0!==t&&t}:null},[ve.genre,z]);t.useEffect(function(){return function(){me.current&&clearTimeout(me.current)}},[]);var Ce=function(n){return e.__awaiter(void 0,void 0,void 0,function(){var t,r,o;return e.__generator(this,function(i){switch(i.label){case 0:if(I)return[2];P(!0),i.label=1;case 1:return i.trys.push([1,3,4,5]),[4,s.retrieveGenreScopes({limit:"20",offset:String(n)})];case 2:return"success"===(null==(t=i.sent())?void 0:t.status)&&Array.isArray(null==t?void 0:t.data)?(r=t.data,E(function(t){if(0===n)return r;var o=new Set(t.map(function(e){return e.id})),i=r.filter(function(e){return!o.has(e.id)});return e.__spreadArray(e.__spreadArray([],t,!0),i,!0)}),r.length<20?N(!1):N(!0),q(n+20)):N(!1),[3,5];case 3:return o=i.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",o),N(!1),[3,5];case 4:return P(!1),[7];case 5:return[2]}})})};t.useEffect(function(){b&&(E([]),q(0),N(!0),Ce(0))},[b]);t.useEffect(function(){Se(O?function(n){var t;return e.__assign(e.__assign({},n),{region:null!==(t=O.market)&&void 0!==t?t:""})}:{region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""})},[O]),t.useEffect(function(){var e=setTimeout(function(){K(H)},500);return function(){return clearTimeout(e)}},[H]),t.useEffect(function(){e.__awaiter(void 0,void 0,void 0,function(){var n,t,r;return e.__generator(this,function(e){switch(e.label){case 0:if(!Z.trim())return G([]),[2];V(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,s.searchScopes({search_string:Z})];case 2:return"success"===(null==(n=e.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(t=n.data.map(function(e){var n,t,r;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===(t=e.inheritance)||void 0===t?void 0:t[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),G(t)):G([]),[3,5];case 3:return r=e.sent(),console.error("[StationOnboard] Error searching scopes:",r),G([]),[3,5];case 4:return V(!1),[7];case 5:return[2]}})})},[Z]),t.useEffect(function(){!Z.trim()&&je&&oe(je.id)},[Z,je]);var we=function(){setTimeout(function(){he.current&&he.current.scrollTo({top:he.current.scrollHeight,behavior:"smooth"})},100)},Te=function(){fe(""),F(null),Se({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),G([]),U(""),oe(null),y()},Oe=function(n,t){var r;if("primeTime"!==n){var o=null!==(r=null==t?void 0:t.value)&&void 0!==r?r:"";Se(function(t){var r;return e.__assign(e.__assign({},t),((r={})[n]=String(o),r))}),"genre"===n&&(ne(!0),me.current&&clearTimeout(me.current),me.current=setTimeout(function(){var e=z.find(function(e){return e.scope_name===o});oe(e?e.id:null),ne(!1)},800))}else{var i=(null==t?void 0:t.value)?String(t.value):"";Se(function(n){return e.__assign(e.__assign({},n),{primeTime:i?[i]:[]})})}},Fe=Boolean(O&&ve.region&&ve.timezone&&ve.primeTime.length>0&&ve.genre);return n.jsxs(r.Dialog,e.__assign({open:b,onClose:Te,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:ge}),n.jsxs(r.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(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#19213D"}},{children:"Onboard a Station"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:400,color:"#666F8D"}},{children:"Onboard a station to start configuring learnings."}))]})),n.jsx(r.IconButton,e.__assign({onClick:Te,disabled:se,sx:{color:"#19213D"}},{children:n.jsx(o.X,{size:24})}))]})),n.jsxs(r.DialogContent,e.__assign({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[n.jsx(u.default,{isLoading:se,currentStep:ue,onComplete:function(){ae(!1);var e=xe.current;Te(),j(e||void 0),xe.current=null}}),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[n.jsxs(r.Box,e.__assign({ref:he,sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"16px",border:"1px solid #F0F2F5",height:"100%",overflowY:"auto"}},{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:600,mb:.5,color:"#19213D"}},{children:"Basic Details"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#00000080",mb:"20px"}},{children:"Set up basic station details to unlock AI recommended scopes."})),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:"16px"}},{children:[n.jsxs(r.Box,e.__assign({className:d.default.formGroup},{children:[n.jsxs("label",e.__assign({className:d.default.label},{children:[n.jsx("span",e.__assign({className:d.default.asterisk},{children:"*"})),"Station Name/Call Letters"]})),n.jsx(a.default,{value:pe,onChange:fe,onStationSelect:function(e){return F(e)}})]})),n.jsx(p.default,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:ve.region||void 0,isSearchable:!1}),n.jsx(p.default,{required:!0,label:"TimeZone",placeholder:"Select TimeZone",options:x,value:be(x,ve.timezone),onOptionChange:function(e){return Oe("timezone",e)},isSearchable:!1}),n.jsx(p.default,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:m,value:be(m,(null===(S=ve.primeTime)||void 0===S?void 0:S[0])||""),onOptionChange:function(e){return Oe("primeTime",e)},isSearchable:!1}),n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{required:!0,label:"Genre",placeholder:"Select Genre",options:ye,value:be(ye,ve.genre),onOptionChange:function(e){return Oe("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!I&&M&&Ce(k)},isLoadingOptions:I,hasMoreOptions:M})})),n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{label:"Station Type",placeholder:"None",options:h,value:be(h,ve.type),onOptionChange:function(n){Oe("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Se(function(n){return e.__assign(e.__assign({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===ve.type&&n.jsx(r.Box,e.__assign({onClick:we,sx:{width:"100%"}},{children:n.jsx(p.default,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:_,value:be(_,ve.lowSelloutConfig),onOptionChange:function(e){return Oe("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),n.jsx(r.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:ve.genre?n.jsxs(n.Fragment,{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Matching scope for your station"})),n.jsx(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2,mb:4}},{children:ee?n.jsx(l.default,{}):je?n.jsx(c.default,e.__assign({},je,{isSelected:re===je.id,onSelect:oe}),je.id):null})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Other available stations"})),n.jsxs("div",e.__assign({className:d.default.searchWrapper},{children:[n.jsx("input",{type:"text",value:H,onChange:function(e){return U(e.target.value)},placeholder:"Search for station...",className:d.default.searchInput}),n.jsx(o.Search,{className:d.default.searchIcon,size:16})]})),n.jsxs(r.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[Q&&n.jsx(l.default,{}),!Q&&0===L.length&&Z.trim()&&n.jsxs(r.Typography,e.__assign({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',Z,'".']})),!Q&&L.map(function(t){return n.jsx(c.default,e.__assign({},t,{isSelected:re===t.id,onSelect:oe}),t.id)})]}))]}):n.jsxs(n.Fragment,{children:[n.jsx(r.Typography,e.__assign({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Fill in the station details to load AI recommended scopes"})),n.jsx(r.Typography,e.__assign({sx:{fontSize:"0.75rem",color:"#64748B",mb:3}},{children:"AI will recommend the most relevant scope for this station."})),n.jsx(r.Box,e.__assign({sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.5,py:10}},{children:n.jsx(o.Brush,{})}))]})}))]}))]})),n.jsxs(r.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:Te,disabled:se,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,t,r,o,i,a,l,u,c,d,p,f,g,x,m,h,_,v;return e.__generator(this,function(S){switch(S.label){case 0:if(!O||!re)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=je?e.__spreadArray([je],L,!0):L,t=n.find(function(e){return e.id===re}),r=null!==(g=null==t?void 0:t.isCopy)&&void 0!==g&&g,ae(!0),ce(0),o=null,S.label=1;case 1:return S.trys.push([1,3,,4]),i={topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:O.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:C},console.log("[StationOnboard] Step 1: Creating rule set with payload:",i),[4,s.createRuleSet(i,w)];case 2:if(a=S.sent(),!(o=null===(x=null==a?void 0:a.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),ce(1),[3,4];case 3:return l=S.sent(),console.error("[StationOnboard] Error creating rule set:",l),null===(m=ge.current)||void 0===m||m.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ae(!1),ce(0),[2];case 4:return S.trys.push([4,6,,11]),u={market:O.market,region:O.region,timezone:ve.timezone,primetime_windows:ve.primeTime,genre:ve.genre,station_type:""===ve.type?null:ve.type,low_sellout_configurations:"Low Sellout"===ve.type?ve.lowSelloutConfig:null,ruleset_id:o,station_guid:O.station_guid,station_name:O.station_name||"New Station"},console.log("[StationOnboard] Step 2: Updating station with payload:",u),[4,s.updateStation(u)];case 5:return S.sent(),console.log("[StationOnboard] Step 2 Complete: Station updated"),ce(2),[3,11];case 6:c=S.sent(),console.error("[StationOnboard] Error updating station, rolling back rule set:",c),409===c.status?(null===(h=ge.current)||void 0===h||h.show({severity:"error",life:2500,summary:"Error updating station",detail:"Station already Onboarded."}),F(null),oe(null),fe(""),Se(function(n){return e.__assign(e.__assign({},n),{region:""})})):null===(_=ge.current)||void 0===_||_.show({severity:"error",life:2500,summary:"Error updating station",detail:"Please try again."}),S.label=7;case 7:return S.trys.push([7,9,,10]),[4,s.deleteRuleSet(o,w)];case 8:return S.sent(),console.log("[StationOnboard] Rollback complete: Deleted rule set",o),[3,10];case 9:return d=S.sent(),console.error("[StationOnboard] Failed to rollback rule set deletion:",d),[3,10];case 10:return ae(!1),ce(0),[2];case 11:return S.trys.push([11,13,,14]),p={source_scope_id:re,target_scope_id:o,is_copy_parent_variant_id:r},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",p),[4,s.inheritScope(p)];case 12:return S.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),ce(3),[3,14];case 13:return f=S.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",f),null===(v=ge.current)||void 0===v||v.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ae(!1),ce(0),[2];case 14:return xe.current=o,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Fe||se,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Fe?"#2563EB":"#BFDBFE",color:"#fff",cursor:Fe&&!se?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:se?n.jsxs(n.Fragment,{children:[n.jsx(r.CircularProgress,{size:16,color:"inherit"}),n.jsx("span",{children:"Onboarding..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"Onboard Station"}),n.jsx(o.ArrowRight,{size:16})]})}))]}))]}))};
2
2
  //# sourceMappingURL=StationOnboardModal.js.map
@@ -1,2 +1,2 @@
1
- import{__assign as e,__awaiter as n,__generator as o,__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 v,BrushCleaning as b,Search as S,ArrowRight as x}from"lucide-react";import{Toast as y}from"primereact/toast";import{retrieveGenreScopes as C,searchScopes as w,inheritScope as T,deleteRuleSet as _,updateStation as O,createRuleSet as F}from"../../apis/scopeApis.js";import z from"./StationAutocomplete.js";import k from"../CardSkeleton.js";import D from"./OnboardingLoader.js";import E from"./TemplateCard.js";import N from"../../styles/StationOnboardModal.module.css.js";import I from"./InputField.js";import A from"../../store/useAuthStore.js";import{useConfigStore as M}from"../../store/useConfigStore.js";var j=[{label:"PT - Pacific Time",value:"Pacific Time"},{label:"MT - Mountain Time",value:"Mountain Time"},{label:"CT - Central Time",value:"Central Time"},{label:"ET - Eastern Time",value:"Eastern Time"}],P=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],B=[{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"}],L=function(L){var R,q=L.isOpen,Y=L.onClose,G=L.onBoardStation,H=L.app_integration_id,U=L.token,Z=a(null),K=Z[0],X=Z[1],J=a([]),Q=J[0],V=J[1],$=a(0),ee=$[0],ne=$[1],oe=a(!0),re=oe[0],te=oe[1],ie=a(!1),le=ie[0],ae=ie[1],se=a([]),ce=se[0],ue=se[1],de=a(""),pe=de[0],fe=de[1],me=a(""),he=me[0],ge=me[1],ve=a(!1),be=ve[0],Se=ve[1],xe=a(!1),ye=xe[0],Ce=xe[1],we=a(null),Te=we[0],_e=we[1],Oe=a(!1),Fe=Oe[0],ze=Oe[1],ke=a(0),De=ke[0],Ee=ke[1],Ne=a(""),Ie=Ne[0],Ae=Ne[1];A().user;var Me=s(null),je=s(null),Pe=s(null),Be=s(null);M().configuration;var We=a({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),Le=We[0],Re=We[1],qe=function(e,n){return e.find(function(e){return e.value===n})||null},Ye=c(function(){return Q.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[Q]),Ge=c(function(){var e,n,o;if(!Le.genre)return null;var r=Q.find(function(e){return e.scope_name===Le.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===(n=r.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(o=r.is_copy)&&void 0!==o&&o}:null},[Le.genre,Q]);u(function(){return function(){Pe.current&&clearTimeout(Pe.current)}},[]);var He=function(e){return n(void 0,void 0,void 0,function(){var n,t,i;return o(this,function(o){switch(o.label){case 0:if(le)return[2];ae(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,C({limit:"20",offset:String(e)})];case 2:return"success"===(null==(n=o.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(t=n.data,V(function(n){if(0===e)return t;var o=new Set(n.map(function(e){return e.id})),i=t.filter(function(e){return!o.has(e.id)});return r(r([],n,!0),i,!0)}),t.length<20?te(!1):te(!0),ne(e+20)):te(!1),[3,5];case 3:return i=o.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",i),te(!1),[3,5];case 4:return ae(!1),[7];case 5:return[2]}})})};u(function(){q&&(V([]),ne(0),te(!0),He(0))},[q]);u(function(){Re(K?function(n){var o;return e(e({},n),{region:null!==(o=K.market)&&void 0!==o?o:""})}:{region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""})},[K]),u(function(){var e=setTimeout(function(){ge(pe)},500);return function(){return clearTimeout(e)}},[pe]),u(function(){n(void 0,void 0,void 0,function(){var e,n,r;return o(this,function(o){switch(o.label){case 0:if(!he.trim())return ue([]),[2];Se(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,w({search_string:he})];case 2:return"success"===(null==(e=o.sent())?void 0:e.status)&&Array.isArray(null==e?void 0:e.data)?(n=e.data.map(function(e){var n,o,r;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===(o=e.inheritance)||void 0===o?void 0:o[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),ue(n)):ue([]),[3,5];case 3:return r=o.sent(),console.error("[StationOnboard] Error searching scopes:",r),ue([]),[3,5];case 4:return Se(!1),[7];case 5:return[2]}})})},[he]),u(function(){!he.trim()&&Ge&&_e(Ge.id)},[he,Ge]);var Ue=function(){setTimeout(function(){Be.current&&Be.current.scrollTo({top:Be.current.scrollHeight,behavior:"smooth"})},100)},Ze=function(){Ae(""),X(null),Re({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),ue([]),fe(""),_e(null),Y()},Ke=function(n,o){var r;if("primeTime"!==n){var t=null!==(r=null==o?void 0:o.value)&&void 0!==r?r:"";Re(function(o){var r;return e(e({},o),((r={})[n]=String(t),r))}),"genre"===n&&(Ce(!0),Pe.current&&clearTimeout(Pe.current),Pe.current=setTimeout(function(){var e=Q.find(function(e){return e.scope_name===t});_e(e?e.id:null),Ce(!1)},800))}else{var i=(null==o?void 0:o.value)?String(o.value):"";Re(function(n){return e(e({},n),{primeTime:i?[i]:[]})})}},Xe=Boolean(K&&Le.region&&Le.timezone&&Le.primeTime.length>0&&Le.genre);return t(d,e({open:q,onClose:Ze,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:Me}),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:Ze,disabled:Fe,sx:{color:"#19213D"}},{children:i(v,{size:24})}))]})),t(h,e({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[i(D,{isLoading:Fe,currentStep:De,onComplete:function(){ze(!1);var e=je.current;Ze(),G(e||void 0),je.current=null}}),t(p,e({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[t(p,e({ref:Be,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:N.formGroup},{children:[t("label",e({className:N.label},{children:[i("span",e({className:N.asterisk},{children:"*"})),"Station Name/Call Letters"]})),i(z,{value:Ie,onChange:Ae,onStationSelect:function(e){return X(e)}})]})),i(I,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:Le.region||void 0,isSearchable:!1}),i(I,{required:!0,label:"TimeZone",placeholder:"Select TimeZone",options:j,value:qe(j,Le.timezone),onOptionChange:function(e){return Ke("timezone",e)},isSearchable:!1}),i(I,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:P,value:qe(P,(null===(R=Le.primeTime)||void 0===R?void 0:R[0])||""),onOptionChange:function(e){return Ke("primeTime",e)},isSearchable:!1}),i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{required:!0,label:"Genre",placeholder:"Select Genre",options:Ye,value:qe(Ye,Le.genre),onOptionChange:function(e){return Ke("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!le&&re&&He(ee)},isLoadingOptions:le,hasMoreOptions:re})})),i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{label:"Station Type",placeholder:"None",options:B,value:qe(B,Le.type),onOptionChange:function(n){Ke("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Re(function(n){return e(e({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===Le.type&&i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:W,value:qe(W,Le.lowSelloutConfig),onOptionChange:function(e){return Ke("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),i(p,e({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:Le.genre?t(l,{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Matching scope for your station"})),i(p,e({sx:{display:"flex",flexDirection:"column",gap:2,mb:4}},{children:ye?i(k,{}):Ge?i(E,e({},Ge,{isSelected:Te===Ge.id,onSelect:_e}),Ge.id):null})),i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Other available stations"})),t("div",e({className:N.searchWrapper},{children:[i("input",{type:"text",value:pe,onChange:function(e){return fe(e.target.value)},placeholder:"Search for station...",className:N.searchInput}),i(S,{className:N.searchIcon,size:16})]})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[be&&i(k,{}),!be&&0===ce.length&&he.trim()&&t(f,e({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',he,'".']})),!be&&ce.map(function(n){return i(E,e({},n,{isSelected:Te===n.id,onSelect:_e}),n.id)})]}))]}):t(l,{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Fill in the station details to load AI recommended scopes"})),i(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:3}},{children:"AI will recommend the most relevant scope for this station."})),i(p,e({sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.5,py:10}},{children:i(b,{})}))]})}))]}))]})),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:Ze,disabled:Fe,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 n(void 0,void 0,void 0,function(){var n,t,i,l,a,s,c,u,d,p,f,m,h,g,v,b,S,x;return o(this,function(o){switch(o.label){case 0:if(!K||!Te)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=Ge?r([Ge],ce,!0):ce,t=n.find(function(e){return e.id===Te}),i=null!==(h=null==t?void 0:t.isCopy)&&void 0!==h&&h,ze(!0),Ee(0),l=null,o.label=1;case 1:return o.trys.push([1,3,,4]),a={topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:K.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:H},console.log("[StationOnboard] Step 1: Creating rule set with payload:",a),[4,F(a,U)];case 2:if(s=o.sent(),!(l=null===(g=null==s?void 0:s.data)||void 0===g?void 0:g.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",l),Ee(1),[3,4];case 3:return c=o.sent(),console.error("[StationOnboard] Error creating rule set:",c),null===(v=Me.current)||void 0===v||v.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ze(!1),Ee(0),[2];case 4:return o.trys.push([4,6,,11]),u={market:K.market,region:K.region,timezone:Le.timezone,primetime_windows:Le.primeTime,genre:Le.genre,station_type:""===Le.type?null:Le.type,low_sellout_configurations:"Low Sellout"===Le.type?Le.lowSelloutConfig:null,ruleset_id:l,station_guid:K.station_guid,station_name:K.station_name||"New Station"},console.log("[StationOnboard] Step 2: Updating station with payload:",u),[4,O(u)];case 5:return o.sent(),console.log("[StationOnboard] Step 2 Complete: Station updated"),Ee(2),[3,11];case 6:d=o.sent(),console.error("[StationOnboard] Error updating station, rolling back rule set:",d),409===d.status?(null===(b=Me.current)||void 0===b||b.show({severity:"error",life:2500,summary:"Error updating station",detail:"Station already Onboarded."}),X(null),_e(null),Ae(""),Re(function(n){return e(e({},n),{region:""})})):null===(S=Me.current)||void 0===S||S.show({severity:"error",life:2500,summary:"Error updating station",detail:"Please try again."}),o.label=7;case 7:return o.trys.push([7,9,,10]),[4,_(l,U)];case 8:return o.sent(),console.log("[StationOnboard] Rollback complete: Deleted rule set",l),[3,10];case 9:return p=o.sent(),console.error("[StationOnboard] Failed to rollback rule set deletion:",p),[3,10];case 10:return ze(!1),Ee(0),[2];case 11:return o.trys.push([11,13,,14]),f={source_scope_id:Te,target_scope_id:l,is_copy_parent_variant_id:i},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",f),[4,T(f)];case 12:return o.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),Ee(3),[3,14];case 13:return m=o.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",m),null===(x=Me.current)||void 0===x||x.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ze(!1),Ee(0),[2];case 14:return je.current=l,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Xe||Fe,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Xe?"#2563EB":"#BFDBFE",color:"#fff",cursor:Xe&&!Fe?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:t(l,Fe?{children:[i(g,{size:16,color:"inherit"}),i("span",{children:"Onboarding..."})]}:{children:[i("span",{children:"Onboard Station"}),i(x,{size:16})]})}))]}))]}))};export{L as default};
1
+ import{__assign as e,__awaiter as n,__generator as o,__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 v,Brush as b,Search as S,ArrowRight as x}from"lucide-react";import{Toast as y}from"primereact/toast";import{retrieveGenreScopes as C,searchScopes as w,inheritScope as T,deleteRuleSet as _,updateStation as O,createRuleSet as F}from"../../apis/scopeApis.js";import z from"./StationAutocomplete.js";import k from"../CardSkeleton.js";import D from"./OnboardingLoader.js";import E from"./TemplateCard.js";import N from"../../styles/StationOnboardModal.module.css.js";import I from"./InputField.js";import A from"../../store/useAuthStore.js";import{useConfigStore as M}from"../../store/useConfigStore.js";var j=[{label:"PT - Pacific Time",value:"Pacific Time"},{label:"MT - Mountain Time",value:"Mountain Time"},{label:"CT - Central Time",value:"Central Time"},{label:"ET - Eastern Time",value:"Eastern Time"}],P=[{label:"6am to 7pm",value:"06:00 AM - 7:00 PM"},{label:"5am to 7pm",value:"05:00 AM - 7:00 PM"}],B=[{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"}],L=function(L){var R,q=L.isOpen,Y=L.onClose,G=L.onBoardStation,H=L.app_integration_id,U=L.token,Z=a(null),K=Z[0],X=Z[1],J=a([]),Q=J[0],V=J[1],$=a(0),ee=$[0],ne=$[1],oe=a(!0),re=oe[0],te=oe[1],ie=a(!1),le=ie[0],ae=ie[1],se=a([]),ce=se[0],ue=se[1],de=a(""),pe=de[0],fe=de[1],me=a(""),he=me[0],ge=me[1],ve=a(!1),be=ve[0],Se=ve[1],xe=a(!1),ye=xe[0],Ce=xe[1],we=a(null),Te=we[0],_e=we[1],Oe=a(!1),Fe=Oe[0],ze=Oe[1],ke=a(0),De=ke[0],Ee=ke[1],Ne=a(""),Ie=Ne[0],Ae=Ne[1];A().user;var Me=s(null),je=s(null),Pe=s(null),Be=s(null);M().configuration;var We=a({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),Le=We[0],Re=We[1],qe=function(e,n){return e.find(function(e){return e.value===n})||null},Ye=c(function(){return Q.map(function(e){return{label:e.scope_name,value:e.scope_name}})},[Q]),Ge=c(function(){var e,n,o;if(!Le.genre)return null;var r=Q.find(function(e){return e.scope_name===Le.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===(n=r.inheritance)||void 0===n?void 0:n[0])||void 0,rulesCount:r.rules_count||0,tiersCount:r.tier_count||0,isCopy:null!==(o=r.is_copy)&&void 0!==o&&o}:null},[Le.genre,Q]);u(function(){return function(){Pe.current&&clearTimeout(Pe.current)}},[]);var He=function(e){return n(void 0,void 0,void 0,function(){var n,t,i;return o(this,function(o){switch(o.label){case 0:if(le)return[2];ae(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,C({limit:"20",offset:String(e)})];case 2:return"success"===(null==(n=o.sent())?void 0:n.status)&&Array.isArray(null==n?void 0:n.data)?(t=n.data,V(function(n){if(0===e)return t;var o=new Set(n.map(function(e){return e.id})),i=t.filter(function(e){return!o.has(e.id)});return r(r([],n,!0),i,!0)}),t.length<20?te(!1):te(!0),ne(e+20)):te(!1),[3,5];case 3:return i=o.sent(),console.error("[StationOnboard] Failed to fetch genre scopes:",i),te(!1),[3,5];case 4:return ae(!1),[7];case 5:return[2]}})})};u(function(){q&&(V([]),ne(0),te(!0),He(0))},[q]);u(function(){Re(K?function(n){var o;return e(e({},n),{region:null!==(o=K.market)&&void 0!==o?o:""})}:{region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""})},[K]),u(function(){var e=setTimeout(function(){ge(pe)},500);return function(){return clearTimeout(e)}},[pe]),u(function(){n(void 0,void 0,void 0,function(){var e,n,r;return o(this,function(o){switch(o.label){case 0:if(!he.trim())return ue([]),[2];Se(!0),o.label=1;case 1:return o.trys.push([1,3,4,5]),[4,w({search_string:he})];case 2:return"success"===(null==(e=o.sent())?void 0:e.status)&&Array.isArray(null==e?void 0:e.data)?(n=e.data.map(function(e){var n,o,r;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===(o=e.inheritance)||void 0===o?void 0:o[0])||void 0,rulesCount:e.rules_count||0,tiersCount:e.tier_count||0,isCopy:null!==(r=e.is_copy)&&void 0!==r&&r}}),ue(n)):ue([]),[3,5];case 3:return r=o.sent(),console.error("[StationOnboard] Error searching scopes:",r),ue([]),[3,5];case 4:return Se(!1),[7];case 5:return[2]}})})},[he]),u(function(){!he.trim()&&Ge&&_e(Ge.id)},[he,Ge]);var Ue=function(){setTimeout(function(){Be.current&&Be.current.scrollTo({top:Be.current.scrollHeight,behavior:"smooth"})},100)},Ze=function(){Ae(""),X(null),Re({region:"",timezone:"",primeTime:[],genre:"",type:"",lowSelloutConfig:""}),ue([]),fe(""),_e(null),Y()},Ke=function(n,o){var r;if("primeTime"!==n){var t=null!==(r=null==o?void 0:o.value)&&void 0!==r?r:"";Re(function(o){var r;return e(e({},o),((r={})[n]=String(t),r))}),"genre"===n&&(Ce(!0),Pe.current&&clearTimeout(Pe.current),Pe.current=setTimeout(function(){var e=Q.find(function(e){return e.scope_name===t});_e(e?e.id:null),Ce(!1)},800))}else{var i=(null==o?void 0:o.value)?String(o.value):"";Re(function(n){return e(e({},n),{primeTime:i?[i]:[]})})}},Xe=Boolean(K&&Le.region&&Le.timezone&&Le.primeTime.length>0&&Le.genre);return t(d,e({open:q,onClose:Ze,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:Me}),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:Ze,disabled:Fe,sx:{color:"#19213D"}},{children:i(v,{size:24})}))]})),t(h,e({sx:{p:0,bgcolor:"#F8FAFC",display:"flex",flexDirection:"row",overflow:"hidden",position:"relative"}},{children:[i(D,{isLoading:Fe,currentStep:De,onComplete:function(){ze(!1);var e=je.current;Ze(),G(e||void 0),je.current=null}}),t(p,e({sx:{display:"flex",flex:1,paddingY:"14px",paddingX:"20px",gap:3,overflowY:"hidden"}},{children:[t(p,e({ref:Be,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:N.formGroup},{children:[t("label",e({className:N.label},{children:[i("span",e({className:N.asterisk},{children:"*"})),"Station Name/Call Letters"]})),i(z,{value:Ie,onChange:Ae,onStationSelect:function(e){return X(e)}})]})),i(I,{required:!0,disabled:!0,label:"Region",placeholder:"Select Region",value:Le.region||void 0,isSearchable:!1}),i(I,{required:!0,label:"TimeZone",placeholder:"Select TimeZone",options:j,value:qe(j,Le.timezone),onOptionChange:function(e){return Ke("timezone",e)},isSearchable:!1}),i(I,{required:!0,label:"Prime Time Window",placeholder:"Select Prime Time",options:P,value:qe(P,(null===(R=Le.primeTime)||void 0===R?void 0:R[0])||""),onOptionChange:function(e){return Ke("primeTime",e)},isSearchable:!1}),i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{required:!0,label:"Genre",placeholder:"Select Genre",options:Ye,value:qe(Ye,Le.genre),onOptionChange:function(e){return Ke("genre",e)},isSearchable:!1,onMenuScrollToBottom:function(){!le&&re&&He(ee)},isLoadingOptions:le,hasMoreOptions:re})})),i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{label:"Station Type",placeholder:"None",options:B,value:qe(B,Le.type),onOptionChange:function(n){Ke("type",n),"Low Sellout"!==(null==n?void 0:n.value)&&Re(function(n){return e(e({},n),{lowSelloutConfig:""})})},isSearchable:!1})})),"Low Sellout"===Le.type&&i(p,e({onClick:Ue,sx:{width:"100%"}},{children:i(I,{label:"Low Sell Out Configurations",placeholder:"Select Configuration",options:W,value:qe(W,Le.lowSelloutConfig),onOptionChange:function(e){return Ke("lowSelloutConfig",e)},isSearchable:!1})}))]}))]})),i(p,e({sx:{flex:1,bgcolor:"#fff",p:3,borderRadius:"12px",border:"1px solid #F0F2F5",display:"flex",flexDirection:"column",height:"100%",overflowY:"auto"}},{children:Le.genre?t(l,{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Matching scope for your station"})),i(p,e({sx:{display:"flex",flexDirection:"column",gap:2,mb:4}},{children:ye?i(k,{}):Ge?i(E,e({},Ge,{isSelected:Te===Ge.id,onSelect:_e}),Ge.id):null})),i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Other available stations"})),t("div",e({className:N.searchWrapper},{children:[i("input",{type:"text",value:pe,onChange:function(e){return fe(e.target.value)},placeholder:"Search for station...",className:N.searchInput}),i(S,{className:N.searchIcon,size:16})]})),t(p,e({sx:{display:"flex",flexDirection:"column",gap:2}},{children:[be&&i(k,{}),!be&&0===ce.length&&he.trim()&&t(f,e({sx:{fontSize:"0.875rem",color:"#64748B",textAlign:"center",py:4}},{children:['No scopes found matching "',he,'".']})),!be&&ce.map(function(n){return i(E,e({},n,{isSelected:Te===n.id,onSelect:_e}),n.id)})]}))]}):t(l,{children:[i(f,e({sx:{fontSize:"1rem",fontWeight:500,mb:1.5}},{children:"Fill in the station details to load AI recommended scopes"})),i(f,e({sx:{fontSize:"0.75rem",color:"#64748B",mb:3}},{children:"AI will recommend the most relevant scope for this station."})),i(p,e({sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",opacity:.5,py:10}},{children:i(b,{})}))]})}))]}))]})),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:Ze,disabled:Fe,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 n(void 0,void 0,void 0,function(){var n,t,i,l,a,s,c,u,d,p,f,m,h,g,v,b,S,x;return o(this,function(o){switch(o.label){case 0:if(!K||!Te)return console.error("[StationOnboard] Missing required data for onboarding"),[2];n=Ge?r([Ge],ce,!0):ce,t=n.find(function(e){return e.id===Te}),i=null!==(h=null==t?void 0:t.isCopy)&&void 0!==h&&h,ze(!0),Ee(0),l=null,o.label=1;case 1:return o.trys.push([1,3,,4]),a={topic:"customRuleSet",scope_reference_id:null,scopeDescription:"demo",parentScopeId:null,scopeName:K.station_name||"New Station",scopeReferenceMetadata:{},applicationMappingId:H},console.log("[StationOnboard] Step 1: Creating rule set with payload:",a),[4,F(a,U)];case 2:if(s=o.sent(),!(l=null===(g=null==s?void 0:s.data)||void 0===g?void 0:g.scopeId))throw new Error("Failed to create scope - no scopeId returned");return console.log("[StationOnboard] Step 1 Complete: Created scope with ID:",l),Ee(1),[3,4];case 3:return c=o.sent(),console.error("[StationOnboard] Error creating rule set:",c),null===(v=Me.current)||void 0===v||v.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to create rule set. Please try again."}),ze(!1),Ee(0),[2];case 4:return o.trys.push([4,6,,11]),u={market:K.market,region:K.region,timezone:Le.timezone,primetime_windows:Le.primeTime,genre:Le.genre,station_type:""===Le.type?null:Le.type,low_sellout_configurations:"Low Sellout"===Le.type?Le.lowSelloutConfig:null,ruleset_id:l,station_guid:K.station_guid,station_name:K.station_name||"New Station"},console.log("[StationOnboard] Step 2: Updating station with payload:",u),[4,O(u)];case 5:return o.sent(),console.log("[StationOnboard] Step 2 Complete: Station updated"),Ee(2),[3,11];case 6:d=o.sent(),console.error("[StationOnboard] Error updating station, rolling back rule set:",d),409===d.status?(null===(b=Me.current)||void 0===b||b.show({severity:"error",life:2500,summary:"Error updating station",detail:"Station already Onboarded."}),X(null),_e(null),Ae(""),Re(function(n){return e(e({},n),{region:""})})):null===(S=Me.current)||void 0===S||S.show({severity:"error",life:2500,summary:"Error updating station",detail:"Please try again."}),o.label=7;case 7:return o.trys.push([7,9,,10]),[4,_(l,U)];case 8:return o.sent(),console.log("[StationOnboard] Rollback complete: Deleted rule set",l),[3,10];case 9:return p=o.sent(),console.error("[StationOnboard] Failed to rollback rule set deletion:",p),[3,10];case 10:return ze(!1),Ee(0),[2];case 11:return o.trys.push([11,13,,14]),f={source_scope_id:Te,target_scope_id:l,is_copy_parent_variant_id:i},console.log("[StationOnboard] Step 3: Inheriting scope with payload:",f),[4,T(f)];case 12:return o.sent(),console.log("[StationOnboard] Step 3 Complete: Scope inherited"),Ee(3),[3,14];case 13:return m=o.sent(),console.error("[StationOnboard] Error inheriting scope (no rollback):",m),null===(x=Me.current)||void 0===x||x.show({severity:"error",life:3e3,summary:"Error",detail:"Failed to apply rule template. Please try again."}),ze(!1),Ee(0),[2];case 14:return je.current=l,console.log("[StationOnboard] Onboarding completed successfully!"),[2]}})})},disabled:!Xe||Fe,style:{padding:"7px 10px",borderRadius:"6px",border:"none",backgroundColor:Xe?"#2563EB":"#BFDBFE",color:"#fff",cursor:Xe&&!Fe?"pointer":"not-allowed",fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"7px"}},{children:t(l,Fe?{children:[i(g,{size:16,color:"inherit"}),i("span",{children:"Onboarding..."})]}:{children:[i("span",{children:"Onboard Station"}),i(x,{size:16})]})}))]}))]}))};export{L 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": "0.1.1-alpha.37",
3
+ "version": "0.1.1-alpha.38",
4
4
  "author": "Devesh Patel",
5
5
  "description": "",
6
6
  "license": "MIT",