'use strict';
'use client';
import { jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { onInitMultiBrowser, handleInputModelChange } from './MultiBrowser.funcs.js';
import { BaseMultiBrowser } from '../base-multi-browser/BaseMultiBrowser.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { browserTypes } from '../browser-type.js';
import { closeBrowserSelectionDialog } from '../browser-selection.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function MultiBrowser({
  required,
  propertyMeta,
  onChange,
  onClose,
  parentContextName: parentContextNameProp,
  displayMode,
  disabled,
  readOnly,
  invalid,
  relatedResourceId,
  selectedResourceIds,
  onSelectedResourceIdsChange,
  variant,
  children: icons,
  ref
}) {
  const [propertyResourceMeta, setPropertyResourceMeta] = useState();
  const [selectedResources, setSelectedResources] = useState([]);
  const [loadComplete, setLoadComplete] = useState(false);
  useAsyncEffect(async () => {
    await onInitMultiBrowser(propertyMeta, setSelectedResources, setPropertyResourceMeta, setLoadComplete, propertyResourceMeta, selectedResourceIds, relatedResourceId, onSelectedResourceIdsChange, onChange);
  }, [selectedResourceIds?.join(), relatedResourceId]);
  const onCloseDialog = /* @__PURE__ */__name(resources => propertyResourceMeta && closeBrowserSelectionDialog(resources, setSelectedResources, propertyMeta, setPropertyResourceMeta, propertyResourceMeta, onChange, onClose), "onCloseDialog");
  return /* @__PURE__ */jsx(BaseMultiBrowser, {
    parentContextName: parentContextNameProp,
    browserType: browserTypes.multiBrowser,
    required: required ?? false,
    propertyMeta,
    relatedResourceId,
    selectedResources,
    onCloseDialog,
    onDescriptionChange: event => handleInputModelChange(event, setSelectedResources, onChange, propertyResourceMeta),
    displayMode,
    disabled,
    readOnly,
    propertyResourceMeta,
    onChange,
    setSelectedResources,
    skipAnimationOnce: !loadComplete,
    variant: variant ?? "float",
    ref,
    invalid,
    children: icons
  });
}
__name(MultiBrowser, "MultiBrowser");

export { MultiBrowser };
