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