'use client';
import { useRouter } from 'next/navigation';
import { FoxButton } from '@fox/core/components/fox-button';
import { FoxButtonGroup } from '@fox/core/components/fox-button-group';
import { useBlockingAction } from '@/app/_hooks/use-blocking-action';
import { useFeedback } from '@/app/_hooks/use-feedback';
import type { MerchantDetailSummary } from '@/lib/domain/merchant-detail';
import { merchantDetailPath } from '@/lib/domain/merchant-detail-query';
import {
deleteMerchantDetailAction,
updateMerchantDetailVisibilityAction,
} from '../_actions';
interface MerchantDetailRowActionsProps {
row: MerchantDetailSummary;
}
/**
* 기획 BO-MAL-001 관리 열 — [수정] [비활성|노출] [삭제]. 목록에는 상세가 있는 가맹점만 서므로
* [수정]은 수정 화면으로 간다.
*/
export function MerchantDetailRowActions({ row }: MerchantDetailRowActionsProps) {
const router = useRouter();
const { showAlert, hideAlert, showToast } = useFeedback();
const [isBusy, startAction] = useBlockingAction();
function toggleVisibility() {
const next = row.isVisible === false;
startAction(async () => {
const result = await updateMerchantDetailVisibilityAction(row.id, next);
showToast(
result.status === 'error'
? { variant: 'danger', message: result.message }
: { variant: 'success', message: next ? '노출로 바꿨습니다.' : '비활성으로 바꿨습니다.' }
);
});
}
function runDelete() {
hideAlert();
startAction(async () => {
const result = await deleteMerchantDetailAction(row.id);
showToast(
result.status === 'error'
? { variant: 'danger', message: result.message }
: { variant: 'success', message: '삭제했습니다.' }
);
});
}
function confirmDelete() {
showAlert({
variant: 'danger',
title: '가맹몰 상세를 삭제하시겠습니까?',
message: `"${row.name}"의 상세 정보를 삭제합니다. 삭제 후에는 되돌릴 수 없습니다.`,
actions: (
),
});
}
return (
router.push(merchantDetailPath(row.id))}
/>
);
}