import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/regenerator";import n from"prop-types";import{createContext as s,useState as a,useContext as c}from"react";import o from"./FeedItemEditModal.js";import"../../../utils/index.js";import{patchFeedItem as i}from"../../../clients/jsonApi/index.js";import{jsxs as u,jsx as l}from"react/jsx-runtime";import{showSuccessNotification as p}from"../../../utils/notificationToasts.js";var m=s(),d=function(n){var s,c=n.children,d=n.tracesMinDateSec,f=n.tracesMaxDateSec,x=n.tracesAssetId,b=n.exitFunc,S=a(null),v=t(S,2),y=v[0],M=v[1],h=function(){b(),M(null)},D=(s=e(r.mark((function e(t){return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,i(y.id,{context:t});case 3:e.next=9;break;case 5:return e.prev=5,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return");case 9:h(),p("Successfully updated");case 11:case"end":return e.stop()}}),e,null,[[0,5]])}))),function(e){return s.apply(this,arguments)});return u(m.Provider,{value:{editedFeedItem:y,setEditedFeedItem:M},children:[y&&l(o,{feedItem:y,onClose:h,onSave:function(e){var t=e.context;D(t)},tracesMinDateSec:d,tracesMaxDateSec:f,tracesAssetId:x}),c]})};function f(){return c(m)}d.propTypes={children:n.node.isRequired,tracesMinDateSec:n.oneOfType([n.string,n.number]),tracesMaxDateSec:n.oneOfType([n.string,n.number]),tracesAssetId:n.oneOfType([n.string,n.number]),exitFunc:n.func},d.defaultProps={tracesMinDateSec:null,tracesMaxDateSec:null,tracesAssetId:null,exitFunc:function(){return null}};export{d as FeedItemEditProvider,f as useFeedItemEditProvider};
