import React from "react";
import { Platform } from "react-native";
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={Platform.OS === "android" ? false : deleteAfterUpload}
      disabled={Platform.OS === "android"}
    />
  );
}

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