function e(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function n(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function t(t){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?n(Object(i),!0).forEach(function(n){e(t,n,i[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))})}return t}function r(e){return function n(){for(var t=this,r=arguments.length,i=new Array(r),c=0;c<r;c++)i[c]=arguments[c];return i.length>=e.length?e.apply(this,i):function(){for(var e=arguments.length,r=new Array(e),c=0;c<e;c++)r[c]=arguments[c];return n.apply(t,[].concat(i,r))}}}function i(e){return{}.toString.call(e).includes("Object")}function c(e){return"function"==typeof e}var o=r(function(e,n){throw new Error(e[n]||e.default)})({initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"}),a={changes:function(e,n){return i(n)||o("changeType"),Object.keys(n).some(function(n){return t=e,r=n,!Object.prototype.hasOwnProperty.call(t,r);var t,r})&&o("changeField"),n},selector:function(e){c(e)||o("selectorType")},handler:function(e){c(e)||i(e)||o("handlerType"),i(e)&&Object.values(e).some(function(e){return!c(e)})&&o("handlersType")},initial:function(e){var n;e||o("initialIsRequired"),i(e)||o("initialType"),n=e,Object.keys(n).length||o("initialContent")}};function u(e,n){return c(n)?n(e.current):n}function l(e,n){return e.current=t(t({},e.current),n),n}function s(e,n,t){return c(n)?n(e.current):Object.keys(t).forEach(function(t){var r;return null===(r=n[t])||void 0===r?void 0:r.call(n,e.current[t])}),t}var f={create:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a.initial(e),a.handler(n);var t={current:e},i=r(s)(t,n),c=r(l)(t),o=r(a.changes)(e),f=r(u)(t);return[function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(e){return e};return a.selector(e),e(t.current)},function(e){!function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){return n.reduceRight(function(e,n){return n(e)},e)}}(i,c,o,f)(e)}]}};export{f as i};
