"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $=require("react/jsx-runtime"),t=require("react"),j=require("./Stream.cjs.js"),C=t.createContext(void 0);function k({children:e}){const[n,i]=t.useState(null),o=t.useMemo(()=>({config:n,setConfig:i}),[n]);return $.jsx(C.Provider,{value:o,children:e})}function d(){const e=t.useContext(C);if(!e)throw new Error("useSuggestionConfig must be used within a SuggestionProvider");return e}function M(e={},n=[]){const{setConfig:i}=d(),o=t.useMemo(()=>JSON.stringify(e),[e.instructions,e.minSuggestions,e.maxSuggestions]),f=t.useMemo(()=>JSON.stringify(n),[n.length,...n]);t.useEffect(()=>(i({options:e,deps:n,isEnabled:!0}),()=>{i(null)}),[o,f])}function q(e={}){const{suggestions:n}=e,{sendMessage:i}=j.useStreamContext(),{config:o}=d(),[f,r]=t.useState([]),p=o?.options?.instructions??e.instructions??"Suggest relevant next actions.",a=o?.options?.minSuggestions??e.minSuggestions??2,S=o?.options?.maxSuggestions??e.maxSuggestions??4,l=o?.options?.suggestions??e.suggestions,g=o?.deps??[],x=o?.isEnabled??!1,b=t.useRef(0),m=t.useRef(new WeakMap),v=t.useMemo(()=>g.map(s=>{if(s===null)return"null";if(s===void 0)return"undefined";const c=typeof s;return c==="object"||c==="function"?(m.current.has(s)||m.current.set(s,b.current++),`ref:${m.current.get(s)}`):`${c}:${String(s)}`}).join("|"),[g]);t.useEffect(()=>{if(!x){r([]);return}let s=!0;if(r([]),n&&n.length>0){r(n);return}if(l&&l.length>0){r(l);return}const c=["Ask for clarification about the user's goals.","Summarize the previous message in one sentence.","Suggest next steps for implementing the feature.","Ask whether they want code examples.","Propose a refactor to improve readability.","Offer to run tests and show results."],h=[];if(g.length>0){const u=g[g.length-1];typeof u=="string"&&u.trim().length>0&&(h.push(`Follow up on: "${u.slice(0,120)}"`),h.push(`Ask a clarifying question about: "${u.slice(0,80)}"`))}const E=Math.max(a,Math.min(S,Math.floor(Math.random()*(S-a+1))+a)),y=[...h,...c].filter(Boolean).slice(0,E),P=setTimeout(()=>{if(!s)return;const u=p?y.map(R=>`${R}`):y;r(u)},150);return()=>{s=!1,clearTimeout(P)}},[v,p,a,S,n,l,x]);const w=t.useCallback(s=>{i(s,{type:"human"})},[i]);return{suggestions:f,onSelect:w}}exports.SuggestionProvider=k;exports.default=M;exports.useChatSuggestions=M;exports.useGeneratedSuggestions=q;exports.useSuggestionConfig=d;
//# sourceMappingURL=useChatSuggestions.cjs.js.map
