import { defineComponent as $, computed as v, openBlock as i, createBlock as w, mergeProps as O, withCtx as u, createElementVNode as s, createElementBlock as c, withDirectives as y, vModelCheckbox as h, withModifiers as _, createVNode as b, withKeys as x, createTextVNode as B, toDisplayString as V, unref as A, createCommentVNode as E, Fragment as K, renderList as N } from "vue";
import { t as D } from "./locale.js";
import { _ as F } from "./Field.vue_vue_type_script_setup_true_lang-CJUQxQdh.js";
import g from "./FilterChip.js";
const I = { class: "flex flex-wrap gap-1.5" }, L = ["id"], T = ["for"], M = ["id", "value"], R = ["for", "onClick"], z = /* @__PURE__ */ $({
  __name: "FilterSelect",
  props: {
    name: {},
    options: {},
    modelValue: {},
    canSelectAll: { type: Boolean, default: !1 },
    addBottomSpace: { type: Boolean },
    errorText: {},
    hintText: {},
    id: {},
    errorId: {},
    isReadOnly: { type: Boolean },
    isRequired: { type: Boolean },
    label: {},
    showOptionalInLabel: { type: Boolean },
    isLabelSrOnly: { type: Boolean },
    fieldset: { type: Boolean },
    isDisabled: { type: Boolean },
    disabled: { type: Boolean }
  },
  emits: ["update:modelValue"],
  setup(k, { emit: S }) {
    const e = k, p = S, o = v({
      get() {
        return e.modelValue;
      },
      set(t) {
        p("update:modelValue", t);
      }
    }), n = v({
      get() {
        return e.options.length === e.modelValue.length;
      },
      set(t) {
        p("update:modelValue", t ? e.options.map((a) => a.value) : []);
      }
    });
    function r(t) {
      return `${e.name}--${t.value}`;
    }
    function C(t) {
      return e.modelValue.includes(t.value);
    }
    function m(t) {
      const a = o.value.filter((l) => l !== t);
      a.length === o.value.length && a.push(t), o.value = a;
    }
    function f() {
      n.value = !n.value;
    }
    return (t, a) => (i(), w(F, O(e, {
      class: "stash-filter-select",
      "data-test": "stash-filter-select",
      fieldset: ""
    }), {
      default: u(() => [
        s("div", I, [
          e.canSelectAll ? (i(), c("div", {
            key: `${e.name}--all`
          }, [
            y(s("input", {
              id: `${e.name}--all`,
              "onUpdate:modelValue": a[0] || (a[0] = (l) => n.value = l),
              class: "sr-only",
              tabindex: "-1",
              type: "checkbox",
              value: "all"
            }, null, 8, L), [
              [h, n.value]
            ]),
            s("label", {
              for: `${e.name}--all`,
              onClick: _(f, ["prevent"])
            }, [
              b(g, {
                "is-selected": n.value,
                tabindex: "0",
                onKeypress: x(f, ["enter"])
              }, {
                default: u(() => [
                  B(V(A(D)("ll.all")), 1)
                ]),
                _: 1
              }, 8, ["is-selected"])
            ], 8, T)
          ])) : E("", !0),
          (i(!0), c(K, null, N(e.options, (l) => (i(), c("div", {
            key: r(l)
          }, [
            y(s("input", {
              id: r(l),
              "onUpdate:modelValue": a[1] || (a[1] = (d) => o.value = d),
              class: "sr-only",
              tabindex: "-1",
              type: "checkbox",
              value: l.value
            }, null, 8, M), [
              [h, o.value]
            ]),
            s("label", {
              for: r(l),
              onClick: _((d) => m(l.value), ["prevent"])
            }, [
              b(g, {
                "is-selected": C(l),
                tabindex: "0",
                onKeypress: x((d) => m(l.value), ["enter"])
              }, {
                default: u(() => [
                  B(V(l.label), 1)
                ]),
                _: 2
              }, 1032, ["is-selected", "onKeypress"])
            ], 8, R)
          ]))), 128))
        ])
      ]),
      _: 1
    }, 16));
  }
});
export {
  z as default
};
//# sourceMappingURL=FilterSelect.js.map
