/** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody, TextControl, BaseControl, TabPanel, SelectControl, Notice, ToggleControl, RangeControl } from '@wordpress/components'; import { useEffect } from '@wordpress/element'; import { select } from '@wordpress/data'; /** * Internal depencencies */ import objAttributes from "./attributes"; import { BOX_BACKGROUND, BOX_PADDING, FIELD_PADDING, FIELD_BORDER, RESULT_BOX_WIDTH, RESULT_BOX_MAXWIDTH, RESULT_BOX_BACKGROUND, RESULT_BOX_BORDER, HTML_TAGS, ITEM_PADDING, ITEM_BORDER, ICON_SIZE, WRAPPER_MARGIN, SEARCH_LAYOUT_VALUES, SEARCH_MODAL_LAYOUT_VALUES, BOX_BACKGROUND_LAYOUT_2, BOX_PADDING_LAYOUT_2, FIELD_PADDING_LAYOUT_2, FIELD_BORDER_LAYOUT_2, ICON_SIZE_LAYOUT_2, SEARCH_MODAL_FIELD_BACKGROUND, SEARCH_MODAL_CONTENT_TABS_ICON_SIZE, SEARCH_MODAL_CONTENT_TABS_BORDER, SEARCH_MODAL_CONTENT_TABS_LIST_ICON_SIZE, SEARCH_MODAL_CONTENT_TABS_LIST_BORDER, SEARCH_MODAL_CONTENT_TABS_LIST_CATEGORY_ICON_SIZE, SEARCH_BUTTON_BACKGROUND_LAYOUT_2, WRAPPER_MARGIN_LAYOUT_2, AI_SUGGESTION_MARGIN, AI_SUGGESTION_PADDING, AI_SUGGESTION_BUTTON_MARGIN, AI_SUGGESTION_BUTTON_PADDING } from "./constants"; import { typoPrefix_fieldtext, typoPrefix_fieldtext_layout_2, typoPrefix_resulttext, SEARCH_MODAL_CONTENT_TABS_LIST_CATEGORY_TYPO, SEARCH_MODAL_FIELD_TYPO, SEARCH_MODAL_CATEGORY_FIELD_TYPO, SEARCH_MODAL_CONTENT_TABS_TYPO, SEARCH_MODAL_CONTENT_TABS_LIST_TYPO, SEARCH_BUTTON_LAYOUT_2_TYPO, AI_SUGGESTION_TITLE_TYPO, AI_SUGGESTION_QUERY_TYPO, AI_SUGGESTION_RESPONSE_TYPO, AI_SUGGESTION_BUTTON_TYPO, } from "./typographyPrefixConstants"; // util import ResponsiveRangeController from "../../../util/responsive-range-control"; import ResponsiveDimensionsControl from "../../../util/dimensions-control-v2"; import TypographyDropdown from "../../../util/typography-control-v2"; import BackgroundControl from "../../../util/background-control"; import BorderShadowControl from "../../../util/border-shadow-control"; import ColorControl from "../../../util/color-control"; import { applyFilters, doAction } from '@wordpress/hooks'; const Inspector = ({ attributes = {}, setAttributes = () => {} }) => { const { resOption, placeholderText, fieldBackgroundColor, fieldBackgroundColorLayout2, fieldTextColor, fieldTextColorLayout2, searchIconColor, searchIconColorLayout2, closeIconColor, closeBorderColor, itemColor, itemHoverColor, searchLayout, searchModalLayout, searchModalWidth, searchModalWidthUnit, searchModalPosition, searchModalMagnifierColor, searchModalFieldColor, searchModalFieldPlaceholderColor, searchModalCategoryColor, searchModalContentTabsListColor, searchModalContentTabsListCategoryColor, searchHeading, searchSubHeading, initialFAQNumber, initialDocsNumber, searchButtonLayout2Color, docQueryType, faqQueryType, searchModalQueryTermIds, searchModalQueryDocIds, searchModalQueriesFaqGroupIds, // AI Search Suggestions attributes enable_ai_powered_search, ai_suggestion_background_color, ai_suggestion_hover_background_color, ai_suggestion_title_color, ai_suggestion_query_color, ai_suggestion_response_color, ai_suggestion_button_color, ai_suggestion_button_bg_color } = attributes; const editorStoreForGettingPreivew = betterdocs_style_handler.editor_type === "edit-site" ? "core/edit-site" : "core/edit-post"; // this useEffect is for setting the resOption attribute to desktop/tab/mobile depending on the added 'eb-res-option-' class only the first time once useEffect(() => { setAttributes({ resOption: select( editorStoreForGettingPreivew ).__experimentalGetPreviewDeviceType(), }); }, []); const resRequiredProps = { setAttributes, resOption, attributes, objAttributes, }; const isAISearchEnabled = () => { try { // Safety check for window object if (typeof window === 'undefined') { return false; } if (typeof window.betterDocsBlocksHelper !== 'undefined' && window.betterDocsBlocksHelper) { // Use the combined flag for simplicity (handle both boolean and numeric values) return window.betterDocsBlocksHelper.AI_SEARCH_SUGGESTIONS_ENABLED == true || window.betterDocsBlocksHelper.AI_SEARCH_SUGGESTIONS_ENABLED === 1; } return false; } catch (error) { return false; } }; return (
{(tab) => (
{tab.name == 'general' && ( <> setAttributes({ searchLayout: newLayout, }) } /> {searchLayout == 'layout-2' && ( <> setAttributes({ searchModalLayout: newLayout, }) } /> {(searchModalLayout === 'docs-archive' || searchModalLayout === 'sidebar') && ( <> setAttributes({ searchModalWidth: value, }) } min={10} max={100} step={1} /> setAttributes({ searchModalPosition: value, }) } /> )} )} {searchLayout == 'layout-2' && setAttributes({ docQueryType: newLayout, }) } /> {docQueryType == 'popular-docs' && { setAttributes({ initialDocsNumber: parseInt(value), }); }} />} {docQueryType == 'specific-doc-ids' && { setAttributes({ searchModalQueryDocIds: value, }); }} /> } { docQueryType == 'specific-doc-term-ids' && { setAttributes({ searchModalQueryTermIds: value, }); }} /> } setAttributes({ faqQueryType: newLayout, }) } /> {faqQueryType == 'default' && { setAttributes({ initialFAQNumber: parseInt(value), }); }} />} {faqQueryType == 'specific-faq-group-ids' && { setAttributes({ searchModalQueriesFaqGroupIds: value, }); }} /> } {__( "Please note that these query changes will be applicable on the front end only", "betterdocs" )} } {(searchLayout == 'layout-1' || (searchLayout == 'layout-2' && searchModalLayout == 'layout-1')) && ( <> { setAttributes({ searchHeading: value, }); }} /> { setAttributes({ searchSubHeading: value, }); }} /> { setAttributes({ searchHeadingTag: value, }); }} /> { setAttributes({ searchSubHeadingTag: value, }); }} /> )} {searchLayout == 'layout-2' && applyFilters('advancedSearchModal', '', [setAttributes, attributes, resOption, objAttributes])} )} {tab.name === "style" && ( <> {(searchLayout == 'layout-1' || (searchLayout == 'layout-2' && searchModalLayout == 'layout-1')) && ( <>

{__("Background", "betterdocs")}

)} <> { setAttributes({ placeholderText: value, }); }} /> { if( searchLayout == 'layout-1' ) { setAttributes({ fieldBackgroundColor:value }) } else { setAttributes({ fieldBackgroundColorLayout2:value }) } }} /> { if( searchLayout == 'layout-1' ){ setAttributes({ fieldTextColor:value }) } else { setAttributes({ fieldTextColorLayout2:value }) } }} />

{__("Border", "betterdocs")}


{__("Search Icon", "betterdocs")}

{ if( searchLayout == 'layout-1' ) { setAttributes({ searchIconColor:value }) } else { setAttributes({ searchIconColorLayout2:value }) } }} /> {searchLayout != 'layout-2' && <>

{__("Close Icon", "betterdocs")}

setAttributes({ closeIconColor, }) } /> setAttributes({ closeBorderColor, }) } />}
{searchLayout == 'layout-2' && ( <> {/* AI Search Suggestions Panel - Only show if AI Chatbot is enabled */} {isAISearchEnabled() && ( setAttributes && setAttributes({ enable_ai_powered_search: !!value })} __nextHasNoMarginBottom={true} /> {enable_ai_powered_search && ( <> { setAttributes && setAttributes({ ai_suggestion_background_color: value }); }} /> { setAttributes && setAttributes({ ai_suggestion_hover_background_color: value }); }} />

{__("Title", "betterdocs")}

{ setAttributes && setAttributes({ ai_suggestion_title_color: value }); }} />

{__("Query", "betterdocs")}

{ setAttributes && setAttributes({ ai_suggestion_query_color: value }); }} />

{__("Response", "betterdocs")}

{ setAttributes && setAttributes({ ai_suggestion_response_color: value }); }} />

{__("Continue Chat Button", "betterdocs")}

{ setAttributes && setAttributes({ ai_suggestion_button_color: value }); }} /> { setAttributes && setAttributes({ ai_suggestion_button_bg_color: value }); }} /> )}
)}

{__("Search Field", "betterdocs")}

{ setAttributes({searchModalMagnifierColor:value}) }} /> { setAttributes({searchModalFieldColor:value}) }} /> { setAttributes({searchModalFieldPlaceholderColor:value}) }} />

{__("Search Category", "betterdocs")}

{ setAttributes({searchModalCategoryColor:value}) }} />

{__("Content Tabs", "betterdocs")}

{__("Content List", "betterdocs")}

{ setAttributes({searchModalContentTabsListColor:value}) }} />

{__("Content List Category", "betterdocs")}

{ setAttributes({searchModalContentTabsListCategoryColor:value}) }} />
{ setAttributes({searchButtonLayout2Color:value}) }} /> )} {searchLayout != 'layout-2' &&

{__("Background", "betterdocs")}

{__("Border", "betterdocs")}

} {searchLayout != 'layout-2' && setAttributes({ itemColor, }) } /> setAttributes({ itemHoverColor, }) } />

{__("Border", "betterdocs")}

} {searchLayout != 'layout-2' && applyFilters('advancedSearchPanel', '', [setAttributes, attributes, resOption, objAttributes])} )} {/* {tab.name === "advance" && ( )} */}
)}
); }; export default Inspector;