import { jsxs as b, jsx as m } from "@emotion/react/jsx-runtime";
import { useModuleDictionary as z, useEnvironment as C } from "@m4l/core";
import { ETimePeriods as e } from "./types.js";
import { DICTIONARY as l } from "./dictionary.js";
import { useComponentSize as D } from "../../../../../hooks/useComponentSize/index.js";
import { Icon as L } from "@m4l/base";
import { useMemo as P } from "react";
import { PeriodRootStyled as _, SelectStyled as I, NumberInputStyled as M } from "../../slots/RHFPeriodSlots.js";
const F = (h) => {
  const {
    value: u,
    onChange: A,
    size: d,
    error: c,
    disabled: r
  } = h, { getLabel: o } = z(), { currentSize: i } = D(d), { host_static_assets: E, environment_assets: T } = C(), S = P(
    () => [
      { id: e.YEARS.toString(), label: o(l.LABEL_YEARS) },
      { id: e.MONTHS.toString(), label: o(l.LABEL_MONTHS) },
      { id: e.DAYS.toString(), label: o(l.LABEL_DAYS) }
    ],
    [o]
  ), Y = (t) => t ? t.singleValue !== void 0 ? t.singleValue : t.years && t.years > 0 ? t.years : t.months && t.months > 0 ? t.months : t.days && t.days > 0 ? t.days : null : null, v = (t) => t ? t.selPeriodTime ? t.selPeriodTime : t.years && t.years > 0 ? e.YEARS : t.months && t.months > 0 ? e.MONTHS : t.days && t.days > 0 ? e.DAYS : e.YEARS : e.YEARS, f = Y(u), y = v(u), g = (t, n) => {
    const a = typeof t == "string" ? parseInt(t) : t, s = {
      selPeriodTime: a,
      singleValue: n
    };
    n && n > 0 && (s.years = 0, s.months = 0, s.days = 0, a === e.YEARS && (s.years = n), a === e.MONTHS && (s.months = n), a === e.DAYS && (s.days = n)), A(s);
  }, R = (t) => {
    t && g(t.id, f);
  };
  return /* @__PURE__ */ b(_, { ownerState: {
    size: i,
    disabled: r
  }, children: [
    /* @__PURE__ */ m(
      L,
      {
        size: i,
        src: `${E}/${T}/frontend/components/period/assets/icons/clock.svg`,
        disabled: r
      }
    ),
    /* @__PURE__ */ m(
      I,
      {
        size: i,
        value: S[y].id,
        options: S,
        onChange: (t) => {
          R(t);
        },
        disabled: r,
        error: !!c
      }
    ),
    /* @__PURE__ */ m(
      M,
      {
        type: "number",
        size: i,
        variant: "outlined",
        value: f,
        withDecimal: !0,
        disabled: r,
        error: !!c,
        onChange: (t, n) => {
          g(y, n);
        }
      }
    )
  ] });
};
export {
  F as Period
};
