/*
 * iDescriptor: A free and open-source idevice management tool.
 *
 * Copyright (C) 2025 Uncore <https://github.com/uncor3>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef APPINSTALLDIALOG_H
#define APPINSTALLDIALOG_H

#include "appcontext.h"
#include "base/appdownload.h"
#include "iDescriptor-ui.h"
#include "iDescriptor.h"
#include "zloadingwidget.h"
#include <QApplication>
#include <QComboBox>
#include <QDialog>
#include <QDir>
#include <QFutureWatcher>
#include <QLabel>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QPainter>
#include <QPainterPath>
#include <QPushButton>
#include <QTemporaryDir>
#include <QVBoxLayout>

class AppInstallDialog : public AppDownloadBaseDialog
{
    Q_OBJECT
public:
    explicit AppInstallDialog(const QString &appName,
                              const QString &description,
                              const QString &bundleId,
                              QWidget *parent = nullptr);
    ~AppInstallDialog();

protected:
    void reject() override;

private slots:
    void onInstallClicked();

private:
    QComboBox *m_deviceCombo;
    QString m_bundleId;
    QLabel *m_statusLabel;
    QFutureWatcher<void> *m_installWatcher;
    IDLoadingIconLabel *m_iconLabel = nullptr;
    QTemporaryDir *m_tempDir = nullptr;
    ZLoadingWidget *m_loadingWidget = nullptr;
    QPushButton *m_cancelButton = nullptr;
    void updateDeviceList();
    void performInstallation(const QString &ipaPath, const QString &ipaName,
                             const QString &deviceUdid);
};

#endif // APPINSTALLDIALOG_H
