"use client";
import React from "react";
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "./ui/select";
import {useRouter, useSearchParams} from "next/navigation";

export default function FilterByisDeleted() {
  const urlSearchParams = useSearchParams();

  const searchParams = new URLSearchParams(urlSearchParams);
  const router = useRouter();

  const handleFilter = (value: string) => {
    if (value === "true") {
      searchParams.set("is_deleted", value);
    }else{
      searchParams.delete("is_deleted");
    }
    router.push(
      `/patients${searchParams ? `?${searchParams.toString()}` : ""}`
    );
  };

  return (
    <>
      <Select onValueChange={handleFilter}>
        <SelectTrigger className="w-[180px] bg-white" dir="rtl">
          <SelectValue placeholder=" انتخاب کنید" />
        </SelectTrigger>
        <SelectContent>
          <SelectGroup>
            <SelectItem value="false">همه</SelectItem>
            <SelectItem value={"true"}>حذف شده ها</SelectItem>
          </SelectGroup>
        </SelectContent>
      </Select>
    </>
  );
}
