var u=Object.defineProperty;var c=(i,e,s)=>e in i?u(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s;var o=(i,e,s)=>(c(i,typeof e!="symbol"?e+"":e,s),s);import{M as f}from"./fp-Model.js?ver=1.3.1";import{R as h,N as g,z as y,j as d}from"./admin.js?ver=1.3.1";class p extends f{constructor(){super(...arguments);o(this,"data",{settings:{general:{},youtube:{},performance:{},analytics:{},google_analytics:{},branding:{}},errors:{},savedSnapshot:"",isBusy:{saving:!1,loading:!1}});o(this,"defaults",{general:{default_aspect_ratio:"original",resume_playback:!0,custom_css:""},youtube:{privacy_mode:!1,show_subscribe_button:!1},performance:{},analytics:{enabled:!1,auto_cleanup:{enabled:!0,days:30}},google_analytics:{enabled:!1,use_existing_tag:!1,measurement_id:""},branding:{brand_color:"#DD1F13",control_bar_color:"#171717A6",logo_url:"",logo_link:"",logo_position:"top-right",logo_width:100}})}get(){return this.isBusy.loading=!0,h.get("settings").then(s=>{if(s&&s.settings){let t=s.settings;if(typeof t=="string")try{t=JSON.parse(t)}catch(a){console.error("Error parsing settings JSON:",a)}this.settings=this.deepMerge(this.defaults,t)}else this.settings=this.deepMerge({},this.defaults);this.takeSnapshot()}).then(()=>this.settings).catch(s=>{throw console.error("Error loading settings:",s),g.error("Failed to load settings"),this.settings=this.deepMerge({},this.defaults),this.takeSnapshot(),s}).finally(()=>{this.isBusy.loading=!1})}takeSnapshot(){this.savedSnapshot=JSON.stringify(this.settings)}isDirty(){return this.savedSnapshot?JSON.stringify(this.settings)!==this.savedSnapshot:!1}discard(){this.savedSnapshot&&(this.settings=JSON.parse(this.savedSnapshot))}deepMerge(s,t){const a={...s};for(const n in t)t[n]instanceof Object&&n in s&&s[n]instanceof Object?a[n]=this.deepMerge(s[n],t[n]):a[n]=t[n];return a}save(){this.isBusy.saving=!0;const s={...this.settings};return delete s.integrations,h.put("settings",{settings:s}).then(t=>t).then(t=>(t&&t.settings&&typeof t.settings=="object"&&(this.settings=this.deepMerge(this.settings,t.settings)),this.takeSnapshot(),g.success(t.message||"Settings saved successfully"),t)).catch(t=>{throw console.error("Error saving settings:",t),g.error(t.message||"Failed to save settings"),t}).finally(()=>{this.isBusy.saving=!1})}}const r=p.init(),l=y(!1),S=d(()=>{var i,e;return((e=(i=r.settings)==null?void 0:i.general)==null?void 0:e.default_preset)||null}),_=d(()=>r.isDirty());function M(){return{Settings:r,loadSettings:async()=>{if(!l.value)try{await r.get(),l.value=!0}catch(e){console.error("Failed to load settings:",e)}},isSettingsLoaded:l,isSettingsDirty:_,defaultPresetSlug:S}}export{M as u};
