'use strict';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { useState } from 'react';
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '../../../../fd-component-toolbox/dropdown-menu/DropdownMenu.js';
import { Button } from '../../../../fd-component-toolbox/button/Button.js';
import { Icon, iconNames, iconSizes } from '../../../../fd-component-toolbox/icon/Icon.js';
import { ViewSheet } from '../../../view/ViewSheet.js';
import { YesOrNoDialog } from '../../../../fd-component-toolbox/dialog/YesOrNoDialog.js';
import { messages } from '../../../../../fd-toolbox-core/constants/messages-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function DataCardAction(t0) {
  const $ = c(10);
  const {
    resourceId,
    uiResourceMeta,
    onDialogResponse,
    shouldShowDeleteButton,
    shouldShowEditButton,
    shouldShowViewButton,
    onRefreshItems,
    onViewClick
  } = t0;
  const [dropdownOpen, setDropdownOpen] = useState(false);
  const resourceName = uiResourceMeta.resourceMeta.resourceName;
  let t1;
  if ($[0] !== dropdownOpen || $[1] !== onDialogResponse || $[2] !== onRefreshItems || $[3] !== onViewClick || $[4] !== resourceId || $[5] !== resourceName || $[6] !== shouldShowDeleteButton || $[7] !== shouldShowEditButton || $[8] !== shouldShowViewButton) {
    t1 = jsx("div", {
      className: "absolute top-2 right-2",
      children: (shouldShowEditButton ?? shouldShowViewButton ?? shouldShowDeleteButton) && jsxs(DropdownMenu, {
        open: dropdownOpen,
        onOpenChange: setDropdownOpen,
        children: [jsx(DropdownMenuTrigger, {
          render: _temp
        }), jsxs(DropdownMenuContent, {
          children: [shouldShowViewButton && jsx(ViewSheet, {
            id: resourceId,
            resourceName,
            onRefreshItems,
            onEditClick: onViewClick,
            onCloseClick: setDropdownOpen,
            children: jsxs(DropdownMenuItem, {
              onSelect: _temp2,
              children: [jsx(Icon, {
                name: iconNames.visibility
              }), jsx("p", {
                children: "View"
              })]
            })
          }), shouldShowDeleteButton && jsx(YesOrNoDialog, {
            title: messages.deleteConfirmation,
            onResponse: onDialogResponse,
            onCloseClick: setDropdownOpen,
            asTriggerChild: true,
            trigger: jsxs(DropdownMenuItem, {
              onSelect: _temp3,
              children: [jsx(Icon, {
                name: iconNames.trash
              }), jsx("p", {
                children: "Delete"
              })]
            })
          }), jsx(ViewSheet, {
            id: resourceId,
            resourceName,
            onRefreshItems,
            onEditClick: onViewClick,
            children: jsxs(DropdownMenuItem, {
              onSelect: _temp4,
              children: [jsx(Icon, {
                name: iconNames.chatBubbleIcon
              }), jsx("p", {
                children: "Comments"
              })]
            })
          })]
        })]
      })
    });
    $[0] = dropdownOpen;
    $[1] = onDialogResponse;
    $[2] = onRefreshItems;
    $[3] = onViewClick;
    $[4] = resourceId;
    $[5] = resourceName;
    $[6] = shouldShowDeleteButton;
    $[7] = shouldShowEditButton;
    $[8] = shouldShowViewButton;
    $[9] = t1;
  } else {
    t1 = $[9];
  }
  return t1;
}
function _temp4(e_1) {
  return e_1.preventDefault();
}
function _temp3(e_0) {
  return e_0.preventDefault();
}
function _temp2(e) {
  return e.preventDefault();
}
function _temp(props) {
  return jsx(Button, {
    ...props,
    size: "icon",
    variant: "ghost",
    className: "size-5 p-1",
    children: jsx(Icon, {
      name: iconNames.dotsVerticalIcon,
      size: iconSizes.medium
    })
  });
}
__name(DataCardAction, "DataCardAction");

export { DataCardAction };
