import * as i from "yup";
import { BOOLEAN_OPERATORS as u } from "../../../constants.js";
import { BooleanFilter as f } from "./index.js";
import { DYNAMIC_FILTER_DICTIONARY_ID as p, DICCTIONARY as d } from "../../../dictionary.js";
import { getFormatBoolean as s } from "../../../../formatters/BooleanFormatter/BooleanFormatter.js";
import { createValidationSchema as m, createValidationFullObject as c, createValidationPartialObject as b } from "../../../../hook-form/RHFormProvider/schema.js";
class v {
  getComponent() {
    return f;
  }
  /**
   * getDefaultFilter devuelve un filtro por defecto para un campo booleano.
   */
  getDefaultFilter(e, o) {
    const r = e.defaultOperand1;
    let t = !1;
    r !== void 0 && typeof r == "boolean" && (t = !0);
    const a = {
      id: 0,
      fieldType: "boolean",
      field: e,
      fixed: o,
      isSet: t,
      operator: "e",
      operand1: !0
    };
    return r !== void 0 && typeof r == "boolean" && (a.operand1 = r), a;
  }
  /**
   * getFilterFromFormValue convierte un valor de formulario en un valor de filtro.
   */
  getFilterFromFormValue(e) {
    const o = e.formValueOperator.id, r = e.formValueOperand1?.value || !1;
    return {
      fieldType: "boolean",
      operator: o,
      operand1: r
    };
  }
  /**
   * getFormValue convierte un valor de filtro en un valor de formulario.
   */
  getFormValue(e, o, r) {
    const t = r || void 0, a = t ? t.operator : e.defaultOperator ?? "e", l = t ? {
      value: t.operand1,
      label: o(
        `${p}.operand_${t.operand1}`
      )
    } : null;
    return {
      fieldType: "boolean",
      formValueOperator: {
        id: a,
        label: o(`${p}.operator_${a}`)
      },
      formValueOperand1: l
    };
  }
  /**
   * getLabel devuelve las etiquetas para el filtro booleano.
   */
  getLabels(e, o, r, t) {
    const a = e.field.presentationType, l = e.operand1;
    let n;
    return a && typeof a == "object" && "trueLabel" in a ? n = l ? a.trueLabel : a.falseLabel : n = s(a ?? "string_true_false", l, o), {
      labelField: e.field.label ?? o(e.field.dictionaryId),
      labelOperator: o(
        `${p}.operator_${e.operator}`
      ),
      labelOperands: n
    };
  }
  /**
   * getschema devuelve un esquema de validación para el filtro booleano.
   */
  getSchema(e, o) {
    return m(c(b({
      formValueOperator: i.object().nullable().required(e(d.error_operator_required)),
      formValueOperand1: i.object().nullable().required(e(d.error_operand_required))
    })));
  }
  /**
   * verifyFilter verifica si el filtro es válido.
   */
  verifyFilter(e, o) {
    return typeof e.operator != "string" || u.findIndex((r) => r === e.operator) === -1 ? !1 : typeof e.operand1 == "boolean";
  }
}
export {
  v as BooleanFilterHelpers
};
