1import{n as ge,r as o,j as r,B as y,T as l,f as S,R as ur}from"./index-CzOd9Km7.js";import{u as _e}from"./useMutation-CJKToZ6s.js";import{u as pr}from"./useQuery-BcbK_yvX.js";import{g as ve}from"./genreContractApi-Cm3YTu1t.js";import{cardApi as mr}from"./cardApi-CCWEEX4S.js";import{S as yr}from"./ProjectView-Mi3StT_6.js";import{A as z}from"./Alert-BXc9IPcV.js";import{C as xr}from"./CircularProgress-CFKeHsf1.js";import{S as p}from"./Stack-E99Gdh2J.js";import{F as ye,I as xe,S as fe,T as qe}from"./TextField-BLDfXARA.js";import{M as N}from"./MenuItem-CKC7Jjka.js";import{C as fr}from"./Checkbox-CDjSoqnY.js";import{L as A,D as hr,a as gr,b as _r,c as vr}from"./TrendingUp-DOlPqcSv.js";import{L as Ke}from"./Menu-BAMQbaXI.js";import{C as J}from"./dividerClasses-CE6pxdyz.js";import"./axiosConfig-BS0LIV0L.js";import"./supabaseAuthClient-D4COccm1.js";import"./useProjects-CIew3vEQ.js";import"./useInfiniteQuery-DMg-BX9J.js";import"./projectSchemas-h1QnwtOV.js";import"./taskCenterStorage-CJYyvdpT.js";import"./createSvgIcon-DaEeqn1R.js";import"./ownerWindow-D5LHhVun.js";import"./useControlled-C1WEhlQX.js";import"./requirePropFactory-CXHKSpYe.js";import"./IconButton-DX7NfjoN.js";import"./useTemplate-ViNE3wSO.js";import"./useBillingPreference-D9W5TnwM.js";import"./useSupabaseAuth-DG28FngJ.js";import"./SupabaseProvider-CTgOxySk.js";import"./authRedirect-DCYLoor1.js";import"./billingApi-B525x-Ud.js";import"./screenplaySchemas-D4JI8Qiv.js";import"./weaveApi-BNjBXpjA.js";import"./Add-DR3ny3xK.js";import"./Paper-2iw6XA5a.js";import"./Popper-t1n9sSlv.js";import"./Avatar-C-SXWBlB.js";import"./Divider-UFPhkgyE.js";import"./Person-Bgotsgvw.js";import"./Tabs-Ba5iDgru.js";import"./Warning-Ps4lknT4.js";import"./Restore-ruzW0M8I.js";import"./usePreviousProps-D6D_fzw_.js";import"./designTokens-CHJCN-yJ.js";import"./Grid-NNIo4zT1.js";import"./ExpandMore-5fy3CFZO.js";import"./Snackbar-zJwnOmcl.js";import"./Edit-hGaSq1bW.js";import"./Card-BXrAfFWw.js";import"./Collapse-Bnk0IQSm.js";import"./ButtonGroup-CVCxmEpG.js";import"./useMediaQuery-BbaHISUJ.js";import"./getThemeProps-whaKXyLK.js";import"./collaborationApi-Bg8o2r1s.js";import"./chunkPrefetch-Db-BfmQX.js";import"./Toolbar-Cld6iuHK.js";import"./styled-D002SLmF.js";import"./useThemeProps-Dhrs3fnV.js";import"./SwitchBase-B_U2OR8-.js";const je=a=>["genre-contract",a];function jr(a,c=!0){return pr({queryKey:je(a),queryFn:()=>ve.get(a),enabled:c&&!!a})}function br(a){const c=ge();return _e({mutationFn:u=>ve.apply(a,u),onSuccess:()=>{c.invalidateQueries({queryKey:je(a)}),c.invalidateQueries({queryKey:["project",a]}),c.invalidateQueries({queryKey:["project-stage",a]})}})}function Cr(a){const c=ge();return _e({mutationFn:u=>ve.createLocalCard(a,u),onSuccess:()=>{c.invalidateQueries({queryKey:je(a)}),c.invalidateQueries({queryKey:["project",a]}),c.invalidateQueries({queryKey:["project-stage",a]})}})}const Sr={Tone:'How the movie should feel. e.g. "Eerie and intimate, like elevated folk horror â grounded, not campy."',Boundaries:'What to avoid or protect. e.g. "Scary but never gory; emotional but never sentimental."'},wr={Tone:"Eerie, intimate, and psychologically tense.",Boundaries:"Scary but never gory. Funny but never silly."},Ir="Choose your movie's genres. Each genre brings in the story cards audie
1nces expect â shown below. Set the tone so the AI matches the feel you want, then apply.",Mr=["Tone","Boundaries"];function Et({project:a,stage:c,onContractApplied:u}){var $e;const x=jr(a.name,a.mode==="genre_movies"),j=br(a.name),b=Cr(a.name),m=ge(),t=x.data,i=t==null?void 0:t.registry,h=o.useMemo(()=>(i==null?void 0:i.genres)??[],[i==null?void 0:i.genres]),E=o.useMemo(()=>new Map(((i==null?void 0:i.overlays)??[]).map(e=>[e.id,e])),[i==null?void 0:i.overlays]),R=o.useMemo(()=>new Map(h.map(e=>[e.id,e])),[h]),[g,$]=o.useState("drama"),[_,B]=o.useState([]),[k,K]=o.useState(new Set),[be,Y]=o.useState(new Set),[Ce,U]=o.useState(new Set),[Se,V]=o.useState(new Set),[we,X]=o.useState(new Set),[Z,ee]=o.useState(""),[T,Ne]=o.useState("all"),[Je,W]=o.useState(!1),[Ye,re]=o.useState(!1),[Ie,Me]=o.useState(""),Re=o.useRef(!1),Oe=o.useRef(!1),D=o.useRef(null),te=o.useRef(null),w=o.useMemo(()=>{const e=R.get(g);if(!e)return{cardIds:[],overlayIds:[]};const s=[...e.primary_default_cards??[]],n=[...e.primary_default_overlays??[]];for(const v of _){const f=R.get(v);if(f){for(const M of f.secondary_default_cards??[])s.includes(M)||s.push(M);for(const M of f.secondary_default_overlays??[])n.includes(M)||n.push(M)}}return{cardIds:s,overlayIds:n}},[R,g,_]),G=o.useMemo(()=>{const e=new Set;for(const s of w.cardIds)Ce.has(s)||e.add(s);for(const s of be)e.add(s);return e},[w.cardIds,Ce,be]),I=o.useMemo(()=>{const e=new Set;for(const s of w.overlayIds)we.has(s)||e.add(s);for(const s of Se)e.add(s);return e},[w.overlayIds,we,Se]),O=($e=a.cards)==null?void 0:$e["10.30.20"],[Q,ke]=o.useState({Tone:"",Boundaries:""}),se=_e({mutationFn:e=>mr.update(a.name,c.id,"10.30.20",{fields:e}),onSuccess:(e,s)=>{te.current=s,m.invalidateQueries({queryKey:["project",a.name]}),m.invalidateQueries({queryKey:["project-stage",a.name]})}}),Ge=se.mutate;o.useEffect(()=>{var De,Pe;if(!(t!=null&&t.selection)||Re.current)return;const e=(t.card_states??[]).filter(d=>d.state==="active"&&d.registry_card_id).map(d=>d.registry_card_id),s=((De=t.recommendation)==null?void 0:De.card_ids)??[],n=new Set(s),v=(t.card_states??[]).filter(d=>d.state==="inactive"&&d.registry_card_id).map(d=>d.registry_card_id),f=new Set(v),M=(t.overlay_states??[]).filter(d=>d.state==="active").map(d=>d.registry_overlay_id),H=((Pe=t.recommendation)==null?void 0:Pe.overlay_ids)??[],C=new Set(H),lr=(t.overlay_states??[]).filter(d=>d.state==="inactive").map(d=>d.registry_overlay_id),cr=new Set(lr);$(t.selection.primary_genre_id||"drama"),B(t.selection.secondary_genre_ids||[]),Y(new Set(e.filter(d=>!n.has(d)))),U(new Set(s.filter(d=>f.has(d)))),V(new Set(M.filter(d=>!C.has(d)))),X(new Set(H.filter(d=>cr.has(d)))),K(new Set((t.card_states??[]).filter(d=>d.state==="active"&&d.project_local_card_id).map(d=>d.project_local_card_id))),Re.current=!0},[t]),o.useEffect(()=>{if(!(O!=null&&O.fields))return;const e={Tone:String(O.fields.Tone??""),Boundaries:String(O.fields.Boundaries??"")};ke(e),te.current=e,Oe.current=!0},[O==null?void 0:O.fields]),o.useEffect(()=>{if(!(!Oe.current||!O)&&JSON.stringify(Q)!==JSON.stringify(te.current))return D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{Ge(Q)},700),()=>{D.current&&clearTimeout(D.current)}},[O,Q,Ge]);const Ue=o.useMemo(()=>{const e=new Map;for(const s of(t==null?void 0:t.card_states)??[])s.registry_card_id&&e.set(s.registry_card_id,s);return e},[t==null?void 0:t.card_states]),P=o.useMemo(()=>((t==null?void 0:t.card_states)??[]).filter(e=>e.project_local_card_id),[t==null?void 0:t.card_states]),Te=o.useMemo(()=>((i==null?void 0:i.cards)??[]).filter(e=>T==="all"||e.genre_id===T),[T,i==null?void 0:i.cards]),Fe=o.useMemo(()=>((i==null?void 0:i.overlays)??[]).filter(e=>T==="all"||e.genre_id===T),[T,i==null?void 0:i.overlays]),ze=o.useMemo(()=>Rr(R,g,_),[R,g,_]),F=o.useMemo(()=>Or((i==null?void 0:i.overlays)??[],I,ze,_),[i==null?void 0:i.overlays,I,ze,_]),q=o.useMemo(()=>((i==null?void 0:i.cards)??[]).filter(e=>G.has(e.id)),[i==null?void 0:i.cards,G]),ne=o.useMemo(()=>P.filter(e=>e.project_local_card_id&&k.has(e.project_local_card_id)),[P,k]),ie=o.useMemo(()=>P.filter(e=>e.project_local_card_id&&!k.has(e.project_local_card_id)),[P,k]),ae=o.useMemo(()=>((i==null?void 0:i.overlays)??[]).filter(e=>I.has(e.id)),[i==null?void 0:i.overlays,I]),Ae=o.useMemo(()=>new Set(q.map(e=>We(e))),[q]),oe=o.useMemo(()=>Te.filter(e=>!G.has(e.id)&&!Ae.has(We(e))),[Ae,Te,G]),de=o.useMemo(()=>Fe.filter(e=>!I.has(e.id)),[Fe,I]),le=q.length+ne.length+ae.length,Ve=o.useMemo(()=>new Set(((t==null?void 0:t.card_states)??[]).filter(e=>e.state==="active"&&e.registry_card_id).map(e=>e.registry_card_id)),[t==null?void 0:t.card_states]),Xe=o.useMemo(()=>new Set(((t==null?void 0:t.card_states)??[]).filter(e=>e.state==="active"&&e.project_local_card_id).map(e=>e.project_local_card_id)),[t==null?void 0:t.card_states]),Ze=o.useMemo(()=>new Set(((t==null?void 0:t.overlay_states)??[]).filter(e=>e.state==="active").map(e=>
1e.registry_overlay_id)),[t==null?void 0:t.overlay_states]),Le=o.useMemo(()=>{var e,s;return Qe({primaryGenreId:((e=t==null?void 0:t.selection)==null?void 0:e.primary_genre_id)||"drama",secondaryGenreIds:((s=t==null?void 0:t.selection)==null?void 0:s.secondary_genre_ids)||[],cardIds:((t==null?void 0:t.card_states)??[]).filter(n=>n.state==="active"&&n.registry_card_id).map(n=>n.registry_card_id),localCardIds:((t==null?void 0:t.card_states)??[]).filter(n=>n.state==="active"&&n.project_local_card_id).map(n=>n.project_local_card_id),overlayIds:((t==null?void 0:t.overlay_states)??[]).filter(n=>n.state==="active").map(n=>n.registry_overlay_id)})},[t==null?void 0:t.card_states,t==null?void 0:t.overlay_states,t==null?void 0:t.selection]),Ee=o.useMemo(()=>Qe({primaryGenreId:g,secondaryGenreIds:_,cardIds:Array.from(G),localCardIds:Array.from(k),overlayIds:Array.from(I)}),[g,_,G,k,I]),ce=e=>{var n;const s=(n=a.cards)==null?void 0:n[e];return typeof(s==null?void 0:s.name)=="string"&&s.name||e},ue=e=>{const s=(e.info||"").trim(),n=(e.llm_instructions||"").trim();return n&&n.length>s.length+30?He(n):s||He(n)};o.useEffect(()=>{t!=null&&t.selection&&Me(Le)},[t==null?void 0:t.selection,Le]);const pe=!!(Ie&&Ee!==Ie),er=j.isPending?"Applying...":pe?"Not applied yet":"Applied",rr=e=>{const s=e.target.value,n=typeof s=="string"?s.split(","):s;B(n.filter(v=>v!==g).slice(0,3))},tr=e=>{w.cardIds.includes(e)?U(s=>{const n=new Set(s);return n.delete(e),n}):Y(s=>new Set(s).add(e))},sr=e=>{w.cardIds.includes(e)?U(s=>new Set(s).add(e)):Y(s=>{const n=new Set(s);return n.delete(e),n})},nr=e=>{K(s=>new Set(s).add(e))},ir=e=>{K(s=>{const n=new Set(s);return n.delete(e),n})},Be=e=>{w.overlayIds.includes(e)?X(s=>{const n=new Set(s);return n.delete(e),n}):V(s=>new Set(s).add(e))},me=e=>{w.overlayIds.includes(e)?X(s=>new Set(s).add(e)):V(s=>{const n=new Set(s);return n.delete(e),n})},ar=(e,s)=>{for(const n of s)n===e?Be(n):me(n)},or=e=>{for(const s of e)me(s)},dr=()=>{const e=new Set(w.cardIds),s=new Set(w.overlayIds),n=Array.from(G).filter(C=>!e.has(C)),v=w.cardIds.filter(C=>!G.has(C)),f=P.map(C=>C.project_local_card_id).filter(C=>!!C),M=Array.from(I).filter(C=>!s.has(C)),H=w.overlayIds.filter(C=>!I.has(C));j.mutate({primary_genre_id:g,secondary_genre_ids:_,enabled_card_ids:n,disabled_card_ids:v,enabled_local_card_ids:Array.from(k),disabled_local_card_ids:f.filter(C=>!k.has(C)),enabled_overlay_ids:M,disabled_overlay_ids:H},{onSuccess:()=>{Me(Ee),u==null||u()}})};return a.mode!=="genre_movies"?r.jsx(z,{severity:"info",children:"Genres are available in Genre Movie projects."}):x.isLoading?r.jsx(y,{display:"flex",justifyContent:"center",py:6,children:r.jsx(xr,{})}):x.error||!(t!=null&&t.supported)?r.jsx(z,{severity:"error",children:(t==null?void 0:t.reason)||"Could not load the genre contract."}):r.jsxs(p,{spacing:3,"data-testid":"genres-stage",children:[r.jsx(yr,{title:c.name||"Genres",description:Ir,actions:r.jsxs(r.Fragment,{children:[r.jsx(l,{variant:"body2",color:pe?"warning.main":"text.secondary","data-testid":"genre-apply-state",children:er}),r.jsx(S,{variant:"contained",onClick:dr,disabled:j.isPending||F.length>0||!pe,"data-testid":"apply-genre-contract",children:"Apply Genres"})]})}),r.jsxs(p,{direction:{xs:"column",md:"row"},spacing:2,children:[r.jsxs(ye,{fullWidth:!0,children:[r.jsx(xe,{id:"primary-genre-label",children:"Primary Genre"}),r.jsx(fe,{labelId:"primary-genre-label",label:"Primary Genre",value:g,onChange:e=>{const s=e.target.value;$(s),B(n=>n.filter(v=>v!==s))},"data-testid":"primary-genre-select",children:h.map(e=>r.jsx(N,{value:e.id,children:e.display_name},e.id))})]}),r.jsxs(ye,{fullWidth:!0,children:[r.jsx(xe,{id:"secondary-genres-label",children:"Secondary Genres"}),r.jsx(fe,{labelId:"secondary-genres-label",label:"Secondary Genres",multiple:!0,value:_,onChange:rr,renderValue:e=>e.map(s=>{var n;return((n=h.find(v=>v.id===s))==null?void 0:n.display_name)||s}).join(", "),"data-testid":"secondary-genres-select",children:h.filter(e=>e.id!==g).map(e=>r.jsxs(N,{value:e.id,disabled:!_.includes(e.id)&&_.length>=3,children:[r.jsx(fr,{checked:_.includes(e.id)}),r.jsx(A,{primary:e.display_name})]},e.id))})]})]}),r.jsxs(p,{spacing:2,"data-testid":"tone-card-controls",children:[r.jsxs(y,{children:[r.jsx(l,{variant:"h5",children:"Tone"}),r.jsx(l,{variant:"body2",color:"text.secondary",children:'This guides the AI whenever it writes, reviews, revises, or visualizes your movie. Example: "eerie and elegant, like elevated folk horror; scary but never gory; grounded like Hereditary with the mystery pull of The Ring."'})]}),r.jsx(p,{direction:{xs:"column",md:"row"},spacing:2,children:Mr.map(e=>r.jsx(qe,{label:e,helperText:Sr[e],placeholder:wr[e],value:Q[e],onChange:s=>ke(n=>({...n,[e]:s.target.value})),multiline:!0,minRows:2,fullWidth:!0},e))}),se.isPending&&r.jsx(l,{variant:"caption",color:"text.secondary",children:"Saving tone..."}),se.error&&r.jsx(z,{severity:"error",children:"Could not save tone."})]}),j.error&&r.jsx(z,{severity:"error",children:"Could not apply genre changes."}),b.error&&r.jsx(z,{severity:"error",children:"Could not add local genre card."}),F.length>0&&r.jsxs(z,{severity:"warning","data-testid":"genre-overlay-conflicts",action:r.jsx(S,{size:"small",color:"inherit",onClick:()=>W(!0),"data-testid":"open-conflict-resolver",children:"Resolve"}),children:[F.length," overlay conflict",F.length===1?"":"s"," to resolve before applying."]}),r.jsxs(y,{"data-testid":"genre-cards-list",children:[r.jsxs(y,{display:"flex",justifyContent:"space-between",alignItems:"center",sx:{mb:1.5},children:[r.jsx(l,{variant:"h5",children:"Genre Cards"}),r.jsx(S,{variant:"outlined",size:"small",onClick:()=>W(!0),"data-testid":"customize-genre-cards",children:"Customize cards..."})]}),le===0?r.jsx(l,{variant:"body2",color:"text.secondary",children:"Pick a primary genre to bring in its story cards."}):r.jsxs(p,{spacing:1.5,children:[q.map(e=>r.jsx(he,{title:e.display_name,genre:L(h,e.genre_id),description:ue(e),isNew:!Ve.has(e.id)},e.id)),ae.map(e=>r.jsx(he,{title:e.display_label,genre:L(h,e.genre_id),description:e.prompt_addition||`${L(h,e.genre_id)} guidance`,isNew:!Ze.has(e.id)},e.id)),ne.map(e=>{const s=e.project_local_card_id||"",n=e.project_local_definition||{};return r.jsx(he,{title:n.display_name||e.card_code,genre:"Custom",description:typeof n.info=="str
1ing"?n.info:"",isNew:!Xe.has(s)},s)})]})]}),r.jsxs(hr,{open:Je,onClose:()=>W(!1),fullWidth:!0,maxWidth:"lg",children:[r.jsx(gr,{children:"Customize Genre Cards"}),r.jsx(_r,{dividers:!0,children:r.jsxs(p,{spacing:3,children:[F.length>0&&r.jsxs(z,{severity:"warning","data-testid":"dialog-overlay-conflicts",children:[r.jsxs(l,{variant:"subtitle2",gutterBottom:!0,children:["Overlay conflicts (",F.length,")"]}),r.jsx(l,{variant:"caption",color:"text.secondary",children:"Two or more overlays want to shape the same structural beat. Pick one or disable them."}),F.map(e=>r.jsxs(y,{sx:{mt:2},children:[r.jsxs(l,{variant:"body2",gutterBottom:!0,children:["Target: ",r.jsx("strong",{children:ce(e.target_card_code)})," (",e.target_card_code,")"]}),r.jsxs(p,{spacing:1,children:[e.overlay_ids.map(s=>{const n=E.get(s),v=e.overlay_ids.filter(M=>I.has(M)),f=v.length===1&&v[0]===s;return r.jsx(y,{sx:{p:1,border:1,borderColor:f?"primary.main":"divider",borderRadius:1},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",justifyContent:"space-between",children:[r.jsxs(y,{sx:{flex:1},children:[r.jsx(l,{variant:"body2",children:(n==null?void 0:n.display_label)||s}),(n==null?void 0:n.prompt_addition)&&r.jsx(l,{variant:"caption",color:"text.secondary",children:n.prompt_addition})]}),r.jsx(S,{size:"small",variant:f?"contained":"outlined","data-testid":`genre-overlay-conflict-choose-${s}`,onClick:()=>ar(s,e.overlay_ids),children:f?"Chosen":"Choose this"})]})},s)}),r.jsx(S,{size:"small",variant:"text","data-testid":`genre-overlay-conflict-disable-${e.target_card_code}-${e.conflict_group}`,onClick:()=>or(e.overlay_ids),children:"Disable both for this beat"})]})]},`${e.target_card_code}-${e.conflict_group}`))]}),r.jsxs(p,{direction:{xs:"column",md:"row"},spacing:2,alignItems:"flex-start",children:[r.jsxs(y,{sx:{flex:1,display:"flex",flexDirection:"column"},children:[r.jsxs(l,{variant:"subtitle1",gutterBottom:!0,children:["Active (",le,")"]}),r.jsx(y,{sx:{border:1,borderColor:"divider",borderRadius:1,bgcolor:"background.paper",p:1,overflowY:"auto",maxHeight:500},"data-testid":"active-cards-pane",children:le===0?r.jsx(y,{sx:{p:2},children:r.jsx(l,{variant:"body2",color:"text.secondary",children:"No active genre items."})}):r.jsxs(Ke,{dense:!0,disablePadding:!0,children:[q.map(e=>r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:e.display_name}),r.jsx(l,{component:"span",variant:"caption",color:"text.secondary",children:L(h,e.genre_id)})]}),secondary:ue(e)}),r.jsx(S,{size:"small",variant:"text",onClick:()=>sr(e.id),"data-testid":`remove-card-${e.id}`,children:"Remove â"})]})},e.id)),ne.map(e=>{const s=e.project_local_card_id||"",n=e.project_local_definition||{};return r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:n.display_name||e.card_code}),r.jsx(J,{label:"Custom",size:"small",variant:"outlined"})]}),secondary:typeof n.info=="string"?n.info:null}),r.jsx(S,{size:"small",variant:"text",onClick:()=>ir(s),"data-testid":`remove-local-card-${s}`,children:"Remove â"})]})},s)}),ae.map(e=>r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:e.display_label}),r.jsxs(l,{component:"span",variant:"caption",color:"text.secondary",children:["on ",ce(e.target_card_code)]})]}),secondary:e.prompt_addition||`${L(h,e.genre_id)} guidance`}),r.jsx(S,{size:"small",variant:"text",onClick:()=>me(e.id),"data-testid":`remove-overlay-${e.id}`,children:"Remove â"})]})},e.id))]})})]}),r.jsxs(y,{sx:{flex:1,display:"flex",flexDirection:"column"},children:[r.jsx(l,{variant:"subtitle1",gutterBottom:!0,children:"Available"}),r.jsx(p,{direction:"row",spacing:1,sx:{mb:1},children:r.jsxs(ye,{size:"small",sx:{flex:1},children:[r.jsx(xe,{id:"genre-card-filter-label",children:"Filter"}),r.jsxs(fe,{labelId:"genre-card-filter-label",label:"Filter",value:T,onChange:e=>Ne(e.target.value),"data-testid":"genre-card-filter",children:[r.jsx(N,{value:"all",children:"All Genres"}),h.map(e=>r.jsx(N,{value:e.id,children:e.display_name},e.id))]})]})}),r.jsx(y,{sx:{border:1,borderColor:"divider",borderRadius:1,bgcolor:"background.paper",p:1,overflowY:"auto",maxHeight:500},"data-testid":"genre-card-selector",children:oe.length+ie.length+de.length===0?r.jsx(y,{sx:{p:2},children:r.jsx(l,{variant:"body2",color:"text.secondary",children:"No more genre items available."})}):r.jsxs(Ke,{dense:!0,disablePadding:!0,children:[oe.map((e,s)=>{const n=oe[s-1],v=!n||n.genre_id!==e.genre_id;return r.jsxs(ur.Fragment,{children:[v&&r.jsx(l,{variant:"caption",color:"text.secondary",sx:{px:2,pt:1,display:"block"},children:L(h,e.genre_id)}),r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(S,{size:"small",variant:"text",onClick:()=>tr(e.id),"data-testid":`add-card-${e.id}`,children:"â Add"}),r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:e.display_name}),(()=>{const f=Ue.get(e.id);return(f==null?void 0:f.state)==="inactive"&&(f!=null&&f.has_content)?r.jsx(J,{label:"Has content",size:"small",variant:"outlined"}):null})()]}),secondary:ue(e)})]})})]},e.id)}),ie.length>0&&r.jsx(l,{variant:"caption",color:"text.secondary",sx:{px:2,pt:1,display:"block"},children:"Custom"}),ie.map(e=>{const s=e.project_local_card_id||"",n=e.project_local_definition||{};return r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(S,{size:"small",variant:"text",onClick:()=>nr(s),"data-testid":`add-local-card-${s}`,children:"â Add"}),r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:n.display_name||e.card_code}),e.state==="inactive"&&e.has_content&&r.jsx(J,{label:"Has content",size:"small",variant:"outlined"})]}
1),secondary:typeof n.info=="string"?n.info:null})]})},s)}),de.length>0&&r.jsx(l,{variant:"caption",color:"text.secondary",sx:{px:2,pt:1,display:"block"},children:"Existing Story Cards"}),de.map(e=>r.jsx(y,{sx:{px:2,py:1.25,mb:1,border:1,borderColor:"divider",borderRadius:1.5,bgcolor:"action.hover"},children:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",children:[r.jsx(S,{size:"small",variant:"text",onClick:()=>Be(e.id),"data-testid":`add-overlay-${e.id}`,children:"â Add"}),r.jsx(A,{primary:r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",useFlexGap:!0,flexWrap:"wrap",children:[r.jsx(l,{component:"span",variant:"body2",children:e.display_label}),r.jsxs(l,{component:"span",variant:"caption",color:"text.secondary",children:["on ",ce(e.target_card_code)]})]}),secondary:e.prompt_addition||`${L(h,e.genre_id)} guidance`})]})},e.id))]})})]})]})]})}),r.jsxs(vr,{sx:{justifyContent:"space-between",gap:2},children:[Ye?r.jsxs(p,{direction:{xs:"column",sm:"row"},spacing:1,sx:{flex:1},children:[r.jsx(qe,{label:"Custom card name",value:Z,onChange:e=>ee(e.target.value),size:"small",autoFocus:!0,inputProps:{"data-testid":"local-genre-card-name"}}),r.jsx(S,{variant:"outlined",disabled:!Z.trim()||b.isPending,onClick:()=>{b.mutate({display_name:Z.trim(),genre_id:"custom",fields:{Content:""}},{onSuccess:e=>{ee(""),re(!1),K(new Set((e.card_states??[]).filter(s=>s.state==="active"&&s.project_local_card_id).map(s=>s.project_local_card_id)))}})},"data-testid":"add-local-genre-card",children:"Add"}),r.jsx(S,{variant:"text",onClick:()=>{ee(""),re(!1)},children:"Cancel"})]}):r.jsx(S,{variant:"text",onClick:()=>re(!0),"data-testid":"open-add-custom-card",children:"Add custom card"}),r.jsx(S,{onClick:()=>W(!1),children:"Done"})]})]})]})}function L(a,c){var u;return((u=a.find(x=>x.id===c))==null?void 0:u.display_name)||c}function We(a){return`${a.genre_id}::${a.display_name.trim().toLowerCase()}`}function Qe({primaryGenreId:a,secondaryGenreIds:c,cardIds:u,localCardIds:x,overlayIds:j}){return JSON.stringify({primaryGenreId:a,secondaryGenreIds:[...c].sort(),cardIds:[...u].sort(),localCardIds:[...x].sort(),overlayIds:[...j].sort()})}function He(a){const c=a.trim();if(!c)return"";const u=c.split(new RegExp("(?<=[.!?])\\s"))[0]??c;return u.length<=160?u:`${u.slice(0,157).trim()}...`}function Rr(a,c,u){const x=new Map,j=a.get(c);for(const b of(j==null?void 0:j.primary_default_overlays)??[])x.set(b,"primary_default");for(const b of u){const m=a.get(b);for(const t of(m==null?void 0:m.secondary_default_overlays)??[])x.has(t)||x.set(t,"secondary_default")}return x}function Or(a,c,u,x){const j=new Map(x.map((m,t)=>[m,t])),b=new Map;for(const m of a){if(!c.has(m.id)||!m.conflict_group)continue;const t=`${m.target_card_code}::${m.conflict_group}`;b.set(t,[...b.get(t)??[],m.id])}return Array.from(b.entries()).filter(([,m])=>m.length>1).map(([m,t])=>{const[i,h]=m.split("::"),E=new Map(a.map(g=>[g.id,g])),R=[...t].sort((g,$)=>{const _=E.get(g),B=E.get($);return!_||!B?g.localeCompare($):kr(_,B,u,j)});return{target_card_code:i,conflict_group:h,overlay_ids:R,recommended_overlay_id:R[0]}})}function kr(a,c,u,x){const j=t=>{const i=u.get(t.id)||"manual",h=i==="primary_default"?0:i==="secondary_default"?1:2,E=x.get(t.genre_id)??999,R=t.priority??t.context_priority??0;return[h,E,-R,t.id]},b=j(a),m=j(c);for(let t=0;t<b.length-1;t+=1){const i=Number(b[t])-Number(m[t]);if(i!==0)return i}return String(b[3]).localeCompare(String(m[3]))}function he({title:a,genre:c,description:u,isNew:x}){return r.jsxs(y,{sx:{px:2,py:1.5,border:1,borderColor:x?"primary.main":"divider",borderRadius:1.5,bgcolor:"action.hover"},children:[r.jsxs(p,{direction:"row",spacing:1,alignItems:"flex-start",justifyContent:"space-between",children:[r.jsx(l,{variant:"subtitle1",children:a}),r.jsxs(p,{direction:"row",spacing:1,alignItems:"center",sx:{flexShrink:0},children:[x&&r.jsx(J,{label:"New",size:"small",color:"primary",variant:"outlined"}),r.jsx(l,{variant:"caption",color:"text.secondary",children:c})]})]}),u&&r.jsx(l,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:u})]})}export{Et as GenresStage}; 2//# sourceMappingURL=GenresStage-WnhK3r6P.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.