'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { onPropsChange, getSortedUiPropertyMetas, getSortedUiPropertyMetasAndCustomActionFields, onItemClick, getPropertyCssClass } from './EditResourcePropertyBlock.funcs.js';
import { useState, useEffect } from 'react';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { EditResourcePropertyField } from '../edit-resource-property-field/EditResourcePropertyField.js';
import { elements } from '../../../../fd-toolbox/constants/elements.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const instanceNumber = {
  value: 0
};
function EditResourcePropertyBlock(t0) {
  const $ = c(27);
  const {
    resourceMeta,
    isNew,
    resource,
    formFieldOptions,
    form,
    uiPropertyMetas,
    showHiddenProperties,
    config,
    values,
    loadComplete,
    readOnlyResource,
    onChange,
    className,
    parentContextName,
    customActionFields
  } = t0;
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = new Map();
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [excludeResourceIds, setExcludeResourceIds] = useState(t1);
  let t2;
  if ($[1] !== form || $[2] !== resourceMeta || $[3] !== values) {
    t2 = () => onPropsChange(form, setExcludeResourceIds, values, instanceNumber, resourceMeta);
    $[1] = form;
    $[2] = resourceMeta;
    $[3] = values;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== form || $[6] !== isNew || $[7] !== resourceMeta || $[8] !== uiPropertyMetas || $[9] !== values) {
    t3 = [form, isNew, uiPropertyMetas, setExcludeResourceIds, values, resourceMeta];
    $[5] = form;
    $[6] = isNew;
    $[7] = resourceMeta;
    $[8] = uiPropertyMetas;
    $[9] = values;
    $[10] = t3;
  } else {
    t3 = $[10];
  }
  useEffect(t2, t3);
  let t4;
  if ($[11] !== className || $[12] !== config || $[13] !== customActionFields || $[14] !== excludeResourceIds || $[15] !== form || $[16] !== formFieldOptions || $[17] !== isNew || $[18] !== loadComplete || $[19] !== onChange || $[20] !== parentContextName || $[21] !== readOnlyResource || $[22] !== resource || $[23] !== resourceMeta || $[24] !== showHiddenProperties || $[25] !== uiPropertyMetas) {
    const sortedUiPropertyMetas = getSortedUiPropertyMetas(uiPropertyMetas);
    const sortedUiPropertyMetasAndCustomActionFields = getSortedUiPropertyMetasAndCustomActionFields(sortedUiPropertyMetas, customActionFields, resourceMeta);
    t4 = jsx("div", {
      className: cn("me-3 grid w-full grid-cols-1 content-between gap-y-2.5", className, config.className),
      children: loadComplete && sortedUiPropertyMetasAndCustomActionFields.map(componentFieldData => {
        if (componentFieldData.customField) {
          const customField = componentFieldData.customField;
          const CustomFieldComponent = customField.component;
          return jsx("div", {
            className: customField.className,
            children: jsx(CustomFieldComponent, {
              form,
              uiPropertyMeta: componentFieldData.uiPropertyMeta,
              editResourceOnChangeCallback: onChange
            })
          }, customField.component.toString());
        } else {
          if (componentFieldData.uiPropertyMeta) {
            return jsx("div", {
              className: cn("relative flex flex-col gap-y-2.5", getPropertyCssClass(componentFieldData.uiPropertyMeta, config, showHiddenProperties), config.propertyConfigs.get(componentFieldData.uiPropertyMeta.name)?.className),
              children: jsx(EditResourcePropertyField, {
                uiPropertyMeta: componentFieldData.uiPropertyMeta,
                propertyMeta: resourceMeta.properties[componentFieldData.uiPropertyMeta.name],
                form,
                formFieldOption: formFieldOptions[resourceMeta.properties[componentFieldData.uiPropertyMeta.name].name],
                resource,
                readOnlyResource,
                loadComplete: loadComplete ?? false,
                excludeResourceIds,
                isNew,
                onItemClick: propertyMeta => onItemClick(propertyMeta, resourceMeta, resource),
                onChange,
                propertyConfig: config.propertyConfigs.get(resourceMeta.properties[componentFieldData.uiPropertyMeta.name].name),
                parentContextName
              })
            }, componentFieldData.uiPropertyMeta.name);
          }
        }
        return void 0;
      })
    });
    $[11] = className;
    $[12] = config;
    $[13] = customActionFields;
    $[14] = excludeResourceIds;
    $[15] = form;
    $[16] = formFieldOptions;
    $[17] = isNew;
    $[18] = loadComplete;
    $[19] = onChange;
    $[20] = parentContextName;
    $[21] = readOnlyResource;
    $[22] = resource;
    $[23] = resourceMeta;
    $[24] = showHiddenProperties;
    $[25] = uiPropertyMetas;
    $[26] = t4;
  } else {
    t4 = $[26];
  }
  return t4;
}
__name(EditResourcePropertyBlock, "EditResourcePropertyBlock");
EditResourcePropertyBlock.displayName = elements.editResource.propertyBlock;

export { EditResourcePropertyBlock };
