import { withSchema } from '@websolutespa/bom-core';
import React, { ReactNode } from 'react';
import { pickChild } from '../utils';

const ReversableLeft = (props: { children: ReactNode }) => {
  return (props.children);
};

const ReversableRight = (props: { children: ReactNode }) => {
  return (props.children);
};

export const ReversableBase = (props: {
  reverse: boolean,
  children: ReactNode,
  render: (left: ReactNode, right: ReactNode, reverse: boolean) => React.ReactNode
}) => {
  const [left] = pickChild(ReversableLeft, props.children);
  const [right] = pickChild(ReversableRight, props.children);
  return props.render(left, right, props.reverse);
};

export const Reversable = withSchema(
  ReversableBase,
  {
    Left: ReversableLeft,
    Right: ReversableRight,
  });
