"use strict";

exports.__esModule = true;
exports["default"] = void 0;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var HolisticPoseValidator = /*#__PURE__*/function () {
  function HolisticPoseValidator() {
    _defineProperty(this, "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 _proto = HolisticPoseValidator.prototype;

  _proto.getNameAndValueByPart = function getNameAndValueByPart(result, key) {
    switch (key) {
      case 'rShoulder':
        if (result.poseLandmarks[14] && result.poseLandmarks[12] && result.poseLandmarks[24]) {
          return [{
            name: 'Right elbow',
            value: result.poseLandmarks[14]
          }, {
            name: 'Right shoulder',
            value: result.poseLandmarks[12]
          }, {
            name: 'Right hip',
            value: result.poseLandmarks[24]
          }];
        }

        break;

      case 'lShoulder':
        if (result.poseLandmarks[13] && result.poseLandmarks[11] && result.poseLandmarks[23]) {
          return [{
            name: 'Left elbow',
            value: result.poseLandmarks[13]
          }, {
            name: 'Left shoulder',
            value: result.poseLandmarks[11]
          }, {
            name: 'Left hip',
            value: result.poseLandmarks[23]
          }];
        }

        break;

      case 'rElbow':
        if (result.rightHandLandmarks && result.poseLandmarks[12] && result.poseLandmarks[12] && result.rightHandLandmarks[0]) {
          return [{
            name: 'Right shoulder',
            value: result.poseLandmarks[12]
          }, {
            name: 'Right elbow',
            value: result.poseLandmarks[14]
          }, {
            name: 'Right wrist',
            value: result.rightHandLandmarks[0]
          }];
        }

        break;

      case 'lElbow':
        if (result.leftHandLandmarks && result.poseLandmarks[11] && result.poseLandmarks[13] && result.leftHandLandmarks[0]) {
          return [{
            name: 'Left shoulder',
            value: result.poseLandmarks[11]
          }, {
            name: 'Left elbow',
            value: result.poseLandmarks[13]
          }, {
            name: 'Left wrist',
            value: result.leftHandLandmarks[0]
          }];
        }

        break;

      case 'rHip':
        if (result.poseLandmarks[26] && result.poseLandmarks[24] && result.poseLandmarks[12]) {
          return [{
            name: 'Right knee',
            value: result.poseLandmarks[26]
          }, {
            name: 'Right hip',
            value: result.poseLandmarks[24]
          }, {
            name: 'Right shoulder',
            value: result.poseLandmarks[12]
          }];
        }

        break;

      case 'lHip':
        if (result.poseLandmarks[25] && result.poseLandmarks[23] && result.poseLandmarks[11]) {
          return [{
            name: 'Left knee',
            value: result.poseLandmarks[25]
          }, {
            name: 'Left hip',
            value: result.poseLandmarks[23]
          }, {
            name: 'Left shoulder',
            value: result.poseLandmarks[11]
          }];
        }

        break;

      case 'rKnee':
        if (result.poseLandmarks[28] && result.poseLandmarks[26] && result.poseLandmarks[24]) {
          return [{
            name: 'Right ankle',
            value: result.poseLandmarks[28]
          }, {
            name: 'Right knee',
            value: result.poseLandmarks[26]
          }, {
            name: 'Right hip',
            value: result.poseLandmarks[24]
          }];
        }

        break;

      case 'lKnee':
        if (result.poseLandmarks[27] && result.poseLandmarks[25] && result.poseLandmarks[23]) {
          return [{
            name: 'Left ankle',
            value: result.poseLandmarks[27]
          }, {
            name: 'Left knee',
            value: result.poseLandmarks[25]
          }, {
            name: 'Left hip',
            value: result.poseLandmarks[23]
          }];
        }

        break;

      case 'rSide':
        if (result.poseLandmarks[28] && result.poseLandmarks[24] && result.poseLandmarks[12]) {
          return [{
            name: 'Right ankle',
            value: result.poseLandmarks[27]
          }, {
            name: 'Right hip',
            value: result.poseLandmarks[23]
          }, {
            name: 'Right shoulder',
            value: result.poseLandmarks[11]
          }];
        }

        break;

      case 'lSide':
        if (result.poseLandmarks[27] && result.poseLandmarks[23] && result.poseLandmarks[11]) {
          return [{
            name: 'Left ankle',
            value: result.poseLandmarks[27]
          }, {
            name: 'Left hip',
            value: result.poseLandmarks[23]
          }, {
            name: 'Left shoulder',
            value: result.poseLandmarks[11]
          }];
        }

        break;

      default:
        throw new Error("Unknowing Key " + key);
    }
  };

  _proto.visiblePoints = function visiblePoints(key, result) {
    try {
      var parts = this.getNameAndValueByPart(result, key);
      return {
        part1: parts && parts.length > 0 && parts[0].value.visibility < 0.5 ? parts[0].name : null,
        part2: parts && parts.length > 0 && parts[1].value.visibility < 0.5 ? parts[1].name : null,
        part3: parts && parts.length > 0 && parts[2].value.visibility < 0.5 ? parts[2].name : null
      };
    } catch (error) {
      throw new Error("error: " + error);
    }
  };

  return HolisticPoseValidator;
}();

exports["default"] = HolisticPoseValidator;
module.exports = exports.default;