import * as n from "yup";
import { STRING_OPERATORS as d } from "../../../constants.js";
import { DYNAMIC_FILTER_DICTIONARY_ID as i, DICCTIONARY as l } from "../../../dictionary.js";
import { StringFilter as f } from "./index.js";
import { createValidationSchema as u, createValidationFullObject as s, createValidationPartialObject as m } from "../../../../hook-form/RHFormProvider/schema.js";
class V {
  getComponent() {
    return f;
  }
  /**
   * getDefaultFilter devuelve un filtro por defecto para un campo de cadena.
   */
  getDefaultFilter(r, t) {
    const e = r.defaultOperand1;
    let o = !1;
    e !== null && typeof e == "string" && (o = !0);
    const a = {
      id: 0,
      fieldType: "string",
      field: r,
      fixed: t,
      isSet: o,
      operator: "c",
      operand1: ""
    };
    return e !== void 0 && typeof e == "string" && (a.operand1 = e), a;
  }
  /**
   * getFilterFromFormValue convierte un valor de formulario en un valor de filtro.
   */
  getFilterFromFormValue(r) {
    const t = r.formValueOperator.id, e = r.formValueOperand1;
    return {
      fieldType: "string",
      operator: t,
      operand1: e
    };
  }
  /**
   * getFormValue convierte un valor de filtro en un valor de formulario.
   */
  getFormValue(r, t, e) {
    const o = e, a = o ? o.operator : r.defaultOperator ?? "c", p = o ? o.operand1 : "";
    return {
      fieldType: "string",
      formValueOperator: {
        id: a,
        label: t(`${i}.operator_${a}`)
      },
      formValueOperand1: p
    };
  }
  /**
   * getLabels devuelve las etiquetas para el filtro de cadena.
   */
  getLabels(r, t, e, o) {
    const a = r.operand1 !== void 0 ? r.operand1 + "" : "";
    return {
      labelField: r.field.label ?? t(r.field.dictionaryId),
      labelOperator: t(
        `${i}.operator_${r.operator}`
      ),
      labelOperands: a
    };
  }
  /**
   * getSchema devuelve el esquema de validación para el filtro de cadena.
   */
  getSchema(r, t) {
    return u(s(m({
      formValueOperator: n.object().nullable().required(r(l.error_operator_required)),
      formValueOperand1: n.string().required(
        r(l.error_operand_required)
      )
    })));
  }
  /**
   * getFilterValue devuelve el valor del filtro.
   */
  verifyFilter(r, t) {
    return !(typeof r.operator != "string" || d.findIndex((e) => e === r.operator) === -1 || typeof r.operand1 != "string");
  }
}
export {
  V as StringFilterHelpers
};
