import { useContext } from "react";
import { obfuscate } from "../utils/obfuscateStrings";
import { SensitiveInfoContext } from "../providers/contexts";

const useSensitiveInfo = () => {
  const { state, actions } = useContext(SensitiveInfoContext);
  const { enabled } = state;
  const { onSensitiveInfoEnabled } = actions;

  const mask = text => {
    if (!enabled) return text;
    return obfuscate(text, "◾");
  };

  const maskElements = list => {
    if (!enabled) return list;
    const maskedList = list.map(z => obfuscate(z, "◻️"));
    return maskedList;
  };

  return { enabled, onSensitiveInfoEnabled, mask, maskElements };
};

export default useSensitiveInfo;
