import { Typography } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectScanLastScanned } from "../../../redux/scan/scan.selectors";
import TimeAgoFormatter from "../../atoms/time-ago-formatter/time-ago-formatter.atom";

const mapStateToProps = createStructuredSelector({
  lastScanned: selectScanLastScanned,
});
const mapDispatchToProps = (dispatch) => ({});

export function LastScannedAtom({ lastScanned }) {
  return (
    lastScanned && (
      <Typography.Title level={5}>
        <span>Last scanned </span>
        <TimeAgoFormatter>{lastScanned}</TimeAgoFormatter>
      </Typography.Title>
    )
  );
}
export default connect(mapStateToProps, mapDispatchToProps)(LastScannedAtom);
