"use client"; import { ChevronUpIcon } from "@/assets/icons"; import { cn } from "@/lib/utils"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; import { Dropdown, DropdownContent, DropdownTrigger } from "./ui/dropdown"; type PropsType = { defaultValue?: TItem; items?: TItem[]; sectionKey: string; minimal?: boolean; }; const PARAM_KEY = "selected_time_frame"; export function PeriodPicker({ defaultValue, sectionKey, items, minimal, }: PropsType) { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const [isOpen, setIsOpen] = useState(false); return ( span]:line-clamp-1 [&[data-state='open']>svg]:rotate-0", minimal && "border-none bg-transparent p-0 text-dark dark:bg-transparent dark:text-white", )} > {defaultValue || "Time Period"}
    {(items || ["monthly", "yearly"]).map((item) => (
  • ))}
); } const createQueryString = (props: { sectionKey: string; value: string; selectedTimeFrame: string | null; }) => { const paramsValue = `${props.sectionKey}:${props.value}`; if (!props.selectedTimeFrame) { return `?${PARAM_KEY}=${paramsValue}`; } const newSearchParams = props.selectedTimeFrame .split(",") .filter((value) => !value.includes(props.sectionKey)) .join(","); if (!newSearchParams) { return `?${PARAM_KEY}=${paramsValue}`; } return `?${PARAM_KEY}=${newSearchParams},${paramsValue}`; };