/**
 * Copyright (c) 2023-present Plane Software, Inc. and contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 * See the LICENSE file for details.
 */

import { ListFilter } from "lucide-react";
// plane imports
import { useTranslation } from "@plane/i18n";
import { ChevronDownIcon } from "@plane/propel/icons";
import { cn } from "@plane/utils";
// components
import { FiltersDropdown } from "@/components/issues/issue-layouts/filters";
// hooks
import useSize from "@/hooks/use-window-size";
// local imports
import { InboxIssueFilterSelection } from "./filters/filter-selection";
import { InboxIssueOrderByDropdown } from "./sorting/order-by";

type TFiltersRootProps = {
  compact?: boolean;
  className?: string;
};

export function FiltersRoot(props: TFiltersRootProps) {
  const { compact = false, className } = props;
  const windowSize = useSize();
  const { t } = useTranslation();
  const useCompactButtons = compact || windowSize[0] <= 1280;

  const smallButton = (
    <div className="nodedc-external-icon-button">
      <ListFilter className="size-3.5" />
    </div>
  );

  const largeButton = (
    <div
      className={cn(
        "nodedc-external-action-button flex min-h-[2.5rem] items-center gap-2 px-4 py-0 text-13 font-medium"
      )}
    >
      <ListFilter className="size-3.5" />
      <span>{t("filters")}</span>
      <ChevronDownIcon className="size-3" strokeWidth={2} />
    </div>
  );

  return (
    <div className={cn("relative flex min-w-0 items-center gap-2", className)}>
      <div>
        <FiltersDropdown menuButton={useCompactButtons ? smallButton : largeButton} title="" placement="bottom-end">
          <InboxIssueFilterSelection />
        </FiltersDropdown>
      </div>
      <div>
        <InboxIssueOrderByDropdown compact={useCompactButtons} />
      </div>
    </div>
  );
}
