import { jsxs as c, jsx as a } from "react/jsx-runtime";
import { Button as f, ButtonTypes as N } from "./index-Button.js";
import { CheckBox as k } from "./index-CheckBox.js";
import { IconNames as B } from "./index-IconNames.js";
import { Render as v } from "./index-Render.js";
import { StatusBadge as T } from "./index-StatusBadge.js";
import { Text as j, TextTypes as I, FontWeights as L } from "./index-Text.js";
import { useState as p, useMemo as V } from "react";
import n from "./index-MultiSelectDrawer.module.scss.js";
const z = (S) => {
  const {
    title: b,
    description: o,
    value: g,
    options: d,
    minSelected: m = 0,
    onSave: C,
    onClose: r
  } = S, [s, x] = p(d.reduce((e, t) => (e[t.value] = g.includes(t.value), e), {})), [u, h] = p(!1), w = async () => {
    const e = Object.entries(s).filter(([i, l]) => l).map(([i]) => i), t = C(e);
    typeof t == "object" && (h(!0), await t, h(!1)), r();
  }, y = (e, t) => {
    x((i) => {
      const l = {
        ...i
      };
      return l[e] = t, l;
    });
  }, D = V(() => Object.entries(s).filter(([e, t]) => t).length < m, [s, m]);
  return c("div", {
    className: n.textEditDrawerContainer,
    children: [a(j, {
      className: n.textEditDrawerTitle,
      fontWeight: L.bold,
      type: I.heading2,
      children: b
    }), a(v, {
      if: !!o,
      children: o
    }), a("div", {
      className: n.optionsContainer,
      children: d.map((e) => c("div", {
        className: n.multiSelectDrawerOption,
        children: [a(k, {
          label: e.label,
          checked: s[e.value],
          disabled: e.disabled,
          onChange: ({
            target: t
          }) => y(e.value, t.checked),
          translate: e.translate
        }), a(v, {
          if: !!e.status,
          children: a(T, {
            ...e.status,
            hideIcon: !0
          })
        })]
      }, e.label))
    }), c("div", {
      className: n.textEditDrawerActionsContainer,
      children: [a(f, {
        onClick: w,
        iconLeft: B.save,
        isLoading: u,
        disabled: D,
        children: "Save"
      }), a(f, {
        type: N.default,
        onClick: r,
        disabled: u,
        children: "Cancel"
      })]
    })]
  });
};
export {
  z as MultiSelectDrawer
};
