"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DEFAULT_ABANDONED_BABY_CONFIG = void 0;
exports.abandonedbaby = abandonedbaby;
exports.default = void 0;
var _CandlestickFinder = _interopRequireWildcard(require("./CandlestickFinder"));
var _Doji = _interopRequireWildcard(require("./Doji"));
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 AbandonedBaby pattern.
 * Only requires scale parameter since this pattern uses direct price comparisons.
 */

/**
 * Default configuration for AbandonedBaby pattern.
 */
const DEFAULT_ABANDONED_BABY_CONFIG = exports.DEFAULT_ABANDONED_BABY_CONFIG = {
  ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG,
  ..._Doji.DEFAULT_DOJI_CONFIG
};
class AbandonedBaby extends _CandlestickFinder.default {
  config;
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_ABANDONED_BABY_CONFIG,
      ...config
    };
    super(finalConfig);
    this.name = 'AbandonedBaby';
    this.requiredCount = 3;
    this.config = finalConfig;
  }
  logic(data) {
    // Correct indexing: [0]=first day (oldest), [1]=doji (middle), [2]=third day (newest)
    let firstdaysOpen = data.open[0]; // First day (oldest)
    let firstdaysClose = data.close[0];
    let firstdaysHigh = data.high[0];
    let firstdaysLow = data.low[0];
    let seconddaysOpen = data.open[1]; // Second day (middle - doji)
    let seconddaysClose = data.close[1];
    let seconddaysHigh = data.high[1];
    let seconddaysLow = data.low[1];
    let thirddaysOpen = data.open[2]; // Third day (newest)
    let thirddaysClose = data.close[2];
    let thirddaysHigh = data.high[2];
    let thirddaysLow = data.low[2];
    let isFirstBearish = firstdaysClose < firstdaysOpen;
    let dojiExists = new _Doji.default(this.config).hasPattern({
      "open": [seconddaysOpen],
      "close": [seconddaysClose],
      "high": [seconddaysHigh],
      "low": [seconddaysLow]
    });

    // Gap detection:
    // Gap 1: Doji high < First day low (gap down from first to second day)
    // Gap 2: Third day low > Doji high (gap up from second to third day)
    let gapExists = seconddaysHigh < firstdaysLow && thirddaysLow > seconddaysHigh;
    let isThirdBullish = thirddaysClose > thirddaysOpen;
    return isFirstBearish && dojiExists && gapExists && isThirdBullish;
  }
}

/**
 * Detects Abandoned Baby candlestick pattern in the provided stock data.
 *
 * An Abandoned Baby is a rare three-candle reversal pattern consisting of:
 * 1. A bearish candle
 * 2. A doji that gaps down from the first candle
 * 3. A bullish candle that gaps up from the doji
 * This pattern indicates a strong reversal from bearish to bullish sentiment.
 *
 * @param data - Stock data containing OHLC values for at least 3 periods
 * @param config - Configuration object for pattern detection
 * @param config.scale - Scale parameter for approximateEqual function precision (default: 0.001)
 * @returns True if Abandoned Baby pattern is detected, false otherwise
 *
 * @example
 * ```typescript
 * // Using default configuration
 * const hasAbandonedBabyPattern = abandonedbaby(stockData);
 *
 * // Using custom configuration
 * const hasAbandonedBabyPattern = abandonedbaby(stockData, {
 *   scale: 0.002
 * });
 *
 * // Backward compatibility with scale parameter
 * const hasAbandonedBabyPattern = abandonedbaby(stockData, { scale: 0.002 });
 * ```
 */
exports.default = AbandonedBaby;
function abandonedbaby(data, config = DEFAULT_ABANDONED_BABY_CONFIG) {
  return new AbandonedBaby(config).hasPattern(data);
}
//# sourceMappingURL=AbandonedBaby.js.map