import React from "react";
import { Switch } from "react-native-paper";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { toggleDeleteAfterUpload } from "../../redux/app/app.actions";
import { selectDeleteAfterUpload } from "../../redux/app/app.selectors";

const mapStateToProps = createStructuredSelector({
  deleteAfterUpload: selectDeleteAfterUpload,
});

const mapDispatchToProps = (dispatch) => ({
  toggleDeleteAfterUpload: () => dispatch(toggleDeleteAfterUpload()),
});

export function UploadDeleteSwitch({
  deleteAfterUpload,
  toggleDeleteAfterUpload,
}) {
  return (
    <Switch
      onValueChange={() => {
        toggleDeleteAfterUpload();
      }}
      value={deleteAfterUpload}
    />
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(UploadDeleteSwitch);
