#!/bin/bash
C='\033[96m'; G='\033[92m'; Y='\033[93m'; R='\033[91m'
B='\033[1m';  D='\033[2m';  X='\033[0m'
echo ""
echo -e "${C}${B}  ─────────────────────────────────────────${X}"
echo -e "${C}${B}    FOTODESK  -  Instalador               ${X}"
echo -e "${C}${B}    Powered by CRYPT3CHO                  ${X}"
echo -e "${C}${B}  ─────────────────────────────────────────${X}"
echo ""
[[ "$(uname)" != "Darwin" ]] && echo -e "  ${R}Solo para macOS.${X}\n" && exit 1

echo -e "  ${D}Verificando Python 3...${X}"

if ! command -v python3 &>/dev/null; then

    command -v brew &>/dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    brew install python3

fi
echo -e "  ${G}✓ $(python3 --version)${X}"

echo -e "  ${D}Instalando dependencias...${X}"
python3 -m pip install paramiko fpdf2 psutil -q --break-system-packages 2>/dev/null || \
python3 -m pip install paramiko fpdf2 psutil -q 2>/dev/null || true
echo -e "  ${G}✓ Dependencias listas${X}"
mkdir -p "$HOME/.fotodesk"
echo -e "  ${D}Descargando FotoDesk...${X}"
curl -fsSL "https://fotos.crypt3cho.com/fotodesk_client.py" -o "$HOME/.fotodesk/fotodesk_client.py"

echo -e "  ${G}✓ FotoDesk descargado${X}"
cat > "$HOME/Desktop/Subir Fotos.command" << CMDEOF
#!/bin/bash
cd "\$HOME"
python3 "\$HOME/.fotodesk/fotodesk_client.py"
CMDEOF
chmod +x "$HOME/Desktop/Subir Fotos.command"
echo ""
echo -e "  ${C}${B}  ─────────────────────────────────────────${X}"
echo -e "  ${G}${B}  OK  INSTALACION COMPLETADA              ${X}"
echo -e "  ${C}${B}  ─────────────────────────────────────────${X}"
echo ""
echo -e "  ${B}Icono 'Subir Fotos' listo en tu Escritorio.${X}"
echo -e "  ${Y}Primera vez con camara: acepta el permiso de acceso.${X}"
echo ""
