"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/slicedToArray"),n=require("@babel/runtime/helpers/toConsumableArray"),e=require("@babel/runtime/helpers/defineProperty"),r=require("react"),a=require("prop-types"),o=require("./constants.js"),i=require("react/jsx-runtime");function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var c=u(t),d=u(n),s=u(e);function l(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),e.push.apply(e,r)}return e}function p(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{};n%2?l(Object(e),!0).forEach((function(n){s.default(t,n,e[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):l(Object(e)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}))}return t}var f=r.createContext(),O=r.createContext();function y(t,n){switch(n.type){case o.SET_ANNOTATIONS:return{annotations:n.annotations};case o.APPEND_ANNOTATIONS:return p(p({},t),{},{annotations:{data:[].concat(d.default(t.annotations.data),d.default(n.annotations.data)),included:n.annotations.included.reduce((function(t,n){return t.find((function(t){var e=t.id,r=t.type;return e===n.id&&r===n.type}))?t:t.concat([n])}),t.annotations.included)}});case o.ADD_ANNOTATION:return p(p({},t),{},{annotations:t.annotations.data?{data:[n.annotation.data].concat(d.default(t.annotations.data)),included:n.annotation.included.reduce((function(t,n){return t.find((function(t){var e=t.id,r=t.type;return e===n.id&&r===n.type}))?t:t.concat([n])}),t.annotations.included)}:{data:[n.annotation.data],included:n.annotation.included}});case o.DELETE_ANNOTATION:var e=t.annotations.data;return p(p({},t),{},{annotations:p(p({},t.annotations),{},{data:e.filter((function(t){return t.id!==n.id}))})});case o.EDIT_ANNOTATION:return p(p({},t),{},{annotations:p(p({},t.annotations),{},{data:t.annotations.data.map((function(t){return t.id===n.id?n.annotation.data:t})),included:n.annotation.included.reduce((function(t,n){return t.find((function(t){var e=t.id,r=t.type;return e===n.id&&r===n.type}))?t:t.concat([n])}),t.annotations.included)})});default:throw new Error("Unhandled action type: ".concat(n.type))}}function b(t){var n=t.children,e=r.useReducer(y,{annotations:[]}),a=c.default(e,2),o=a[0],u=a[1];return i.jsx(f.Provider,{value:o,children:i.jsx(O.Provider,{value:u,children:n})})}b.propTypes={children:a.node.isRequired},exports.AnnotationsProvider=b,exports.useAnnotationsDispatch=function(){var t=r.useContext(O);if(void 0===t)throw new Error("useAnnotationsDispatch must be used within a AnnotationsProvider");return t},exports.useAnnotationsState=function(){var t=r.useContext(f);if(void 0===t)throw new Error("useAnnotationsState must be used within a AnnotationsProvider");return t};
