var __typeError = (msg) => {
  throw TypeError(msg);
};
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
var _client, _currentResult, _currentMutation, _mutateOptions, _MutationObserver_instances, updateResult_fn, notify_fn, _a;
import { Y as Subscribable, Z as shallowEqualObjects, $ as hashKey, J as notifyManager, a0 as getDefaultState, A as useQueryClient, S as noop, a1 as shouldThrowError, c as useTranslation, u as useWidgetsCore, l as useQueries, j as jsxRuntimeExports, P as Provider, k as createAnchor, a2 as name, a3 as Avatar, R as Root3, T as Trigger, C as Content2 } from "./root-DkXjXudT.js";
import { r as reactExports } from "./index-_B6UFTan.js";
import { at as cx } from "./index-B_ccougm.js";
import { H as Hyperlink } from "./loader-DPk2fY1u.js";
import { u as useCurrentSpace } from "./root-BhTtopL3.js";
var MutationObserver = (_a = class extends Subscribable {
  constructor(client, options) {
    super();
    __privateAdd(this, _MutationObserver_instances);
    __privateAdd(this, _client);
    __privateAdd(this, _currentResult);
    __privateAdd(this, _currentMutation);
    __privateAdd(this, _mutateOptions);
    __privateSet(this, _client, client);
    this.setOptions(options);
    this.bindMethods();
    __privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
  }
  bindMethods() {
    this.mutate = this.mutate.bind(this);
    this.reset = this.reset.bind(this);
  }
  setOptions(options) {
    var _a2;
    const prevOptions = this.options;
    this.options = __privateGet(this, _client).defaultMutationOptions(options);
    if (!shallowEqualObjects(this.options, prevOptions)) {
      __privateGet(this, _client).getMutationCache().notify({
        type: "observerOptionsUpdated",
        mutation: __privateGet(this, _currentMutation),
        observer: this
      });
    }
    if ((prevOptions == null ? void 0 : prevOptions.mutationKey) && this.options.mutationKey && hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)) {
      this.reset();
    } else if (((_a2 = __privateGet(this, _currentMutation)) == null ? void 0 : _a2.state.status) === "pending") {
      __privateGet(this, _currentMutation).setOptions(this.options);
    }
  }
  onUnsubscribe() {
    var _a2;
    if (!this.hasListeners()) {
      (_a2 = __privateGet(this, _currentMutation)) == null ? void 0 : _a2.removeObserver(this);
    }
  }
  onMutationUpdate(action) {
    __privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
    __privateMethod(this, _MutationObserver_instances, notify_fn).call(this, action);
  }
  getCurrentResult() {
    return __privateGet(this, _currentResult);
  }
  reset() {
    var _a2;
    (_a2 = __privateGet(this, _currentMutation)) == null ? void 0 : _a2.removeObserver(this);
    __privateSet(this, _currentMutation, void 0);
    __privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
    __privateMethod(this, _MutationObserver_instances, notify_fn).call(this);
  }
  mutate(variables, options) {
    var _a2;
    __privateSet(this, _mutateOptions, options);
    (_a2 = __privateGet(this, _currentMutation)) == null ? void 0 : _a2.removeObserver(this);
    __privateSet(this, _currentMutation, __privateGet(this, _client).getMutationCache().build(__privateGet(this, _client), this.options));
    __privateGet(this, _currentMutation).addObserver(this);
    return __privateGet(this, _currentMutation).execute(variables);
  }
}, _client = new WeakMap(), _currentResult = new WeakMap(), _currentMutation = new WeakMap(), _mutateOptions = new WeakMap(), _MutationObserver_instances = new WeakSet(), updateResult_fn = function() {
  var _a2;
  const state = ((_a2 = __privateGet(this, _currentMutation)) == null ? void 0 : _a2.state) ?? getDefaultState();
  __privateSet(this, _currentResult, {
    ...state,
    isPending: state.status === "pending",
    isSuccess: state.status === "success",
    isError: state.status === "error",
    isIdle: state.status === "idle",
    mutate: this.mutate,
    reset: this.reset
  });
}, notify_fn = function(action) {
  notifyManager.batch(() => {
    var _a2, _b, _c, _d, _e, _f, _g, _h;
    if (__privateGet(this, _mutateOptions) && this.hasListeners()) {
      const variables = __privateGet(this, _currentResult).variables;
      const context = __privateGet(this, _currentResult).context;
      if ((action == null ? void 0 : action.type) === "success") {
        (_b = (_a2 = __privateGet(this, _mutateOptions)).onSuccess) == null ? void 0 : _b.call(_a2, action.data, variables, context);
        (_d = (_c = __privateGet(this, _mutateOptions)).onSettled) == null ? void 0 : _d.call(_c, action.data, null, variables, context);
      } else if ((action == null ? void 0 : action.type) === "error") {
        (_f = (_e = __privateGet(this, _mutateOptions)).onError) == null ? void 0 : _f.call(_e, action.error, variables, context);
        (_h = (_g = __privateGet(this, _mutateOptions)).onSettled) == null ? void 0 : _h.call(
          _g,
          void 0,
          action.error,
          variables,
          context
        );
      }
    }
    this.listeners.forEach((listener) => {
      listener(__privateGet(this, _currentResult));
    });
  });
}, _a);
function useMutation(options, queryClient) {
  const client = useQueryClient();
  const [observer] = reactExports.useState(
    () => new MutationObserver(
      client,
      options
    )
  );
  reactExports.useEffect(() => {
    observer.setOptions(options);
  }, [observer, options]);
  const result = reactExports.useSyncExternalStore(
    reactExports.useCallback(
      (onStoreChange) => observer.subscribe(notifyManager.batchCalls(onStoreChange)),
      [observer]
    ),
    () => observer.getCurrentResult(),
    () => observer.getCurrentResult()
  );
  const mutate = reactExports.useCallback(
    (variables, mutateOptions) => {
      observer.mutate(variables, mutateOptions).catch(noop);
    },
    [observer]
  );
  if (result.error && shouldThrowError(observer.options.throwOnError, [result.error])) {
    throw result.error;
  }
  return { ...result, mutate, mutateAsync: result.mutate };
}
function ClockIcon({
  title,
  titleId,
  ...props
}, svgRef) {
  return /* @__PURE__ */ reactExports.createElement("svg", Object.assign({
    xmlns: "http://www.w3.org/2000/svg",
    fill: "none",
    viewBox: "0 0 24 24",
    strokeWidth: 1.5,
    stroke: "currentColor",
    "aria-hidden": "true",
    "data-slot": "icon",
    ref: svgRef,
    "aria-labelledby": titleId
  }, props), title ? /* @__PURE__ */ reactExports.createElement("title", {
    id: titleId
  }, title) : null, /* @__PURE__ */ reactExports.createElement("path", {
    strokeLinecap: "round",
    strokeLinejoin: "round",
    d: "M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
  }));
}
const ForwardRef$2 = /* @__PURE__ */ reactExports.forwardRef(ClockIcon);
function LanguageIcon({
  title,
  titleId,
  ...props
}, svgRef) {
  return /* @__PURE__ */ reactExports.createElement("svg", Object.assign({
    xmlns: "http://www.w3.org/2000/svg",
    fill: "none",
    viewBox: "0 0 24 24",
    strokeWidth: 1.5,
    stroke: "currentColor",
    "aria-hidden": "true",
    "data-slot": "icon",
    ref: svgRef,
    "aria-labelledby": titleId
  }, props), title ? /* @__PURE__ */ reactExports.createElement("title", {
    id: titleId
  }, title) : null, /* @__PURE__ */ reactExports.createElement("path", {
    strokeLinecap: "round",
    strokeLinejoin: "round",
    d: "m10.5 21 5.25-11.25L21 21m-9-3h7.5M3 5.621a48.474 48.474 0 0 1 6-.371m0 0c1.12 0 2.233.038 3.334.114M9 5.25V3m3.334 2.364C11.176 10.658 7.69 15.08 3 17.502m9.334-12.138c.896.061 1.785.147 2.666.257m-4.589 8.495a18.023 18.023 0 0 1-3.827-5.802"
  }));
}
const ForwardRef$1 = /* @__PURE__ */ reactExports.forwardRef(LanguageIcon);
function Square3Stack3DIcon({
  title,
  titleId,
  ...props
}, svgRef) {
  return /* @__PURE__ */ reactExports.createElement("svg", Object.assign({
    xmlns: "http://www.w3.org/2000/svg",
    fill: "none",
    viewBox: "0 0 24 24",
    strokeWidth: 1.5,
    stroke: "currentColor",
    "aria-hidden": "true",
    "data-slot": "icon",
    ref: svgRef,
    "aria-labelledby": titleId
  }, props), title ? /* @__PURE__ */ reactExports.createElement("title", {
    id: titleId
  }, title) : null, /* @__PURE__ */ reactExports.createElement("path", {
    strokeLinecap: "round",
    strokeLinejoin: "round",
    d: "M6.429 9.75 2.25 12l4.179 2.25m0-4.5 5.571 3 5.571-3m-11.142 0L2.25 7.5 12 2.25l9.75 5.25-4.179 2.25m0 0L21.75 12l-4.179 2.25m0 0 4.179 2.25L12 21.75 2.25 16.5l4.179-2.25m11.142 0-5.571 3-5.571-3"
  }));
}
const ForwardRef = /* @__PURE__ */ reactExports.forwardRef(Square3Stack3DIcon);
function Settings(props) {
  var _a2, _b, _c, _d;
  const { t } = useTranslation();
  const core = useWidgetsCore();
  const [currentSpaceId] = useCurrentSpace();
  const [userQuery, spacesQuery] = useQueries({
    queries: [
      {
        // @ts-expect-error Allow mixing with non-suspense queries
        suspense: true,
        queryKey: ["user"],
        queryFn: () => core.getUser()
      },
      {
        queryKey: ["spaces"],
        queryFn: () => core.getSpaces()
      }
    ]
  });
  const user = userQuery.data;
  const spaces = spacesQuery.data;
  const entries = [
    {
      title: t("current-space"),
      icon: ForwardRef,
      value: ((_a2 = spaces == null ? void 0 : spaces.find((space) => space.id === currentSpaceId)) == null ? void 0 : _a2.name) ?? currentSpaceId
    },
    {
      title: t("timezone"),
      icon: ForwardRef$2,
      value: user.timezone
    },
    {
      title: t("preferred-langauge"),
      icon: ForwardRef$1,
      value: (() => {
        if (!user.preferredLanguage) return;
        try {
          return new Intl.DisplayNames(void 0, {
            type: "language",
            languageDisplay: "standard"
          }).of(user.preferredLanguage);
        } catch {
        }
      })()
    }
  ];
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Provider, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...createAnchor(name), className: "flex h-full w-full flex-col", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 p-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Avatar, { className: "h-16 w-16 flex-shrink-0 rounded-2xl text-[1.5rem]" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "gap-0.25 flex min-w-0 flex-col py-1", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "truncate text-xl font-semibold", children: [
          (_b = user.name) == null ? void 0 : _b.givenName,
          " ",
          (_c = user.name) == null ? void 0 : _c.familyName
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-sm text-zinc-700", children: user.email })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-col gap-2 p-4", children: entries.map((entry, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 text-zinc-900", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Root3, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(entry.icon, { className: "h-4 w-4 flex-shrink-0" }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Content2,
          {
            className: "z-10 rounded bg-zinc-600 px-2 py-1.5 text-xs leading-none text-white",
            sideOffset: 6,
            side: "left",
            children: entry.title
          }
        )
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate text-xs", children: entry.value ?? /* @__PURE__ */ jsxRuntimeExports.jsx("em", { children: t("empty-value") }) })
    ] }, index)) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-16 mt-auto flex flex-col items-center gap-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Hyperlink,
        {
          href: "https://workgrid.com/privacy-policy",
          className: "rounded px-2 py-1 text-xs text-brand-900 underline",
          children: t("privacy-policy")
        }
      ),
      (_d = props.actions) == null ? void 0 : _d.map((action) => {
        return /* @__PURE__ */ jsxRuntimeExports.jsx(Action, { ...action }, action.label);
      })
    ] })
  ] }) });
}
function Action(props) {
  const mutation = useMutation({
    mutationFn: async () => props.handler()
  });
  if (mutation.error) throw mutation.error;
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    "button",
    {
      className: cx(
        "rounded-full border border-brand-700 bg-brand-900 px-4 py-2 text-sm text-white hover:border-brand-900 hover:bg-brand-700 focus:border-brand-900 focus:bg-brand-700 active:border-zinc-100 active:bg-brand-900",
        { "pointer-events-none opacity-80": mutation.isPending }
      ),
      onClick: () => {
        mutation.mutate();
      },
      disabled: mutation.isPending,
      children: props.label
    }
  );
}
export {
  Settings as default
};
//# sourceMappingURL=settings-Fg-J5fJ4.js.map
