'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { BackButton } from '../../fd-component-toolbox/back-button/BackButton.js';
import { Button } from '../../fd-component-toolbox/button/Button.js';
import { Icon, iconSizes, iconNames } from '../../fd-component-toolbox/icon/Icon.js';
import { SubHeading } from '../../fd-component-toolbox/subheading/SubHeading.js';
import { messages } from '../../../fd-toolbox-core/constants/messages-constants.js';
import { YesOrNoDialog } from '../../fd-component-toolbox/dialog/YesOrNoDialog.js';
import { wellKnownMetaProps } from '../../../fd-toolbox-core/constants/meta-constants.js';
import { SaveStatus } from '../../fd-component-toolbox/save-status/SaveStatus.js';
import { EditImage } from '../components/edit-image/EditImage.js';
import { useElementId } from '../../../fd-toolbox/hooks/use-element-id.js';
import { getEditResourceHeaderBackButtonId, getEditResourceHeaderExpandRelationButtonId, getEditResourceHeaderSaveAndCloseButtonId, getEditResourceHeaderSaveButtonId, getEditResourceHeaderCancelButtonId, getEditResourceHeaderDeleteButtonId } from './EditResourceHeader.funcs.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function EditResourceHeader(t0) {
  const $ = c(21);
  const {
    config,
    onCancel,
    resourceDisplayName,
    resourceName,
    parentContextName,
    onToggleHiddenProperties,
    showHiddenProperties,
    isNew,
    form,
    resourceMeta,
    backArrowUrl,
    shouldShowSaveCancelButtons,
    showDeleteButton,
    onDeleteDialogResponse,
    onSaveResource,
    onChange,
    saved,
    showSavingStatus,
    hasSavedOnce
  } = t0;
  const editResourceHeaderId = useElementId(EditResourceHeader.displayName, parentContextName);
  let t1;
  if ($[0] !== backArrowUrl || $[1] !== config || $[2] !== editResourceHeaderId || $[3] !== form || $[4] !== hasSavedOnce || $[5] !== isNew || $[6] !== onCancel || $[7] !== onChange || $[8] !== onDeleteDialogResponse || $[9] !== onSaveResource || $[10] !== onToggleHiddenProperties || $[11] !== parentContextName || $[12] !== resourceDisplayName || $[13] !== resourceMeta?.description || $[14] !== resourceName || $[15] !== saved || $[16] !== shouldShowSaveCancelButtons || $[17] !== showDeleteButton || $[18] !== showHiddenProperties || $[19] !== showSavingStatus) {
    t1 = jsxs("div", {
      className: "flex w-full flex-col gap-y-3",
      children: [jsxs("div", {
        className: "flex w-full items-center justify-between",
        children: [jsxs("div", {
          className: "flex min-h-9 items-center justify-start gap-2",
          children: [config && config.showBackArrow && jsx(BackButton, {
            id: getEditResourceHeaderBackButtonId(resourceName),
            className: "flex size-5 items-center",
            onClick: onCancel,
            href: backArrowUrl
          }), config && config.showTitle && jsx(SubHeading, {
            className: "pb-0",
            children: resourceDisplayName
          }), config && config.propertyConfigs.size !== 0 && !config.hideExpandButton && jsx(Button, {
            size: "icon",
            variant: "icon",
            onClick: onToggleHiddenProperties,
            children: showHiddenProperties ? jsx(Icon, {
              name: iconNames.caretUp,
              size: iconSizes.small
            }) : jsx(Icon, {
              name: iconNames.caretDown,
              id: getEditResourceHeaderExpandRelationButtonId(resourceName),
              size: iconSizes.small
            })
          })]
        }), hasSavedOnce && showSavingStatus && jsx("div", {
          children: jsx(SaveStatus, {
            saved: !!saved
          })
        })]
      }), jsxs("div", {
        className: "flex flex-row items-center justify-start gap-2",
        children: [!isNew && resourceMeta?.description.useImage && (config?.propertyConfigs.get(wellKnownMetaProps.imageUrl)?.visible ?? true) && jsx(EditImage, {
          parentContextName,
          form,
          initialImageUrl: form.getValues(wellKnownMetaProps.imageUrl),
          onChange
        }), config && jsxs("div", {
          className: "flex flex-row items-end gap-2",
          children: [isNew && shouldShowSaveCancelButtons() && !config.hideTopSaveButton && jsxs(Fragment, {
            children: [jsx(Button, {
              id: getEditResourceHeaderSaveAndCloseButtonId(editResourceHeaderId),
              onClick: () => onSaveResource(false),
              type: "submit",
              children: "Save & Close"
            }), jsx(Button, {
              id: getEditResourceHeaderSaveButtonId(resourceName),
              onClick: () => onSaveResource(true),
              type: "submit",
              children: "Save"
            })]
          }), isNew && shouldShowSaveCancelButtons() && !config.hideTopCancelButton && jsx(Button, {
            id: getEditResourceHeaderCancelButtonId(resourceName),
            onClick: onCancel,
            variant: "outline",
            children: "Cancel"
          }), !isNew && showDeleteButton() && !config.hideTopDeleteButton && jsx(YesOrNoDialog, {
            title: messages.deleteConfirmation || "",
            onResponse: onDeleteDialogResponse,
            asTriggerChild: true,
            trigger: jsx(Button, {
              id: getEditResourceHeaderDeleteButtonId(editResourceHeaderId),
              variant: "icon",
              size: "icon",
              className: "size-5",
              tooltipText: "Delete",
              tooltipSide: "top",
              tooltipClassName: "mb-1",
              children: jsx(Icon, {
                name: iconNames.trash,
                size: iconSizes.medium,
                color: "text-destructive"
              })
            })
          })]
        })]
      })]
    });
    $[0] = backArrowUrl;
    $[1] = config;
    $[2] = editResourceHeaderId;
    $[3] = form;
    $[4] = hasSavedOnce;
    $[5] = isNew;
    $[6] = onCancel;
    $[7] = onChange;
    $[8] = onDeleteDialogResponse;
    $[9] = onSaveResource;
    $[10] = onToggleHiddenProperties;
    $[11] = parentContextName;
    $[12] = resourceDisplayName;
    $[13] = resourceMeta?.description;
    $[14] = resourceName;
    $[15] = saved;
    $[16] = shouldShowSaveCancelButtons;
    $[17] = showDeleteButton;
    $[18] = showHiddenProperties;
    $[19] = showSavingStatus;
    $[20] = t1;
  } else {
    t1 = $[20];
  }
  return t1;
}
__name(EditResourceHeader, "EditResourceHeader");
EditResourceHeader.displayName = "EditResourceHeader";

export { EditResourceHeader };
