import { router } from '@inertiajs/react';
import type { ReactNode } from 'react';

type SystemRecordActionsProps = {
    activeUrl: string;
    children: ReactNode;
    isActive: boolean;
    isSystem: boolean;
};

export function SystemRecordActions({
    activeUrl,
    children,
    isActive,
    isSystem,
}: SystemRecordActionsProps) {
    if (!isSystem) {
        return <>{children}</>;
    }

    return (
        <button
            type="button"
            onClick={() =>
                router.patch(
                    activeUrl,
                    { is_active: !isActive },
                    { preserveScroll: true },
                )
            }
            className="rounded-md border border-[#0b7285]/40 px-2.5 py-1 text-xs font-medium text-[#0b7285] hover:bg-[#e6f7fa] dark:border-[#a78bfa]/50 dark:text-[#c4b5fd] dark:hover:bg-[#2a1d50]"
        >
            {isActive ? 'Deactivate' : 'Activate'}
        </button>
    );
}
