'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { MultiSelect, MultiselectTrigger, MultiselectInput, MultiselectContent, MultiselectList, MultiselectItem } from '../../../fd-component-toolbox/multiselect/Multiselect.js';
import { initVisibleWorkspacePicker, onSelectedVisibleWorkspaceChange } from './VisibleWorkspacePicker.funcs.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { isTemporaryDisabled } from '../../../../fd-toolbox/functions/condition-check-functions.js';
import { useOptionalPromise } from '../../../../fd-toolbox/hooks/use-optional-promise.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function VisibleWorkspacePicker(t0) {
  const $ = c(7);
  const {
    visibleWorkspaces
  } = t0;
  const userVisibleWorkspaces = useOptionalPromise(visibleWorkspaces);
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = [];
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [visibleWorkspacesState, setVisibleWorkspacesState] = useState(t1);
  const [workspaces, setWorkspaces] = useState();
  let t2;
  if ($[1] !== userVisibleWorkspaces) {
    t2 = async () => {
      await initVisibleWorkspacePicker(setVisibleWorkspacesState, setWorkspaces, userVisibleWorkspaces);
    };
    $[1] = userVisibleWorkspaces;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = [];
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  useAsyncEffect(t2, t3);
  let t4;
  if ($[4] !== visibleWorkspacesState || $[5] !== workspaces) {
    t4 = workspaces && workspaces.size > 0 ? jsxs(MultiSelect, {
      values: visibleWorkspacesState,
      onValuesChange: value => {
        onSelectedVisibleWorkspaceChange(value, setVisibleWorkspacesState);
      },
      disabled: false,
      displayValues: workspaces,
      variant: "float",
      showSelectAll: true,
      children: [!isTemporaryDisabled() && jsx(MultiselectTrigger, {
        className: "hover:bg-muted/50 p-2 text-sm font-medium shadow-none",
        children: jsx(MultiselectInput, {
          placeholder: "Visible Workspaces",
          className: "mt-0 cursor-pointer pl-0"
        })
      }), jsx(MultiselectContent, {
        className: "absolute min-w-60",
        children: jsx(MultiselectList, {
          className: "top-9 z-50",
          children: Array.from(workspaces).map(_temp)
        })
      })]
    }) : void 0;
    $[4] = visibleWorkspacesState;
    $[5] = workspaces;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  return t4;
}
function _temp(t0) {
  const [key, value_0] = t0;
  return jsx(MultiselectItem, {
    className: "min-h-6 whitespace-nowrap",
    value: key,
    children: value_0
  }, key);
}
__name(VisibleWorkspacePicker, "VisibleWorkspacePicker");

export { VisibleWorkspacePicker };
