"use client";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { ApprovalRequestModal } from "./ApprovalRequestModal";

export interface ApprovalButtonProps {
  objIds: string[];
  targetType: string;
  title?: string;
  description?: string;
  onSuccess?: () => void;
  disabled?: boolean;
  label?: string;
  size?: "sm" | "md" | "lg";
  variant?: "primary" | "secondary" | "danger" | "ghost";
}

// 공통 결재상신 버튼 - 어느 목록/폼에서나 한 줄로 사용
// <ApprovalButton objIds={selectedIds} targetType="CSM" title={...} onSuccess={fetchData} />
export function ApprovalButton({
  objIds, targetType, title, description, onSuccess,
  disabled, label = "결재상신", size = "sm", variant = "secondary",
}: ApprovalButtonProps) {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button
        size={size}
        variant={variant}
        disabled={disabled}
        onClick={() => setOpen(true)}
      >
        {label}
      </Button>
      <ApprovalRequestModal
        open={open}
        onClose={() => setOpen(false)}
        objIds={objIds}
        targetType={targetType}
        defaultTitle={title}
        defaultDescription={description}
        onSuccess={onSuccess}
      />
    </>
  );
}
