import{r as e}from"./chunk-QTnfLwEv.js";import{o as t}from"./jsx-runtime-DHSfUA5-.js";import{P as n,R as r}from"./test.id-DxQrYxPk.js";var i=e(t(),1);function a(e,t){let a=n(r),[o,s]=(0,i.useState)(()=>{if(e.channel===`host`)return a.getPreference(e);let t=localStorage.getItem(e.key);if(t===null)return e.defaultValue;let n=e.schema.safeParse(t);return n.success?n.data:e.defaultValue});return[o,async n=>{let r=o,i=n??e.defaultValue;s(i);try{if(e.channel===`host`){let t=e;n===void 0?await a.clearPreference(t):await a.savePreference(t,n)}else if(n===void 0)localStorage.removeItem(e.key);else{let t=e.schema.parse(n);if(typeof t!=`string`)throw Error(`Local preference "${e.key}" must serialize to a string.`);localStorage.setItem(e.key,t)}}catch(e){throw s(r),e}await t?.onSave?.(i)}]}export{a as t};
//# sourceMappingURL=usePreference-3fMY0uE5.js.map