'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { useState } from 'react';
import '../../../fd-component-toolbox/client/framework/index.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { initSearchFilters, search, notFoundImg, getSearchResultContainerId } from './SearchDialog.funcs.js';
import { useEnterKey } from '../../../../fd-toolbox/hooks/use-enter-key.js';
import { Icon } from '../../../fd-component-toolbox/icon/Icon.js';
import { BadgeToggleList } from '../../../fd-component-toolbox/badge-toggle-list/BadgeToggleList.js';
import { SearchScreenResults } from '../search-resource-results/SearchResourcesResults.js';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { SearchInput } from '../search-input/SearchInput.js';
import { SearchSearchableResourceResults } from '../search-searchable-resource-results/SearchSearchableResourceResults.js';
import { useSidebarContext } from '../../providers/sidebar-provider/SidebarContext.js';
import FrameworkImage from 'next/image.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function SearchDialog(t0) {
  const $ = c(30);
  const {
    parentContextName,
    onClose,
    searchQuery,
    onFocus,
    onBlur,
    onOpenDialog,
    onSearchQueryChanged,
    compactMode
  } = t0;
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = [];
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [filters, setFilters] = useState(t1);
  let t2;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = [];
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const [selectedFilters, setSelectedFilters] = useState(t2);
  let t3;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = [];
    $[2] = t3;
  } else {
    t3 = $[2];
  }
  const [searchableResourcesResult, setSearchableResourcesResult] = useState(t3);
  let t4;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = [];
    $[3] = t4;
  } else {
    t4 = $[3];
  }
  const [screensResult, setScreensResult] = useState(t4);
  const sidebarContext = useSidebarContext();
  let t5;
  let t6;
  if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = async () => {
      await initSearchFilters(setFilters, setSelectedFilters);
    };
    t6 = [];
    $[4] = t5;
    $[5] = t6;
  } else {
    t5 = $[4];
    t6 = $[5];
  }
  useAsyncEffect(t5, t6);
  let t7;
  if ($[6] !== searchQuery || $[7] !== selectedFilters) {
    t7 = async () => {
      await search(searchQuery, selectedFilters, setSearchableResourcesResult, setScreensResult);
    };
    $[6] = searchQuery;
    $[7] = selectedFilters;
    $[8] = t7;
  } else {
    t7 = $[8];
  }
  let t8;
  if ($[9] !== filters || $[10] !== searchQuery || $[11] !== selectedFilters) {
    t8 = [searchQuery, selectedFilters, filters];
    $[9] = filters;
    $[10] = searchQuery;
    $[11] = selectedFilters;
    $[12] = t8;
  } else {
    t8 = $[12];
  }
  useAsyncEffect(t7, t8);
  let t9;
  if ($[13] !== searchQuery || $[14] !== selectedFilters) {
    t9 = async () => {
      await search(searchQuery, selectedFilters, setSearchableResourcesResult, setScreensResult);
    };
    $[13] = searchQuery;
    $[14] = selectedFilters;
    $[15] = t9;
  } else {
    t9 = $[15];
  }
  useEnterKey(t9);
  let t10;
  if ($[16] !== compactMode || $[17] !== filters || $[18] !== onBlur || $[19] !== onClose || $[20] !== onFocus || $[21] !== onOpenDialog || $[22] !== onSearchQueryChanged || $[23] !== parentContextName || $[24] !== screensResult || $[25] !== searchQuery || $[26] !== searchableResourcesResult || $[27] !== selectedFilters || $[28] !== sidebarContext?.sidebarOpen) {
    t10 = jsxs("div", {
      className: "fixed inset-0 z-20 mt-10",
      onFocus,
      onBlur,
      children: [jsx("div", {
        className: "absolute inset-0",
        onClick: onClose
      }), jsxs("div", {
        className: cn("bg-background relative z-10 mt-2 ml-0 h-[calc(100vh-2.5rem)] w-full p-6 shadow-lg transition-all duration-75 ease-in", !compactMode && (sidebarContext?.sidebarOpen ? "ml-60 w-[calc(100%-15rem)]" : "md:ml-14 md:w-[calc(100%-3.5rem)]")),
        children: [jsx(SearchInput, {
          parentContextName,
          searchQuery,
          onSearchQueryChanged,
          onOpenDialog,
          className: "mb-4 flex md:hidden",
          useCustomInputStyle: true
        }), jsxs("div", {
          className: "mb-4 flex items-start justify-between gap-2",
          children: [jsx(BadgeToggleList, {
            items: filters,
            selectedItems: selectedFilters,
            onSelectedItemsChange: setSelectedFilters
          }), jsx("div", {
            className: "text-subtle-700 hover:text-subtle-500 focus:outline-none",
            onClick: onClose,
            children: jsx(Icon, {
              name: "cross2",
              size: "medium",
              className: "size-6 cursor-pointer"
            })
          })]
        }), jsx("hr", {
          className: "mb-5"
        }), jsx("div", {
          className: "mt-4 h-[calc(100%-2.5rem)] overflow-y-auto",
          children: searchableResourcesResult.length === 0 && screensResult.length === 0 ? jsx("div", {
            className: "flex h-full flex-col items-center justify-center text-center",
            children: !!searchQuery && jsxs(Fragment, {
              children: [jsx(FrameworkImage, {
                src: notFoundImg,
                alt: "No Results",
                width: 300,
                height: 200,
                className: "mb-4 object-cover",
                priority: true
              }), jsx("h5", {
                children: "No results found."
              })]
            })
          }) : jsxs("div", {
            id: getSearchResultContainerId(parentContextName ?? ""),
            className: "flex flex-col gap-4",
            children: [searchableResourcesResult.length !== 0 && jsx(SearchSearchableResourceResults, {
              parentContextName,
              resourcesResults: searchableResourcesResult
            }), screensResult.length !== 0 && jsx(SearchScreenResults, {
              resourcesResults: screensResult,
              onClose
            })]
          })
        })]
      })]
    });
    $[16] = compactMode;
    $[17] = filters;
    $[18] = onBlur;
    $[19] = onClose;
    $[20] = onFocus;
    $[21] = onOpenDialog;
    $[22] = onSearchQueryChanged;
    $[23] = parentContextName;
    $[24] = screensResult;
    $[25] = searchQuery;
    $[26] = searchableResourcesResult;
    $[27] = selectedFilters;
    $[28] = sidebarContext?.sidebarOpen;
    $[29] = t10;
  } else {
    t10 = $[29];
  }
  return t10;
}
__name(SearchDialog, "SearchDialog");

export { SearchDialog };
