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

<?import javafx.collections.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import tornadofx.control.*?>
<?import org.controlsfx.control.RangeSlider?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.drongo.policy.PolicyType?>
<?import com.sparrowwallet.drongo.protocol.ScriptType?>
<?import com.sparrowwallet.sparrow.control.DescriptorArea?>
<?import org.fxmisc.flowless.VirtualizedScrollPane?>
<?import org.controlsfx.glyphfont.Glyph?>

<?import com.sparrowwallet.sparrow.control.HelpLabel?>
<BorderPane stylesheets="@settings.css, @wallet.css, @../script.css, @../descriptor.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.SettingsController">
    <center>
        <GridPane hgap="10.0" vgap="10.0">
            <padding>
                <Insets left="25.0" right="25.0" top="25.0" />
            </padding>
            <columnConstraints>
                <ColumnConstraints percentWidth="50" />
                <ColumnConstraints percentWidth="50" />
            </columnConstraints>
            <rowConstraints>
                <RowConstraints />
                <RowConstraints />
            </rowConstraints>

            <Form GridPane.columnIndex="0" GridPane.rowIndex="0">
                <Fieldset inputGrow="SOMETIMES" text="Settings" styleClass="header">
                    <Field text="Policy Type:">
                        <ComboBox fx:id="policyType">
                            <items>
                                <FXCollections fx:factory="observableArrayList">
                                    <PolicyType fx:constant="SINGLE" />
                                    <PolicyType fx:constant="MULTI" />
                                    <!-- <PolicyType fx:constant="CUSTOM" /> -->
                                </FXCollections>
                            </items>
                        </ComboBox>
                        <HelpLabel helpText="Single signature wallets use a single keystore (hardware wallet or seed).\nMultisignature wallets require multiple keystores (N), of which a certain number (M) need to sign." />
                    </Field>
                    <Field text="Script Type:">
                        <ComboBox fx:id="scriptType">
                            <items>
                                <FXCollections fx:factory="observableArrayList">
                                    <!-- <ScriptType fx:constant="P2PK" /> -->
                                    <ScriptType fx:constant="P2PKH" />
                                    <ScriptType fx:constant="P2SH" />
                                    <ScriptType fx:constant="P2SH_P2WPKH" />
                                    <ScriptType fx:constant="P2SH_P2WSH" />
                                    <ScriptType fx:constant="P2WPKH" />
                                    <ScriptType fx:constant="P2WSH" />
                                </FXCollections>
                            </items>
                        </ComboBox>
                        <HelpLabel helpText="Native Segwit types are the default and are usually the best choice.\nNested Segwit types are a good choice for the widest compatibility with older wallets.\nLegacy types should be avoided, unless configuring an old wallet." />
                    </Field>
                </Fieldset>
            </Form>

            <Form GridPane.columnIndex="1" GridPane.rowIndex="0">
                <Fieldset inputGrow="SOMETIMES" text="" fx:id="multisigFieldset">
                    <Field text="Cosigners:">
                        <RangeSlider fx:id="multisigControl" showTickMarks="true" showTickLabels="true" blockIncrement="1" min="1" max="9" highValue="3" lowValue="2" snapToTicks="true" majorTickUnit="1" minorTickCount="0" />
                    </Field>
                    <Field text="M of N:">
                        <CopyableLabel fx:id="multisigLowLabel" />
                        <CopyableLabel text="/"/>
                        <CopyableLabel fx:id="multisigHighLabel" />
                    </Field>
                </Fieldset>
            </Form>

            <Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="1">
                <Fieldset inputGrow="SOMETIMES" text="Script Policy">
                    <Field text="Descriptor:">
                        <VirtualizedScrollPane hbarPolicy="NEVER" vbarPolicy="NEVER">
                            <content>
                                <DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" />
                            </content>
                        </VirtualizedScrollPane>
                        <Button onAction="#scanDescriptorQR">
                            <graphic>
                                <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="CAMERA" />
                            </graphic>
                            <tooltip>
                                <Tooltip text="Scan a QR code" />
                            </tooltip>
                        </Button>
                        <Button text="Edit..." onAction="#editDescriptor" />
                    </Field>
                </Fieldset>
            </Form>

            <Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="2">
                <Fieldset inputGrow="SOMETIMES" text="Keystores">
                        <StackPane styleClass="keystore-padding-border">
                            <StackPane styleClass="etched-raised-border">
                                <StackPane fx:id="keystoreTabsPane"/>
                            </StackPane>
                        </StackPane>
                </Fieldset>
            </Form>
        </GridPane>
    </center>
    <bottom>
        <AnchorPane>
            <padding>
                <Insets left="25.0" right="25.0" bottom="25.0" />
            </padding>
            <HBox AnchorPane.leftAnchor="0" spacing="20">
                <Button fx:id="export" text="Export..." onAction="#exportWallet" />
            </HBox>
            <HBox AnchorPane.rightAnchor="10" spacing="20">
                <Button text="Advanced..." onAction="#showAdvanced" />
                <Button fx:id="revert" text="Revert" cancelButton="true" />
                <Button fx:id="apply" text="Apply" defaultButton="true" />
            </HBox>
        </AnchorPane>
    </bottom>
</BorderPane>
