"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.DEFAULT_HAMMER_PATTERN_UNCONFIRMED_CONFIG = void 0;
exports.hammerpatternunconfirmed = hammerpatternunconfirmed;
var _HammerPattern = _interopRequireWildcard(require("./HammerPattern"));
var _BearishHammerStick = require("./BearishHammerStick");
var _BearishInvertedHammerStick = require("./BearishInvertedHammerStick");
var _BullishHammerStick = require("./BullishHammerStick");
var _BullishInvertedHammerStick = require("./BullishInvertedHammerStick");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * Configuration interface for HammerPatternUnconfirmed.
 * Extends HammerPattern configuration.
 */

/**
 * Default configuration for HammerPatternUnconfirmed.
 */
const DEFAULT_HAMMER_PATTERN_UNCONFIRMED_CONFIG = exports.DEFAULT_HAMMER_PATTERN_UNCONFIRMED_CONFIG = {
  ..._HammerPattern.DEFAULT_HAMMER_PATTERN_CONFIG,
  ..._BullishHammerStick.DEFAULT_BULLISH_HAMMER_CONFIG,
  ..._BullishInvertedHammerStick.DEFAULT_BULLISH_INVERTED_HAMMER_STICK_CONFIG,
  ..._BearishHammerStick.DEFAULT_BEARISH_HAMMER_STICK_CONFIG,
  ..._BearishInvertedHammerStick.DEFAULT_BEARISH_INVERTED_HAMMER_CONFIG
};
class HammerPatternUnconfirmed extends _HammerPattern.default {
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_HAMMER_PATTERN_UNCONFIRMED_CONFIG,
      ...config
    };
    super(finalConfig);
    this.name = 'HammerPatternUnconfirmed';
    this.requiredCount = 4; // Reduced from 5 since no confirmation needed
  }
  logic(data) {
    // Validate data integrity first
    for (let i = 0; i < data.close.length; i++) {
      if (!this.validateOHLC(data.open[i], data.high[i], data.low[i], data.close[i])) {
        return false;
      }
    }

    // Check for downward trend and hammer pattern without confirmation
    // Pass false to indicate this is an unconfirmed pattern
    let isPattern = this.downwardTrend(data, false);
    isPattern = isPattern && this.includesHammer(data, false);
    return isPattern;
  }

  // Override the downwardTrend method to be more lenient for unconfirmed patterns
  downwardTrend(data, confirm = true) {
    // Ensure we have enough data
    if (data.close.length < (confirm ? 5 : 4)) {
      return false;
    }

    // For unconfirmed patterns, we need at least 3 candles before the hammer
    // to establish a downward trend
    let trendLength = confirm ? 3 : 3;
    let trendData = data.close.slice(0, trendLength);

    // Simple downward trend check: first close > last close in trend
    let hasOverallDecline = trendData[0] > trendData[trendLength - 1];

    // Additional check: ensure there's meaningful price movement
    let priceRange = Math.max(...trendData) - Math.min(...trendData);
    let minMovement = priceRange * 0.02; // At least 2% movement

    // Check for at least one significant down move
    let hasSignificantMove = false;
    for (let i = 1; i < trendLength; i++) {
      if (trendData[i - 1] - trendData[i] >= minMovement) {
        hasSignificantMove = true;
        break;
      }
    }
    return hasOverallDecline && hasSignificantMove;
  }

  // Override includesHammer to work with 4 candles instead of 5
  includesHammer(data, confirm = true) {
    // Ensure we have the required data
    if (data.close.length < (confirm ? 5 : 4)) {
      return false;
    }

    // For unconfirmed pattern, check for hammer at the last index (index 3)
    let hammerIndex = confirm ? 3 : 3;
    let possibleHammerData = {
      open: [data.open[hammerIndex]],
      close: [data.close[hammerIndex]],
      low: [data.low[hammerIndex]],
      high: [data.high[hammerIndex]]
    };

    // Use the appropriate function signatures - mix of updated and not yet updated
    let isPattern = (0, _BearishHammerStick.bearishhammerstick)(possibleHammerData, this.config);
    isPattern = isPattern || (0, _BearishInvertedHammerStick.bearishinvertedhammerstick)(possibleHammerData, this.config);
    isPattern = isPattern || (0, _BullishHammerStick.bullishhammerstick)(possibleHammerData, this.config);
    isPattern = isPattern || (0, _BullishInvertedHammerStick.bullishinvertedhammerstick)(possibleHammerData, this.config);
    return isPattern;
  }
}
exports.default = HammerPatternUnconfirmed;
function hammerpatternunconfirmed(data, config = DEFAULT_HAMMER_PATTERN_UNCONFIRMED_CONFIG) {
  return new HammerPatternUnconfirmed(config).hasPattern(data);
}
//# sourceMappingURL=HammerPatternUnconfirmed.js.map