'use strict';
'use client';
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 { SaveStatus } from '../../fd-component-toolbox/save-status/SaveStatus.js';
import { Tabs, TabsList, TabsTab, TabsPanel } from '../../fd-component-toolbox/tabs/Tabs.js';
import { tabsNames, editResourceLayoutTypes } from './edit-resource-constants.js';
import { RelatedResources } from '../components/related-resources/RelatedResources.js';
import { CommentList } from '../comment/CommentList.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function EditResourceTabs(t0) {
  const $ = c(19);
  const {
    isLoadComplete,
    tabsHasSavedOnce,
    multiListItems,
    resourceName,
    resourceId,
    config,
    isNew,
    defaultTab,
    uiResourceMeta,
    multiListConfig,
    resource,
    commentList,
    children
  } = t0;
  const [activeTab, setActiveTab] = useState(defaultTab ?? tabsNames.overview);
  const [tabsActiveSaveOperations, setTabsActiveSaveOperations] = useState(0);
  let t1;
  if ($[0] !== multiListConfig?.customSections || $[1] !== multiListItems.length) {
    t1 = multiListItems.length > 0 || !!multiListConfig?.customSections?.some(_temp);
    $[0] = multiListConfig?.customSections;
    $[1] = multiListItems.length;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const hasOverviewContent = t1;
  const shouldShowCommentsTab = !!config.tabsConfig?.isCommentTabVisible;
  const shouldRenderRightPanel = !isNew && !!multiListConfig && (hasOverviewContent || shouldShowCommentsTab);
  const isNavigationLayout = config.tabsConfig?.layoutType === editResourceLayoutTypes.navigation;
  if (!isLoadComplete) {
    return void 0;
  }
  let t2;
  if ($[3] !== activeTab || $[4] !== children || $[5] !== commentList || $[6] !== hasOverviewContent || $[7] !== isNavigationLayout || $[8] !== multiListConfig || $[9] !== multiListItems || $[10] !== resource || $[11] !== resourceId || $[12] !== resourceName || $[13] !== shouldRenderRightPanel || $[14] !== shouldShowCommentsTab || $[15] !== tabsActiveSaveOperations || $[16] !== tabsHasSavedOnce || $[17] !== uiResourceMeta) {
    t2 = jsxs("div", {
      className: "relative h-full",
      children: [tabsHasSavedOnce && jsx("div", {
        className: "absolute top-1.5 right-9",
        children: jsx(SaveStatus, {
          saved: tabsActiveSaveOperations === 0
        })
      }), jsxs("div", {
        className: cn("flex w-full flex-col justify-center lg:h-full lg:flex-row lg:overflow-hidden", !isNavigationLayout && "lg:gap-x-6"),
        children: [isNavigationLayout ? children : jsx("div", {
          className: "min-w-0 lg:grow-[5] lg:basis-0",
          children
        }), shouldRenderRightPanel && isNavigationLayout && jsx("div", {
          className: cn("my-4 h-px w-full pr-2 lg:mt-0 lg:ml-2 lg:h-auto lg:min-h-full lg:w-px lg:pr-0", shouldShowCommentsTab ? "lg:mr-6" : "lg:mr-0"),
          children: jsx("div", {
            className: "bg-border size-full"
          })
        }), shouldRenderRightPanel && jsxs(Tabs, {
          value: String(activeTab),
          className: cn("flex h-1/2 w-full min-w-0 flex-col overflow-y-auto pr-2 lg:h-full lg:overflow-hidden lg:pr-0", !isNavigationLayout && "lg:grow-[7] lg:basis-0"),
          children: [jsxs(TabsList, {
            className: "flex items-end text-sm",
            children: [hasOverviewContent && shouldShowCommentsTab && jsx(TabsTab, {
              onClick: () => setActiveTab(tabsNames.overview),
              value: String(tabsNames.overview),
              className: "hover:text-subtle-500 [&:not([data-active])]:bg-muted data-[active]:text-muted-foreground flex h-full min-w-32 items-center justify-center rounded-tl-md border px-1 py-3 outline-none data-[active]:border-b-0 data-[active]:font-semibold",
              children: "Overview"
            }), shouldShowCommentsTab && jsx(TabsTab, {
              onClick: () => setActiveTab(tabsNames.comments),
              value: String(tabsNames.comments),
              className: cn("hover:text-subtle-500 [&:not([data-active])]:bg-muted data-[active]:text-muted-foreground flex h-full min-w-32 items-center justify-center rounded-tr-md border px-1 py-3 outline-none data-[active]:border-b-0 data-[active]:font-semibold", {
                "rounded-tl-md": multiListItems?.length === 0
              }),
              children: "Comments"
            }), activeTab !== tabsNames.overview && jsx("hr", {
              className: "h-px w-full border-t"
            })]
          }), jsx(TabsPanel, {
            value: String(tabsNames.overview),
            className: cn("h-full max-w-full overflow-x-hidden overflow-y-auto pt-7", activeTab !== tabsNames.overview ? "hidden" : "visible"),
            children: jsx(RelatedResources, {
              multiListConfig,
              uiResourceMeta,
              setActiveSaveOperations: setTabsActiveSaveOperations,
              multiListItems,
              resource,
              commentList
            })
          }), jsx(TabsPanel, {
            value: String(tabsNames.comments),
            className: cn("h-full max-w-full overflow-x-hidden overflow-y-auto pt-3", activeTab !== tabsNames.comments ? "hidden" : "visible"),
            children: resourceName && jsx("div", {
              className: "mt-2 flex w-full grow-0 basis-full flex-col gap-y-10 overflow-x-hidden overflow-y-auto",
              children: jsx(CommentList, {
                resourceName,
                resourceId,
                resources: commentList
              })
            })
          })]
        })]
      })]
    });
    $[3] = activeTab;
    $[4] = children;
    $[5] = commentList;
    $[6] = hasOverviewContent;
    $[7] = isNavigationLayout;
    $[8] = multiListConfig;
    $[9] = multiListItems;
    $[10] = resource;
    $[11] = resourceId;
    $[12] = resourceName;
    $[13] = shouldRenderRightPanel;
    $[14] = shouldShowCommentsTab;
    $[15] = tabsActiveSaveOperations;
    $[16] = tabsHasSavedOnce;
    $[17] = uiResourceMeta;
    $[18] = t2;
  } else {
    t2 = $[18];
  }
  return t2;
}
function _temp(section) {
  return section.hasPermission;
}
__name(EditResourceTabs, "EditResourceTabs");

export { EditResourceTabs };
