'use client';

import { useCustomerMutation } from '@/hooks/api/customers';
import { useClientOnce } from '@/hooks/telegram';
import { initData, useSignal } from '@telegram-apps/sdk-react';

export function UpdateProfile() {
  const initDataUser = useSignal(initData.user);
  const { mutate: updateProfile } = useCustomerMutation();

  useClientOnce(() => {
    if (
      localStorage.getItem('firstLogin') === null ||
      localStorage.getItem('firstLogin') === 'true'
    ) {
      updateProfile({
        data: {
          active: true,
          photoUrl: initDataUser?.photoUrl || undefined,
        },
      });
      localStorage.setItem('firstLogin', 'false');
    }
  });

  return null;
}
