<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<installer-gui-script minSpecVersion="2">
    <title>eTiKeT Sync Suite</title>
    <organization>com.quantum-machines</organization>
    <!-- Per-user install: no admin password prompt, files land under $HOME. -->
    <domains enable_localSystem="false" enable_anywhere="false" enable_currentUserHome="true"/>
    <!-- customize="always" forces the choice panel to be shown immediately
         instead of being hidden behind a "Customize" button. -->
    <options customize="always" require-scripts="true" rootVolumeOnly="false" hostArchitectures="arm64,x86_64"/>
    <script><![CDATA[
// All accessors below are defensive: macOS Installer evaluates
// `enabled`/`selected`/`start_selected` during choice initialisation, which
// happens in document order. When the first choice's `enabled` runs, later
// choices haven't been registered yet — accessing `my.choice.<later>.selected`
// would throw and the whole JS context would fail with the unhelpful
// "An error occurred while evaluating JavaScript for the package" message.

var ACTION_IDS = ['install', 'update', 'uninstall_keep_data', 'uninstall_remove_data'];

function isChoiceSelected(id) {
    try {
        if (typeof my === 'undefined' || typeof my.choice === 'undefined') return false;
        var c = my.choice[id];
        if (typeof c === 'undefined' || c === null) return false;
        return !!c.selected;
    } catch (e) {
        return false;
    }
}

function hasExistingInstall() {
    try {
        var home = (system && system.env && system.env.HOME) ? system.env.HOME : '';
        if (!home) return false;
        return system.files.fileExistsAtPath(
            home + "/Applications/quantum_machines/eTiKeT Service.app/Contents/MacOS/etiket_service_runner"
        );
    } catch (e) {
        return false;
    }
}

// Radio behaviour via reciprocal `enabled`: a choice is enabled only when
// no other action is currently selected. Combined with `start_selected`
// providing a sensible default, this gives the user a single-action picker
// without macOS Installer having native radio button widgets.
//
// We deliberately do NOT use an `<installation-check>` to validate "exactly
// one selected" — that hook fires at .pkg-open time, before the user has
// touched any choice, so all `my.choice.*.selected` are still null and the
// check would always fail. `start_selected` + reciprocal `enabled` are the
// right primitives for choice-state UX; installation-check is for
// environmental gates (OS version, architecture, disk space, etc.).
function onlyMeOrUnselected(myId) {
    for (var i = 0; i < ACTION_IDS.length; i++) {
        if (ACTION_IDS[i] === myId) continue;
        if (isChoiceSelected(ACTION_IDS[i])) return false;
    }
    return true;
}
]]></script>
    <choices-outline>
        <line choice="install"/>
        <line choice="update"/>
        <line choice="uninstall_keep_data"/>
        <line choice="uninstall_remove_data"/>
    </choices-outline>
    <!-- Install: download + bootstrap a fresh runner.
         Default-on when no existing install is detected. -->
    <choice id="install" title="Install" description="Install dataQruiser and set up the eTiKeT Sync Service. Choose this for a fresh install." start_selected="!hasExistingInstall()" enabled="onlyMeOrUnselected('install')">
        <pkg-ref id="com.quantum-machines.dataqruiser-installer.dataqruiser"/>
        <pkg-ref id="com.quantum-machines.dataqruiser-installer.install"/>
    </choice>
    <!-- Update: refresh package versions via 'pyapp self update'.
         Default-on when an existing install is detected. -->
    <choice id="update" title="Update existing installation" description="Refresh the installed runner's packages via pyapp's self-update. Does not change the runner binary version." start_selected="hasExistingInstall()" enabled="onlyMeOrUnselected('update')">
        <pkg-ref id="com.quantum-machines.dataqruiser-installer.update"/>
    </choice>
    <!-- Uninstall (keep data): remove apps + runner + pyapp env, preserve
         App Group container (sync DB, tokens, config). -->
    <choice id="uninstall_keep_data" title="Uninstall (keep data)" description="Remove dataQruiser and the eTiKeT Sync Service. Sync database, tokens, and config are preserved." start_selected="false" enabled="onlyMeOrUnselected('uninstall_keep_data')">
        <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_keep_data"/>
    </choice>
    <!-- Uninstall (remove all data): remove apps + runner + pyapp env +
         App Group container. Irreversible. -->
    <choice id="uninstall_remove_data" title="Uninstall (remove all data)" description="Remove dataQruiser, the eTiKeT Sync Service, AND all sync data. This action is irreversible." start_selected="false" enabled="onlyMeOrUnselected('uninstall_remove_data')">
        <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_remove_data"/>
    </choice>
    <!-- Sub-package references. The .install choice references both the
         dataqruiser payload pkg and the install action pkg; the update +
         uninstall choices reference only their action pkg (no dataQruiser
         payload, since they don't change/install dataQruiser). -->
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.dataqruiser" version="2.0.6" installKBytes="163149" updateKBytes="0">#dataqruiser.pkg</pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.install" version="2.0.6" installKBytes="0" updateKBytes="0">#install_action.pkg</pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.update" version="2.0.6" installKBytes="0" updateKBytes="0">#update_action.pkg</pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_keep_data" version="2.0.6" installKBytes="0" updateKBytes="0">#uninstall_keep_data_action.pkg</pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_remove_data" version="2.0.6" installKBytes="0" updateKBytes="0">#uninstall_remove_data_action.pkg</pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.dataqruiser">
        <bundle-version>
            <bundle CFBundleShortVersionString="1.0.0" CFBundleVersion="1" id="org.cocoapods.appkit-ui-element-colors-privacy" path="dataQruiser.app/Contents/Frameworks/appkit_ui_element_colors.framework/Versions/A/Resources/appkit_ui_element_colors_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.webview-flutter-wkwebview" path="dataQruiser.app/Contents/Frameworks/webview_flutter_wkwebview.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.pasteboard" path="dataQruiser.app/Contents/Frameworks/pasteboard.framework"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1.0" id="io.flutter.flutter-macos" path="dataQruiser.app/Contents/Frameworks/FlutterMacOS.framework"/>
            <bundle CFBundleShortVersionString="6.0.3" CFBundleVersion="1" id="org.cocoapods.OrderedSet-privacy" path="dataQruiser.app/Contents/Frameworks/OrderedSet.framework/Versions/A/Resources/OrderedSet_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.screen-retriever-macos" path="dataQruiser.app/Contents/Frameworks/screen_retriever_macos.framework"/>
            <bundle CFBundleShortVersionString="1.0.0" CFBundleVersion="1" id="org.cocoapods.appkit-ui-element-colors" path="dataQruiser.app/Contents/Frameworks/appkit_ui_element_colors.framework"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1.0" id="io.flutter.flutter.app" path="dataQruiser.app/Contents/Frameworks/App.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.objectbox-flutter-libs" path="dataQruiser.app/Contents/Frameworks/objectbox_flutter_libs.framework"/>
            <bundle CFBundleShortVersionString="6.4.1" CFBundleVersion="1" id="org.cocoapods.app-links" path="dataQruiser.app/Contents/Frameworks/app_links.framework"/>
            <bundle CFBundleShortVersionString="0.5.0" CFBundleVersion="1" id="org.cocoapods.window-manager" path="dataQruiser.app/Contents/Frameworks/window_manager.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.flutter-inappwebview-macos" path="dataQruiser.app/Contents/Frameworks/flutter_inappwebview_macos.framework"/>
            <bundle CFBundleShortVersionString="1.0.3" CFBundleVersion="1" id="org.cocoapods.open-file-mac-privacy" path="dataQruiser.app/Contents/Frameworks/open_file_mac.framework/Versions/A/Resources/open_file_mac_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.package-info-plus" path="dataQruiser.app/Contents/Frameworks/package_info_plus.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.connectivity-plus" path="dataQruiser.app/Contents/Frameworks/connectivity_plus.framework"/>
            <bundle CFBundleShortVersionString="0.1.0" CFBundleVersion="1" id="org.cocoapods.macos-ui" path="dataQruiser.app/Contents/Frameworks/macos_ui.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.super-native-extensions" path="dataQruiser.app/Contents/Frameworks/super_native_extensions.framework"/>
            <bundle CFBundleShortVersionString="6.4.1" CFBundleVersion="1" id="org.cocoapods.app-links-macos-privacy" path="dataQruiser.app/Contents/Frameworks/app_links.framework/Versions/A/Resources/app_links_macos_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.shared-preferences-foundation" path="dataQruiser.app/Contents/Frameworks/shared_preferences_foundation.framework"/>
            <bundle CFBundleShortVersionString="1.14.5" CFBundleVersion="1.14.5" id="com.qharbor.hdf5_c_libs" path="dataQruiser.app/Contents/Frameworks/hdf5_c_libs.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.url-launcher-macos" path="dataQruiser.app/Contents/Frameworks/url_launcher_macos.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.device-info-plus" path="dataQruiser.app/Contents/Frameworks/device_info_plus.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.irondash-engine-context" path="dataQruiser.app/Contents/Frameworks/irondash_engine_context.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.sqlite3-flutter-libs" path="dataQruiser.app/Contents/Frameworks/sqlite3_flutter_libs.framework"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1" id="io.objectbox.ObjectBox" path="dataQruiser.app/Contents/Frameworks/ObjectBox.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.webview-flutter-wkwebview-privacy" path="dataQruiser.app/Contents/Frameworks/webview_flutter_wkwebview.framework/Versions/A/Resources/webview_flutter_wkwebview_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.url-launcher-macos-privacy" path="dataQruiser.app/Contents/Frameworks/url_launcher_macos.framework/Versions/A/Resources/url_launcher_macos_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.1.5" CFBundleVersion="1" id="org.cocoapods.pdfium-flutter" path="dataQruiser.app/Contents/Frameworks/pdfium_flutter.framework"/>
            <bundle CFBundleShortVersionString="144.0.7811" CFBundleVersion="144.0.7811.0" id="com.pdfium.PDFium" path="dataQruiser.app/Contents/Frameworks/pdfium.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.flutter-inappwebview-macos-privacy" path="dataQruiser.app/Contents/Frameworks/flutter_inappwebview_macos.framework/Versions/A/Resources/flutter_inappwebview_macos_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.desktop-drop" path="dataQruiser.app/Contents/Frameworks/desktop_drop.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.package-info-plus-privacy" path="dataQruiser.app/Contents/Frameworks/package_info_plus.framework/Versions/A/Resources/package_info_plus_privacy.bundle"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1.0" id="io.flutter.flutter.native-assets.objective-c" path="dataQruiser.app/Contents/Frameworks/objective_c.framework"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.shared-preferences-foundation-privacy" path="dataQruiser.app/Contents/Frameworks/shared_preferences_foundation.framework/Versions/A/Resources/shared_preferences_foundation_privacy.bundle"/>
            <bundle CFBundleShortVersionString="3.52.0" CFBundleVersion="1" id="org.cocoapods.sqlite3" path="dataQruiser.app/Contents/Frameworks/sqlite3.framework"/>
            <bundle CFBundleShortVersionString="6.0.3" CFBundleVersion="1" id="org.cocoapods.OrderedSet" path="dataQruiser.app/Contents/Frameworks/OrderedSet.framework"/>
            <bundle CFBundleShortVersionString="2.0.6" CFBundleVersion="3" id="com.qdrive.dataQruiser" path="dataQruiser.app"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="1" id="org.cocoapods.connectivity-plus-privacy" path="dataQruiser.app/Contents/Frameworks/connectivity_plus.framework/Versions/A/Resources/connectivity_plus_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.0.1" CFBundleVersion="0.0.1" id="com.dataqruiser.numd_c_libs" path="dataQruiser.app/Contents/Frameworks/numd_c_libs.framework"/>
            <bundle CFBundleShortVersionString="1.0.3" CFBundleVersion="1" id="org.cocoapods.open-file-mac" path="dataQruiser.app/Contents/Frameworks/open_file_mac.framework"/>
            <bundle CFBundleShortVersionString="1.0.0" CFBundleVersion="1" id="org.cocoapods.macos-window-utils-privacy" path="dataQruiser.app/Contents/Frameworks/macos_window_utils.framework/Versions/A/Resources/macos_window_utils_privacy.bundle"/>
            <bundle CFBundleShortVersionString="0.1.0" CFBundleVersion="1" id="org.cocoapods.macos-ui-privacy" path="dataQruiser.app/Contents/Frameworks/macos_ui.framework/Versions/A/Resources/macos_ui_privacy.bundle"/>
            <bundle CFBundleShortVersionString="1.0.0" CFBundleVersion="1" id="org.cocoapods.macos-window-utils" path="dataQruiser.app/Contents/Frameworks/macos_window_utils.framework"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.install">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.update">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_keep_data">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.quantum-machines.dataqruiser-installer.uninstall_remove_data">
        <bundle-version/>
    </pkg-ref>
</installer-gui-script>