'use strict';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { Card } from '../../../fd-component-toolbox/card/Card.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { initDataCard, onViewClick, onDialogResponse } from './DataCard.funcs.js';
import { DataCardImage } from './data-card-image/DataCardImage.js';
import { DataCardContent } from './data-card-content/DataCardContent.js';
import { DataCardAction } from './data-card-action/DataCardAction.js';
import { isCardLayoutVertical, isCardLayoutHorizontal } from '../card-layout.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function DataCard(t0) {
  const $ = c(16);
  const {
    cardConfig,
    uiResourceMeta,
    resource,
    onItemDelete,
    onRefreshItems
  } = t0;
  const [item, setItem] = useState();
  const [imageUrl, setImageUrl] = useState();
  const [shouldShowEditButton, setShouldShowEditButton] = useState(false);
  const [shouldShowViewButton, setShouldShowViewButton] = useState(false);
  const [shouldShowDeleteButton, setShouldShowDeleteButton] = useState(false);
  const resourceName = uiResourceMeta.resourceMeta.resourceName;
  let t1;
  let t2;
  if ($[0] !== resource || $[1] !== uiResourceMeta) {
    t1 = async () => {
      await initDataCard(uiResourceMeta, resource, setItem, setImageUrl, setShouldShowEditButton, setShouldShowViewButton, setShouldShowDeleteButton);
    };
    t2 = [uiResourceMeta, resource];
    $[0] = resource;
    $[1] = uiResourceMeta;
    $[2] = t1;
    $[3] = t2;
  } else {
    t1 = $[2];
    t2 = $[3];
  }
  useAsyncEffect(t1, t2);
  let t3;
  if ($[4] !== cardConfig || $[5] !== imageUrl || $[6] !== item || $[7] !== onItemDelete || $[8] !== onRefreshItems || $[9] !== resource || $[10] !== resourceName || $[11] !== shouldShowDeleteButton || $[12] !== shouldShowEditButton || $[13] !== shouldShowViewButton || $[14] !== uiResourceMeta) {
    t3 = jsxs(Card, {
      className: cn("relative flex overflow-hidden rounded-sm shadow-sm", {
        "w-full flex-row": isCardLayoutHorizontal(cardConfig),
        "w-64 flex-col": isCardLayoutVertical(cardConfig)
      }),
      children: [jsx(DataCardImage, {
        imageUrl,
        cardLayoutHorizontal: isCardLayoutHorizontal(cardConfig),
        cardLayoutVertical: isCardLayoutVertical(cardConfig)
      }), item && jsx(DataCardContent, {
        uiResourceMeta,
        item,
        resource
      }), item && jsx(DataCardAction, {
        resourceId: resource.id,
        uiResourceMeta,
        shouldShowEditButton,
        shouldShowViewButton,
        shouldShowDeleteButton,
        onDialogResponse: isYes => onDialogResponse(isYes, resource, uiResourceMeta, resourceName, onItemDelete),
        onRefreshItems,
        onViewClick: () => onViewClick(item, resourceName)
      })]
    });
    $[4] = cardConfig;
    $[5] = imageUrl;
    $[6] = item;
    $[7] = onItemDelete;
    $[8] = onRefreshItems;
    $[9] = resource;
    $[10] = resourceName;
    $[11] = shouldShowDeleteButton;
    $[12] = shouldShowEditButton;
    $[13] = shouldShowViewButton;
    $[14] = uiResourceMeta;
    $[15] = t3;
  } else {
    t3 = $[15];
  }
  return t3;
}
__name(DataCard, "DataCard");

export { DataCard };
