import { useMatch } from './useMatch' import type { StructuralSharingOption, ValidateSelected, } from './structuralSharing' import type { AnyRouter, RegisteredRouter, ResolveUseSearch, StrictOrFrom, ThrowConstraint, ThrowOrOptional, UseSearchResult, } from '@tanstack/router-core' export interface UseSearchBaseOptions< TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing, > { select?: ( state: ResolveUseSearch, ) => ValidateSelected shouldThrow?: TThrow } export type UseSearchOptions< TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing, > = StrictOrFrom & UseSearchBaseOptions< TRouter, TFrom, TStrict, TThrow, TSelected, TStructuralSharing > & StructuralSharingOption export type UseSearchRoute = < TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean, >( opts?: UseSearchBaseOptions< TRouter, TFrom, /* TStrict */ true, /* TThrow */ true, TSelected, TStructuralSharing > & StructuralSharingOption, ) => UseSearchResult export function useSearch< TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean, >( opts: UseSearchOptions< TRouter, TFrom, TStrict, ThrowConstraint, TSelected, TStructuralSharing >, ): ThrowOrOptional< UseSearchResult, TThrow > { return useMatch({ from: opts.from!, strict: opts.strict, shouldThrow: opts.shouldThrow, structuralSharing: opts.structuralSharing, select: (match: any) => { return opts.select ? opts.select(match.search) : match.search }, }) as any }