import { jsxs as i, jsx as o } from "@emotion/react/jsx-runtime";
import { useEnvironment as w, useModuleDictionary as D } from "@m4l/core";
import { useState as N, useRef as A, useMemo as V } from "react";
import * as j from "yup";
import { shallow as C } from "zustand/shallow";
import z from "@mui/material/ButtonBase/TouchRipple";
import { useAreasStore as m } from "../../../../../../hooks/useAreas/index.js";
import { getAreasDictionary as a, AREAS_DICCTIONARY as s } from "../../../../../../dictionary.js";
import { Typography as F } from "@m4l/base";
import { ICONS as d } from "../../../../../../icons.js";
import { ChipActionsMobile as L } from "../../../AreaChip/subcomponents/ChipActionsMobile/ChipActionsMobile.js";
import { ChipMobileRootStyled as B, ChipMobileContentStyled as H, NameChipMobileStyled as Y, EditAreaChipMobileContainerStyled as q } from "../../../../slots/AreasAdminSlots.js";
import { RHFormProvider as U } from "../../../../../../../hook-form/RHFormProvider/RHFormProvider.js";
import { ActionsContainer as G } from "../../../../../../../CommonActions/components/ActionsContainer/ActionsContainer.js";
import { createValidationSchema as J, createValidationFullObject as K, createValidationPartialObject as Q } from "../../../../../../../hook-form/RHFormProvider/schema.js";
import { MenuActions as W } from "../../../../../../../MenuActions/MenuActions.js";
import { Popover as X } from "../../../../../../../extended/mui/Popover/Popover.js";
import { RHFTextField as Z } from "../../../../../../../hook-form/RHFTextField/RHFTextField.js";
import { ActionCancel as ee } from "../../../../../../../CommonActions/components/ActionCancel/ActionCancel.js";
import { ActionIntro as oe } from "../../../../../../../CommonActions/components/ActionIntro/ActionIntro.js";
const te = z, re = (b) => {
  const { areaId: r, selected: E, disabled: g, setAnchorMenuAreas: h } = b, { host_static_assets: l, environment_assets: c } = w(), { deleteArea: _, selectArea: v, editArea: R } = m((e) => e.areasActions), f = m((e) => e.hashAreas[r].name, C), y = m((e) => e.areasIds, C), [M, n] = N(!1), { getLabel: t } = D(), u = A(null), S = (e) => {
    y.length > 1 && (e.stopPropagation(), _(r));
  }, I = (e) => {
    R(r, e.inputEditArea), n(!1);
  }, O = (e) => {
    e?.stopPropagation(), n(!0);
  }, T = {
    inputEditArea: f
  }, $ = V(
    () => J(K(Q({
      inputEditArea: j.string().required(
        t(a(s.validation_edit_area))
      )
    }))),
    [t]
  ), x = (e) => {
    h && h(e.currentTarget), v(r);
  }, p = A(null), P = (e) => {
    p.current && p.current.stop(e);
  }, k = [
    {
      type: "menuItem",
      startIcon: `${l}/${c}/frontend/components/areas/assets/icons/${d.EDIT_AREA}`,
      label: `${t(a(s.label_edit_area))}`,
      onClick: O
    },
    {
      type: "menuItem",
      startIcon: `${l}/${c}/frontend/components/areas/assets/icons/${d.DELETE_AREA}`,
      label: `${t(a(s.label_delete_area))}`,
      onClick: S,
      color: "error"
    }
  ];
  return /* @__PURE__ */ i(B, { selected: E, disabled: g, children: [
    /* @__PURE__ */ i(
      H,
      {
        role: "presentation",
        ref: u,
        onMouseUp: P,
        onClick: (e) => {
          x(e);
        },
        children: [
          /* @__PURE__ */ o(te, { ref: p, center: !1 }),
          /* @__PURE__ */ o(Y, { variant: "bodyStandard", children: `${f}` }),
          /* @__PURE__ */ o(
            W,
            {
              icon: `${l}/${c}/frontend/components/window_base/assets/icons/${d.MORE_VERTICAL}`,
              arrowType: "no-arrow",
              anchorOrigin: { vertical: "bottom", horizontal: "right" },
              transformOrigin: { vertical: "top", horizontal: "right" },
              menuActions: k
            }
          )
        ]
      }
    ),
    /* @__PURE__ */ o(
      L,
      {}
    ),
    /* @__PURE__ */ o(
      "div",
      {
        role: "presentation",
        onClick: (e) => {
          e.stopPropagation();
        },
        children: /* @__PURE__ */ o(
          X,
          {
            arrowType: "top-center",
            open: M,
            anchorEl: u.current,
            anchorOrigin: { vertical: "bottom", horizontal: "center" },
            transformOrigin: { vertical: "top", horizontal: "center" },
            onClose: () => {
              n(!1);
            },
            sx: {
              "& .MuiPaper-root": {
                marginTop: "10px"
              }
            },
            children: /* @__PURE__ */ i(
              U,
              {
                onSubmit: I,
                values: T,
                validationSchema: $,
                children: [
                  /* @__PURE__ */ o(q, { children: /* @__PURE__ */ o(F, { children: t(a(s.label_edit_area)) }) }),
                  /* @__PURE__ */ o(
                    Z,
                    {
                      name: "inputEditArea",
                      sx: { mt: "20px" }
                    }
                  ),
                  /* @__PURE__ */ i(G, { children: [
                    /* @__PURE__ */ o(
                      ee,
                      {
                        onClick: () => {
                          n(!1);
                        },
                        variant: "outlined"
                      }
                    ),
                    /* @__PURE__ */ o(oe, {})
                  ] })
                ]
              }
            )
          }
        )
      }
    )
  ] });
};
re.displayName = "AreaButtons";
export {
  re as ChipMobile
};
