"use client"; import { useCallback, useState } from "react"; import { Query, Builder, Utils as QbUtils } from "react-awesome-query-builder"; import type { ImmutableTree, BuilderProps } from "react-awesome-query-builder"; import type { JsonTree } from "react-awesome-query-builder"; import { withRaqbSettingsAndWidgets, ConfigFor, } from "@calcom/app-store/routing-forms/components/react-awesome-query-builder/config/uiConfig"; import { getQueryBuilderConfigForAttributes } from "@calcom/app-store/routing-forms/lib/getQueryBuilderConfig"; import { classNames as cn } from "@calcom/lib"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { isEqual } from "@calcom/lib/isEqual"; import { buildStateFromQueryValue } from "@calcom/lib/raqb/raqbUtils"; import type { AttributesQueryValue } from "@calcom/lib/raqb/types"; import { trpc, type RouterOutputs } from "@calcom/trpc"; export type Attributes = RouterOutputs["viewer"]["appRoutingForms"]["getAttributesForTeam"]; export function useAttributes(teamId: number) { const { data: attributes, isPending } = trpc.viewer.appRoutingForms.getAttributesForTeam.useQuery({ teamId, }); return { attributes, isPending, }; } function SegmentWithAttributes({ attributes, teamId, queryValue: initialQueryValue, onQueryValueChange, className, }: { attributes: Attributes; teamId: number; queryValue: AttributesQueryValue | null; onQueryValueChange: ({ queryValue }: { queryValue: AttributesQueryValue }) => void; className?: string; }) { const attributesQueryBuilderConfig = getQueryBuilderConfigForAttributes({ attributes, }); const [queryValue, setQueryValue] = useState(initialQueryValue); const attributesQueryBuilderConfigWithRaqbSettingsAndWidgets = withRaqbSettingsAndWidgets({ config: attributesQueryBuilderConfig, configFor: ConfigFor.Attributes, }); const queryBuilderData = buildStateFromQueryValue({ queryValue: queryValue as JsonTree, config: attributesQueryBuilderConfigWithRaqbSettingsAndWidgets, }); const renderBuilder = useCallback( (props: BuilderProps) => (