'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { Select, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectItem } from '../../../fd-component-toolbox/select/Select.js';
import { useState, useEffect } from 'react';
import { getEnumDisplayValue } from '../../core/property-meta.js';
import { setSelectValueFromForm, getRequiredLabel } from '../../services/property-fields.js';
import { setEnumValue } from './EditResourceEnumField.funcs.js';
import { useElementId } from '../../../../fd-toolbox/hooks/use-element-id.js';
import { emptyString } from '../../../../fd-toolbox/constants/constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function EditResourceEnumField(t0) {
  const $ = c(21);
  const {
    uiPropertyMeta,
    form,
    disabled,
    readOnly,
    skipAnimationOnce,
    onChange,
    propertyMeta,
    parentContextName
  } = t0;
  const [isOpen, setIsOpen] = useState(false);
  const [value, setValue] = useState(emptyString);
  const editResourceEnumSelectId = useElementId(EditResourceEnumField.displayName, parentContextName);
  let t1;
  if ($[0] !== form || $[1] !== uiPropertyMeta.name) {
    t1 = () => {
      setSelectValueFromForm(form, setValue, uiPropertyMeta.name);
    };
    $[0] = form;
    $[1] = uiPropertyMeta.name;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== form || $[4] !== uiPropertyMeta) {
    t2 = [form, uiPropertyMeta];
    $[3] = form;
    $[4] = uiPropertyMeta;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  useEffect(t1, t2);
  let t3;
  if ($[6] !== disabled || $[7] !== editResourceEnumSelectId || $[8] !== form || $[9] !== isOpen || $[10] !== onChange || $[11] !== propertyMeta || $[12] !== readOnly || $[13] !== skipAnimationOnce || $[14] !== uiPropertyMeta.name || $[15] !== value) {
    let t4;
    if ($[17] !== form || $[18] !== onChange || $[19] !== uiPropertyMeta.name) {
      t4 = nextValue => setEnumValue(setValue, uiPropertyMeta.name, form, nextValue ?? void 0, onChange);
      $[17] = form;
      $[18] = onChange;
      $[19] = uiPropertyMeta.name;
      $[20] = t4;
    } else {
      t4 = $[20];
    }
    t3 = jsx("div", {
      className: "w-full",
      children: jsxs(Select, {
        value: value?.toString(),
        onValueChange: t4,
        disabled,
        open: isOpen && !readOnly,
        onOpenChange: setIsOpen,
        children: [jsx(SelectTrigger, {
          className: "pl-1",
          id: editResourceEnumSelectId,
          label: getRequiredLabel(propertyMeta.required, propertyMeta.displayName),
          shouldAnimate: !!value || isOpen,
          skipAnimationOnce,
          children: jsx(SelectValue, {
            children: getEnumDisplayValue(value, propertyMeta)
          })
        }), jsx(SelectContent, {
          children: jsxs(SelectGroup, {
            children: [!propertyMeta.required && jsx(SelectItem, {
              value: emptyString,
              children: jsx("span", {
                className: "text-slate-500",
                children: "Sub Type"
              })
            }), propertyMeta.enumerationValues?.map((val, index) => jsx(SelectItem, {
              value: val.toString(),
              children: propertyMeta.enumerationDisplayName[index]
            }, val))]
          })
        })]
      })
    });
    $[6] = disabled;
    $[7] = editResourceEnumSelectId;
    $[8] = form;
    $[9] = isOpen;
    $[10] = onChange;
    $[11] = propertyMeta;
    $[12] = readOnly;
    $[13] = skipAnimationOnce;
    $[14] = uiPropertyMeta.name;
    $[15] = value;
    $[16] = t3;
  } else {
    t3 = $[16];
  }
  return t3;
}
__name(EditResourceEnumField, "EditResourceEnumField");
EditResourceEnumField.displayName = "EditResourceEnumField";

export { EditResourceEnumField };
