import React from 'react';
import {COLOR_VERY_BAD, colorByDiff} from "../helpers/color";

import "./Misc.css";
import {diffString} from "../helpers/diff";

const Filter = ({bool, children}) => bool ? <>{children}</> : null;

export const StateFilter = ({current, required, children}) => (
  <Filter bool={current === required}>{children}</Filter>
);

export const Differ = ({diff, prevDiff}) => (
  <div className="Warning" style={{color: colorByDiff(diff, prevDiff)}}>
    {diffString(diff)}
  </div>
);

export const Info = ({children}) => (
  <div className="Info">
    {children}
  </div>
);

export const InfoTable = ({keyValuePairs}) => (
  <Info>
    <table>
      {keyValuePairs.map(({key, value}) => (
        <tr key={key}>
          <td>{key}:</td>
          <td><b>{value}</b></td>
        </tr>
      ))}
    </table>
  </Info>
);
