"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var LIMIT = 0.9;
var LEGS_LIMIT = 0.9;
var POSE_LANDMARKS = {
  NOSE: 0,
  LEFT_EYE_INNER: 1,
  LEFT_EYE: 2,
  LEFT_EYE_OUTER: 3,
  RIGHT_EYE_INNER: 4,
  RIGHT_EYE: 5,
  RIGHT_EYE_OUTER: 6,
  LEFT_EAR: 7,
  RIGHT_EAR: 8,
  LEFT_RIGHT: 9,
  RIGHT_LEFT: 10,
  LEFT_SHOULDER: 11,
  RIGHT_SHOULDER: 12,
  LEFT_ELBOW: 13,
  RIGHT_ELBOW: 14,
  LEFT_WRIST: 15,
  RIGHT_WRIST: 16,
  LEFT_PINKY: 17,
  RIGHT_PINKY: 18,
  LEFT_INDEX: 19,
  RIGHT_INDEX: 20,
  LEFT_THUMB: 21,
  RIGHT_THUMB: 22,
  LEFT_HIP: 23,
  RIGHT_HIP: 24,
  LEFT_KNEE: 25,
  RIGHT_KNEE: 26,
  LEFT_ANKLE: 27,
  RIGHT_ANKLE: 28,
  LEFT_HEEL: 29,
  RIGHT_HEEL: 30,
  LEFT_FOOT_INDEX: 31,
  RIGHT_FOOT_INDEX: 32
};

var getVisibility = function getVisibility(result) {
  var _result$poseLandmarks, _result$poseLandmarks2, _result$poseLandmarks3, _result$poseLandmarks4, _result$poseLandmarks5, _result$poseLandmarks6, _result$poseLandmarks7, _result$poseLandmarks8, _result$poseLandmarks9, _result$poseLandmarks10, _result$poseLandmarks11, _result$poseLandmarks12;

  return {
    rightElbow: (_result$poseLandmarks = result.poseLandmarks[POSE_LANDMARKS.RIGHT_ELBOW]) === null || _result$poseLandmarks === void 0 ? void 0 : _result$poseLandmarks.visibility,
    leftElbow: (_result$poseLandmarks2 = result.poseLandmarks[POSE_LANDMARKS.LEFT_ELBOW]) === null || _result$poseLandmarks2 === void 0 ? void 0 : _result$poseLandmarks2.visibility,
    rightShoulder: (_result$poseLandmarks3 = result.poseLandmarks[POSE_LANDMARKS.RIGHT_SHOULDER]) === null || _result$poseLandmarks3 === void 0 ? void 0 : _result$poseLandmarks3.visibility,
    leftSHoulder: (_result$poseLandmarks4 = result.poseLandmarks[POSE_LANDMARKS.LEFT_SHOULDER]) === null || _result$poseLandmarks4 === void 0 ? void 0 : _result$poseLandmarks4.visibility,
    rightHip: (_result$poseLandmarks5 = result.poseLandmarks[POSE_LANDMARKS.RIGHT_HIP]) === null || _result$poseLandmarks5 === void 0 ? void 0 : _result$poseLandmarks5.visibility,
    leftHip: (_result$poseLandmarks6 = result.poseLandmarks[POSE_LANDMARKS.LEFT_HIP]) === null || _result$poseLandmarks6 === void 0 ? void 0 : _result$poseLandmarks6.visibility,
    rightWrist: (_result$poseLandmarks7 = result.poseLandmarks[POSE_LANDMARKS.RIGHT_WRIST]) === null || _result$poseLandmarks7 === void 0 ? void 0 : _result$poseLandmarks7.visibility,
    leftWrist: (_result$poseLandmarks8 = result.poseLandmarks[POSE_LANDMARKS.LEFT_WRIST]) === null || _result$poseLandmarks8 === void 0 ? void 0 : _result$poseLandmarks8.visibility,
    rightKnee: (_result$poseLandmarks9 = result.poseLandmarks[POSE_LANDMARKS.RIGHT_KNEE]) === null || _result$poseLandmarks9 === void 0 ? void 0 : _result$poseLandmarks9.visibility,
    leftKnee: (_result$poseLandmarks10 = result.poseLandmarks[POSE_LANDMARKS.LEFT_KNEE]) === null || _result$poseLandmarks10 === void 0 ? void 0 : _result$poseLandmarks10.visibility,
    rightAnkle: (_result$poseLandmarks11 = result.poseLandmarks[POSE_LANDMARKS.RIGHT_ANKLE]) === null || _result$poseLandmarks11 === void 0 ? void 0 : _result$poseLandmarks11.visibility,
    leftAnkle: (_result$poseLandmarks12 = result.poseLandmarks[POSE_LANDMARKS.LEFT_ANKLE]) === null || _result$poseLandmarks12 === void 0 ? void 0 : _result$poseLandmarks12.visibility
  };
};

var resolve = function resolve(part1, part2, part3, limit) {
  if (limit === void 0) {
    limit = LIMIT;
  }

  return {
    part1: part1 > limit,
    part2: part2 > limit,
    part3: part3 > limit
  };
};

var getPartsValue = function getPartsValue(result, key) {
  var vsby = getVisibility(result);
  var points = {
    rShoulder: function rShoulder() {
      return resolve(vsby.rightElbow, vsby.rightShoulder, vsby.rightHip);
    },
    lShoulder: function lShoulder() {
      return resolve(vsby.leftElbow, vsby.leftSHoulder, vsby.leftHip);
    },
    rElbow: function rElbow() {
      return resolve(vsby.rightShoulder, vsby.rightElbow, vsby.rightWrist);
    },
    lElbow: function lElbow() {
      return resolve(vsby.leftSHoulder, vsby.leftElbow, vsby.leftWrist);
    },
    rHip: function rHip() {
      return resolve(vsby.rightKnee, vsby.rightHip, vsby.rightShoulder);
    },
    lHip: function lHip() {
      return resolve(vsby.leftKnee, vsby.leftHip, vsby.leftSHoulder);
    },
    rKnee: function rKnee() {
      return resolve(vsby.rightAnkle, vsby.rightKnee, vsby.rightHip);
    },
    lKnee: function lKnee() {
      return resolve(vsby.leftAnkle, vsby.leftKnee, vsby.leftHip);
    },
    rSide: function rSide() {
      return resolve(vsby.rightAnkle, vsby.rightHip, vsby.rightShoulder);
    },
    lSide: function lSide() {
      return resolve(vsby.leftAnkle, vsby.leftHip, vsby.leftSHoulder);
    },
    legs: function legs() {
      if (vsby.rightAnkle && vsby.rightKnee && vsby.rightHip) {
        return resolve(vsby.rightAnkle, vsby.rightKnee, vsby.rightHip, LEGS_LIMIT);
      }

      if (vsby.leftAnkle && vsby.leftKnee && vsby.leftHip) {
        return resolve(vsby.leftAnkle, vsby.leftKnee, vsby.leftHip, LEGS_LIMIT);
      }

      return {
        part1: false,
        part2: false,
        part3: false
      };
    }
  };
  return points[key]();
};

var getSideValue = function getSideValue(result, key) {
  var vsby = getVisibility(result);
  var points = {
    rShoulder: function rShoulder() {
      return vsby.rightElbow < vsby.leftElbow && vsby.rightShoulder < vsby.leftSHoulder && vsby.rightHip < vsby.leftHip;
    },
    lShoulder: function lShoulder() {
      return vsby.rightElbow > vsby.leftElbow && vsby.rightShoulder > vsby.leftSHoulder && vsby.rightHip > vsby.leftHip;
    },
    rElbow: function rElbow() {
      return vsby.rightShoulder < vsby.leftSHoulder && vsby.rightElbow < vsby.leftElbow && vsby.rightWrist < vsby.leftWrist;
    },
    lElbow: function lElbow() {
      return vsby.rightShoulder > vsby.leftSHoulder && vsby.rightElbow > vsby.leftElbow && vsby.rightWrist > vsby.leftWrist;
    },
    rHip: function rHip() {
      return vsby.rightKnee < vsby.leftKnee && vsby.rightHip < vsby.leftHip && vsby.rightShoulder < vsby.leftSHoulder;
    },
    lHip: function lHip() {
      return vsby.rightKnee > vsby.leftKnee && vsby.rightHip > vsby.leftHip && vsby.rightShoulder > vsby.leftSHoulder;
    },
    rKnee: function rKnee() {
      return vsby.rightAnkle < vsby.leftAnkle && vsby.rightKnee < vsby.leftKnee && vsby.rightHip < vsby.leftHip;
    },
    lKnee: function lKnee() {
      return vsby.rightAnkle > vsby.leftAnkle && vsby.rightKnee > vsby.leftKnee && vsby.rightHip > vsby.leftHip;
    },
    rSide: function rSide() {
      return vsby.rightAnkle < vsby.leftAnkle && vsby.rightHip < vsby.leftHip && vsby.rightShoulder < vsby.leftSHoulder;
    },
    lSide: function lSide() {
      return vsby.rightAnkle > vsby.leftAnkle && vsby.rightHip > vsby.leftHip && vsby.rightShoulder > vsby.leftSHoulder;
    },
    legs: function legs() {
      return false;
    }
  };
  return points[key]();
};

var visiblePoints = function visiblePoints(key, result) {
  try {
    var parts = getPartsValue(result, key);
    var incorrectSide = getSideValue(result, key);
    return {
      parts: parts,
      incorrectSide: incorrectSide
    };
  } catch (error) {
    throw new Error("error: " + error);
  }
};

var _default = {
  visiblePoints: visiblePoints
};
exports["default"] = _default;
module.exports = exports.default;