/*
 * uNav http://launchpad.net/unav
 * Copyright (C) 2015-2016 Marcos Alvarez Costales https://launchpad.net/~costales
 * Copyright (C) 2016 Nekhelesh Ramananthan https://launchpad.net/~nik90
 *
 * uNav is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * uNav 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 General Public License for more details.
 */

import QtQuick 2.4
import Ubuntu.Content 1.3
import Ubuntu.Components 1.3
import "components"

Page {
    id: picker

    property var lat
    property var lon

    header: UNavHeader {
        title: i18n.tr("Share location to")

        // #FIXME: This back button is only here to allow the user to press Escape keyboard key to go back.
        // This feature will be implemented upstream by the SDK devs when they add keyboard shortcuts to pages,
        // at which point this back button can be removed.
        leadingActionBar.actions: Action {
            iconName: "back"
            text: i18n.tr("Back")
            shortcut: "Escape"
            onTriggered: {
                mainPageStack.pop()
            }
        }
    }

    Component {
        id: resultComponent
        ContentItem {}
    }

    ContentPeerPicker {
        id: peerPicker

        showTitle: false
        contentType: ContentType.Links
        handler: ContentHandler.Share

        anchors.topMargin: picker.header.height

        onCancelPressed: {
            mainPageStack.pop()
        }

        onPeerSelected: {
            var request = peer.request();
            var url2shared = 'http://unav-go.github.io/?p=' + parseFloat(picker.lat).toFixed(5) + ',' + parseFloat(picker.lon).toFixed(5);
            request.items = [ resultComponent.createObject(navApp.mainPageStack, {"url": url2shared}) ];
            request.state = ContentTransfer.Charged;
            mainPageStack.pop()
        }
    }
}
