import { LOG_ACTION } from '@/types/enum';
import { m } from '@paraglide/messages';
import { Badge } from '@ui/badge';

export type UserActionType = {
  create: string;
  update: string;
  delete: string;
  ban: string;
  unban: string;
  sign_in: string;
  sign_out: string;
  change_password: string;
};

const ActionBadge = ({ action }: { action: LOG_ACTION }) => {
  const USER_ACTION = Object.freeze(
    new Proxy(
      {
        create: 'bg-green-400',
        update: 'bg-blue-400',
        delete: 'bg-red-400',
        sign_in: 'bg-lime-400',
        sign_out: 'bg-yellow-400',
        ban: 'bg-rose-400',
        unban: 'bg-emerald-400',
        change_password: 'bg-red-600',
      } as UserActionType,
      {
        get: function (target: UserActionType, name: string | symbol) {
          return target.hasOwnProperty(name as string)
            ? target[name as keyof UserActionType]
            : '';
        },
      },
    ),
  );

  return (
    <Badge variant="default" className={USER_ACTION[action]}>
      {m.logs_page_ui_badge_action({ action })}
    </Badge>
  );
};

export default ActionBadge;
