"use client";

import * as React from "react";
import { ArrowRightLeft, Pencil, UserPlus } from "lucide-react";
import { Button } from "@/components/ui/button";
import type { DealsPipelineUiCopy } from "./pipeline-ui-copy";

export type DealsPipelineBulkSelectionBarProps = {
  selectedCount: number;
  pipelineUi: DealsPipelineUiCopy;
  canUpdateDeal: boolean;
  canBulkAssignLead?: boolean;
  canBulkEditLead?: boolean;
  onClear: () => void;
  onOpenBulkStageTransfer: () => void;
  onOpenBulkEdit?: () => void;
  onGoToBulkAssignPage?: () => void;
};

export const DealsPipelineBulkSelectionBar = React.memo(
  function DealsPipelineBulkSelectionBar({
    selectedCount,
    pipelineUi,
    canUpdateDeal,
    canBulkAssignLead = false,
    canBulkEditLead = false,
    onClear,
    onOpenBulkStageTransfer,
    onOpenBulkEdit,
    onGoToBulkAssignPage,
  }: DealsPipelineBulkSelectionBarProps) {
    if (selectedCount <= 0) return null;

    return (
      <div className="flex items-center justify-between gap-3 mb-3 px-4 py-2.5 rounded-xl bg-accent/10 border border-accent/20">
        <span className="text-[13px] font-bold text-accent font-['Lexend']">
          {pipelineUi.bulkSelectedLabel(selectedCount)}
        </span>
        <div className="flex items-center gap-2">
          <Button
            variant="outline"
            size="sm"
            onClick={onClear}
            className="h-8 text-[12px]"
          >
            Clear
          </Button>
          {canUpdateDeal ? (
            <Button
              size="sm"
              variant="outline"
              onClick={onOpenBulkStageTransfer}
              className="h-8 gap-1.5 text-[12px] border-accent/40 text-accent hover:bg-accent/10"
            >
              <ArrowRightLeft size={13} /> Move Stage
            </Button>
          ) : null}
          {canBulkEditLead && onOpenBulkEdit ? (
            <Button
              size="sm"
              variant="outline"
              onClick={onOpenBulkEdit}
              className="h-8 gap-1.5 text-[12px] border-accent/40 text-accent hover:bg-accent/10"
            >
              <Pencil size={13} /> Bulk edit
            </Button>
          ) : null}

          {canBulkAssignLead && onGoToBulkAssignPage ? (
            <Button
              size="sm"
              onClick={onGoToBulkAssignPage}
              className="h-8 gap-1.5 text-[12px]"
            >
              <UserPlus size={13} /> Bulk Assign
            </Button>
          ) : null}
        </div>
      </div>
    );
  },
);
