<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<?import ru.trader.view.support.NumberField?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import ru.trader.view.support.cells.DoubleCell?>
<?import ru.trader.view.support.cells.OfferCellValueImpl?>

<?import javafx.geometry.Insets?>
<?import ru.trader.view.support.cells.DistanceCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
      fx:controller="ru.trader.controllers.RouterController">
    <fx:define><Insets fx:id="fields_group_margin" left="2" right="10"/></fx:define>
    <fx:define><Insets fx:id="separator_margin" top="10" bottom="10"/></fx:define>

    <VBox minWidth="270">
        <TitledPane text="%router.pane.ship" minHeight="160" collapsible="false">
            <GridPane vgap="4">
                <columnConstraints>
                    <ColumnConstraints minWidth="150" />
                    <ColumnConstraints minWidth="100"  maxWidth="100"/>
                </columnConstraints>
                <Label text="%router.pane.ship.balance"/>
                <NumberField fx:id="balance" GridPane.columnIndex="1" />
                <Label text="%router.pane.ship.cargo" GridPane.rowIndex="1" />
                <NumberField fx:id="cargo" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                <Label text="%router.pane.ship.fueltank" GridPane.rowIndex="2" />
                <NumberField fx:id="tank" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                <Label text="%router.pane.ship.distance" GridPane.rowIndex="3" />
                <NumberField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="3" />
            </GridPane>
        </TitledPane>
        <TitledPane text="%router.pane.route" minHeight="320" collapsible="false">
            <GridPane vgap="4">
                <columnConstraints>
                    <ColumnConstraints minWidth="80"/>
                    <ColumnConstraints minWidth="170" maxWidth="170"/>
                </columnConstraints>
                <Label text="%router.pane.route.from" />
                <ComboBox fx:id="source" prefWidth="170" GridPane.columnIndex="1" />
                <ComboBox fx:id="sStation" prefWidth="170" GridPane.rowIndex="1" GridPane.columnIndex="1" />
                <Label text="%router.pane.route.to" GridPane.rowIndex="2"/>
                <ComboBox fx:id="target" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
                <ComboBox fx:id="tStation" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
                <Label text="%router.pane.route.jumps" GridPane.rowIndex="4" />
                <NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="4" />

                <Separator GridPane.columnSpan="2" GridPane.rowIndex="5" GridPane.margin="$separator_margin"/>
                <VBox GridPane.columnSpan="2" GridPane.rowIndex="6" spacing="5">
                    <HBox alignment="CENTER" spacing="5">
                        <Button fx:id="addBtn" text="%dialog.button.add" onAction="#addStationToRoute" />
                        <Button fx:id="editBtn" text="%dialog.button.edit" onAction="#editOrders"/>
                        <Button fx:id="removeBtn" text="%dialog.button.remove" onAction="#removeSelected"/>
                    </HBox>
                    <HBox alignment="CENTER" spacing="5">
                        <Button text="%router.button.recompute" onAction="#recompute"/>
                        <Button text="%router.button.rebuild" onAction="#rebuild"/>
                        <Button text="%dialog.button.clear" onAction="#removeAll" />
                    </HBox>
                    <HBox alignment="CENTER" spacing="5">
                        <Button prefWidth="80" text="%market.offers" onAction="#showOrders" />
                        <Button text="%router.button.top" onAction="#showTopOrders" />
                    </HBox>
                    <HBox alignment="CENTER" spacing="5">
                        <Button prefWidth="80" text="%router.button.routes" onAction="#showRoutes" />
                        <Button text="%router.button.top" onAction="#showTopRoutes" />
                    </HBox>
                </VBox>
            </GridPane>
        </TitledPane>
        <Pane VBox.vgrow="ALWAYS"/>
        <TitledPane text="%router.pane.total" minHeight="100" collapsible="false">
            <GridPane vgap="4">
                <columnConstraints>
                    <ColumnConstraints minWidth="80"/>
                    <ColumnConstraints minWidth="170"/>
                </columnConstraints>
                <Label text="%router.pane.ship.balance"/>
                <NumberField fx:id="totalBalance" prefWidth="100" GridPane.columnIndex="1" editable="false"/>
                <Label text="%router.pane.total.profit"  GridPane.rowIndex="1"/>
                <NumberField fx:id="totalProfit" prefWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="1" editable="false"/>
            </GridPane>
        </TitledPane>
    </VBox>
    <VBox HBox.hgrow="ALWAYS">
        <TableView fx:id="tblOrders" VBox.vgrow="ALWAYS">
            <columns>
                <TableColumn minWidth="140.0" text="%market.system.name">
                    <cellValueFactory><PropertyValueFactory property="system"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="150.0" text="%market.order.seller">
                    <cellValueFactory><PropertyValueFactory property="station"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="140.0" text="%market.item.name">
                    <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="80.0" text="%market.offer.price">
                    <cellFactory><DoubleCell/></cellFactory>
                    <cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="80.0" text="%market.order.count">
                    <cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="160.0" text="%market.order.buyer">
                    <cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="80.0" text="%market.order.distance">
                    <cellFactory><DistanceCell /></cellFactory>
                    <cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
                </TableColumn>
                <TableColumn minWidth="80.0" text="%market.order.profit">
                    <cellFactory><DoubleCell/></cellFactory>
                    <cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
                </TableColumn>
            </columns>
            <columnResizePolicy>
                <TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
            </columnResizePolicy>
        </TableView>
        <ScrollPane fx:id="path" styleClass="path-pane" minHeight="100" fitToHeight="true"/>
    </VBox>
</HBox>
