import { stringActions } from "../../apis";
import moment from "moment";
import { File, Paths } from "expo-file-system";
// import * as FaceDetector from 'expo-face-detector';

const detectFaces = async (remoteUrl) => {
	// deprecated

	const parts = remoteUrl.split("/").splice(-2);
	const mediaId = parts[0];
	const extension = parts[1]?.split(".").splice(-1)[0] || "jpg";

	const file = await File.downloadFileAsync(
		remoteUrl,
		new File(Paths.cache, `${mediaId}.${extension}`),
		{ idempotent: true },
	);
	const localUrl = file.uri;

	// const faces = await FaceDetector.detectFacesAsync(localUrl, {
	//   mode: FaceDetector.FaceDetectorMode.accurate,
	// });

	const faces = null;

	if (faces && faces.image && faces.image.uri) {
		delete faces.image.uri;
	}

	faces.timestamp = moment().valueOf();

	stringActions.setString(
		"plussSpace",
		`imagefaces_${encodeURIComponent(remoteUrl)}`,
		faces,
	);

	return faces;
};

export default detectFaces;
