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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import org.controlsfx.glyphfont.Glyph?>
<?import ru.trader.view.support.cells.*?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          fx:controller="ru.trader.controllers.OffersController"
        prefHeight="500">

    <fx:define><Insets fx:id="stationsMargin" left="5" right="5" /></fx:define>
    <fx:define><Insets fx:id="stationsPadding" left="12" right="10" /></fx:define>

    <fx:define>
        <ContextMenu fx:id="editMenu">
            <items>
                <MenuItem text="%main.menu.edit.editSystem" onAction="#editSystem" />
                <SeparatorMenuItem />
                <MenuItem text="%main.menu.edit.addStation" onAction="#addStation" />
                <MenuItem text="%main.menu.edit.editStation" onAction="#editStation" />
                <MenuItem text="%main.menu.edit.removeStation" onAction="#removeStation" />
            </items>
        </ContextMenu>
    </fx:define>

    <columnConstraints>
        <ColumnConstraints minWidth="270" maxWidth="270"/>
        <ColumnConstraints fillWidth="true"/>
    </columnConstraints>

    <VBox GridPane.rowSpan="2" GridPane.vgrow="ALWAYS" minWidth="270">
        <TitledPane text="%market.system"  collapsible="false">
            <HBox><TextField fx:id="systemText" HBox.hgrow="ALWAYS" /><Button minWidth="30" onAction="#currentSystem"><graphic><Glyph text="FontAwesome|MAP_MARKER"/></graphic></Button></HBox>
        </TitledPane>
        <TitledPane VBox.vgrow="ALWAYS" text="%market.stations" collapsible="false">
            <ListView fx:id="stationsList">
                <contextMenu><fx:reference source="editMenu"/></contextMenu>
            </ListView>
        </TitledPane>
    </VBox>
    <TitledPane fx:id="stationPane" GridPane.columnIndex="1"
                minHeight="120" maxHeight="120" collapsible="false">
            <GridPane hgap="4" vgap="4">
                <columnConstraints>
                    <ColumnConstraints minWidth="80"/>
                    <ColumnConstraints minWidth="80"/>
                    <ColumnConstraints minWidth="140" />
                    <ColumnConstraints minWidth="100" />
                    <ColumnConstraints minWidth="140" />
                    <ColumnConstraints minWidth="110" />
                    <ColumnConstraints minWidth="140" />
                    <ColumnConstraints hgrow="ALWAYS" />
                </columnConstraints>
                <HBox GridPane.columnIndex="7" GridPane.rowSpan="2" alignment="TOP_RIGHT">
                    <Label fx:id="warningIcon" styleClass="icon-warning" prefWidth="30" prefHeight="30" visible="false">
                        <graphic><Glyph text="FontAwesome|WARNING" /></graphic>
                    </Label>
                </HBox>
                <HBox GridPane.rowIndex="2" spacing="4" alignment="BOTTOM_CENTER">
                    <Button minWidth="30" minHeight="25" onAction="#showOffers"><graphic><Glyph text="FontAwesome|EXCHANGE"/></graphic></Button>
                    <Button minWidth="30" minHeight="25" onAction="#showOffersByRoute"><graphic><Glyph text="FontAwesome|SHARE"/></graphic></Button>
                </HBox>

                <Label text="%label.station.type" GridPane.columnIndex="1"/>
                <Label fx:id="type" GridPane.columnIndex="2"/>
                <Label text="%label.government" GridPane.columnIndex="3" />
                <Label fx:id="government" GridPane.columnIndex="4" />
                <Label text="%label.allegiance" GridPane.columnIndex="5"/>
                <Label fx:id="faction" GridPane.columnIndex="6" />


                <Label text="%label.station.distance" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                <Label fx:id="distance" GridPane.rowIndex="1" GridPane.columnIndex="2" />
                <Label text="%label.economic" GridPane.rowIndex="1" GridPane.columnIndex="3" />
                <Label fx:id="economic" GridPane.rowIndex="1" GridPane.columnIndex="4" />
                <Label fx:id="subeconomic"  GridPane.rowIndex="1" GridPane.columnIndex="5" GridPane.columnSpan="2"/>


                <Label text="%label.station.services" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
                <TilePane GridPane.rowIndex="2" GridPane.columnIndex="2" GridPane.columnSpan="6" GridPane.hgrow="ALWAYS"
                          hgap="5" vgap="5" prefColumns="4" tileAlignment="BASELINE_LEFT">
                    <CheckBox fx:id="cbMarket" text="%services.MARKET"/>
                    <CheckBox fx:id="cbBlackMarket" text="%services.BLACK_MARKET"/>
                    <CheckBox fx:id="cbRefuel" text="%services.REFUEL"/>
                    <CheckBox fx:id="cbRepair" text="%services.REPAIR"/>
                    <CheckBox fx:id="cbMunition" text="%services.MUNITION"/>
                    <CheckBox fx:id="cbOutfit" text="%services.OUTFIT"/>
                    <CheckBox fx:id="cbShipyard" text="%services.SHIPYARD"/>
                </TilePane>
            </GridPane>
        <contextMenu><fx:reference source="editMenu"/></contextMenu>
    </TitledPane>
    <Accordion GridPane.rowIndex="1" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
        <panes>
            <TitledPane fx:id="paneSells" animated="false" text="%offers.pane.sell">
              <TableView fx:id="tblSell" editable="true">
                  <rowFactory><OfferDecoratedRow /></rowFactory>
                  <columns>
                      <TableColumn minWidth="230.0" text="%market.item">
                          <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn minWidth="110.0" text="%market.offer.price" onEditCommit="#editPrice">
                          <cellFactory><PriceCellImpl/></cellFactory>
                          <cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn minWidth="80.0" text="%market.offer.supply">
                          <cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn fx:id="sortSell" minWidth="90.0" text="%market.order.profit" sortType="DESCENDING">
                          <cellFactory><DoubleCell/></cellFactory>
                          <cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn text="%market.offer.avg">
                        <columns>
                            <TableColumn minWidth="80.0" text="%market.offer.sell">
                                <cellFactory><DoubleCell/></cellFactory>
                                <cellValueFactory><PropertyValueFactory property="avgSell"/></cellValueFactory>
                            </TableColumn>
                            <TableColumn minWidth="80.0" text="%market.offer.buy">
                                <cellFactory><DoubleCell/></cellFactory>
                                <cellValueFactory><PropertyValueFactory property="avgBuy"/></cellValueFactory>
                            </TableColumn>
                        </columns>
                      </TableColumn>
                      <TableColumn text="%market.offer.best">
                        <columns>
                            <TableColumn minWidth="120.0" text="%market.offer.sell">
                                <cellValueFactory><OfferCellValueImpl property="bestSell"/></cellValueFactory>
                            </TableColumn>
                            <TableColumn minWidth="120.0" text="%market.offer.buy">
                                <cellValueFactory><OfferCellValueImpl property="bestBuy"/></cellValueFactory>
                            </TableColumn>
                        </columns>
                      </TableColumn>
                  </columns>
                  <columnResizePolicy>
                      <TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
                  </columnResizePolicy>
                  <sortOrder>
                      <fx:reference source="sortSell"/>
                  </sortOrder>
              </TableView>
            </TitledPane>
            <TitledPane animated="false" text="%offers.pane.buy">
              <TableView fx:id="tblBuy" editable="true">
                  <rowFactory><OfferDecoratedRow /></rowFactory>
                  <columns>
                      <TableColumn minWidth="230.0" text="%market.item">
                          <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn minWidth="110.0" text="%market.offer.price" editable="true" onEditCommit="#editPrice">
                          <cellFactory><PriceCellImpl/></cellFactory>
                          <cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn minWidth="80.0" text="%market.offer.demand">
                          <cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn fx:id="sortBuy" minWidth="90.0" text="%market.order.profit" sortType="DESCENDING">
                          <cellFactory><DoubleCell/></cellFactory>
                          <cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
                      </TableColumn>
                      <TableColumn text="%market.offer.avg">
                          <columns>
                              <TableColumn minWidth="80.0" text="%market.offer.sell">
                                  <cellFactory><DoubleCell/></cellFactory>
                                  <cellValueFactory><PropertyValueFactory property="avgSell"/></cellValueFactory>
                              </TableColumn>
                              <TableColumn minWidth="80.0" text="%market.offer.buy">
                                  <cellFactory><DoubleCell/></cellFactory>
                                  <cellValueFactory><PropertyValueFactory property="avgBuy"/></cellValueFactory>
                              </TableColumn>
                          </columns>
                      </TableColumn>
                      <TableColumn text="%market.offer.best">
                          <columns>
                              <TableColumn minWidth="120.0" text="%market.offer.sell">
                                  <cellValueFactory><OfferCellValueImpl property="bestSell"/></cellValueFactory>
                              </TableColumn>
                              <TableColumn minWidth="120.0" text="%market.offer.buy">
                                  <cellValueFactory><OfferCellValueImpl property="bestBuy"/></cellValueFactory>
                              </TableColumn>
                          </columns>
                      </TableColumn>
                  </columns>
                  <columnResizePolicy>
                      <TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
                  </columnResizePolicy>
                  <sortOrder>
                      <fx:reference source="sortBuy"/>
                  </sortOrder>
              </TableView>
            </TitledPane>
        </panes>
        <expandedPane>
            <fx:reference source="paneSells"/>
        </expandedPane>
    </Accordion>
</GridPane>
