import React from 'react';
import { PortalContext } from './portal-context';
import { PortalService } from './portal-service';

type TProps = {
  children: React.ReactElement[];
};

export const PortalProvider: React.FC<TProps> = ({ children }) => {
  return (
    <PortalContext.Provider
      value={{
        teleport: (params: { id: string; children: React.ReactElement }) =>
          PortalService.teleport(params),
        unload: (id: string) => PortalService.unload(id),
      }}
    >
      {children}
    </PortalContext.Provider>
  );
};
