(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,72637,e=>{"use strict";var t=e.i(43476),r=e.i(71645);let a={id:void 0,name:"",description:"",greeting:"",gender:"",appearance:"",image_url:"",image_style:"anime",generated_images:[],background:"",personality:{dominant:50,kind:50,flirty:50,funny:50,intelligent:50,brave:50},step1_personality:void 0,voice_id:"",voice_archetype:void 0,visibility:"",chat_filter:"",communication_style:"roleplay",age:"",rank:0,is_edited:!1},i=(0,r.createContext)(void 0);function o({children:e}){let[o,n]=(0,r.useState)(a),[l,s]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),u=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{if(c)return;let e=localStorage.getItem("character_draft");if(e)try{let t=JSON.parse(e);t.is_edited?(console.log("[Context] Abandoned re-edit draft detected in localStorage — discarding to ensure clean slate."),localStorage.removeItem("character_draft")):(n({...a,...t,personality:{dominant:50,kind:50,flirty:50,funny:50,intelligent:50,brave:50,...t.personality||{}},voice_id:t.voice_id?t.voice_id.toString():"",visibility:t.visibility||"private",chat_filter:t.chat_filter||"filtered",communication_style:t.communication_style||"roleplay",age:t.age||18,rank:t.rank||0,is_edited:!1,...t.step1_personality?{step1_personality:t.step1_personality}:{}}),console.log("[Context] Restored new-character draft from localStorage"))}catch(e){console.error("[Context] Failed to parse draft:",e)}d(!0)},[c]),(0,r.useEffect)(()=>{if(!c)return;s(!0);let e=setTimeout(()=>{u.current=!1},100);return()=>clearTimeout(e)},[c]),(0,r.useEffect)(()=>{if(!l||u.current)return;let e=setTimeout(()=>{console.log("[Context] Persisting changes to localStorage");let e={...o,last_saved:new Date().toLocaleString()};localStorage.setItem("character_draft",JSON.stringify(e))},500);return()=>clearTimeout(e)},[o,l]),(0,t.jsx)(i.Provider,{value:{characterData:o,isInitialized:l,updateCharacter:e=>{n(t=>{let r=e.personality?{...t.personality,...e.personality}:t.personality,a=e.step1_personality?{...t.step1_personality||{},...e.step1_personality}:t.step1_personality;return{...t,...e,personality:r,step1_personality:a}})},resetCharacter:()=>{localStorage.removeItem("character_draft"),localStorage.removeItem("character_creation_progressed"),u.current=!0,n(a),s(!1),d(!1)}},children:e})}function n(){let e=(0,r.useContext)(i);if(!e)throw Error("useCharacterCreation must be used within CharacterCreationProvider");return e}e.s(["CharacterCreationProvider",()=>o,"useCharacterCreation",()=>n])},4046,e=>{"use strict";var t=e.i(43476),r=e.i(72637);function a({children:e}){return(0,t.jsx)(r.CharacterCreationProvider,{children:e})}e.s(["default",()=>a])}]);