<?xml version="1.0" encoding="UTF-8"?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Bit.App.Lists.ItemLayouts.CustomFields.LinkedCustomFieldItemLayout"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:cfvm="clr-namespace:Bit.App.Lists.ItemViewModels.CustomFields"
    xmlns:core="clr-namespace:Bit.Core;assembly=BitwardenCore"
    x:DataType="cfvm:LinkedCustomFieldItemViewModel"
    Spacing="0" Padding="0">
    <StackLayout.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:BooleanToBoxRowInputPaddingConverter x:Key="booleanToBoxRowInputPaddingConverter" />
        </ResourceDictionary>
    </StackLayout.Resources>
    <Grid
        StyleClass="box-row"
        Padding="{Binding IsEditing, Converter={StaticResource booleanToBoxRowInputPaddingConverter}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Label
            Text="{Binding Field.Name, Mode=OneWay}"
            StyleClass="box-label"
            Grid.Row="0"
            Grid.Column="0" />
        <controls:IconLabel
            Text="{Binding ValueText, Mode=OneWay}"
            StyleClass="box-value"
            Grid.Row="1"
            Grid.Column="0"
            IsVisible="{Binding IsEditing, Mode=OneWay, Converter={StaticResource inverseBool}}" />
        <StackLayout
            StyleClass="box-row, box-row-input"
            IsVisible="{Binding IsEditing}">
            <Picker
                x:Name="_linkedFieldOptionPicker"
                ItemsSource="{Binding LinkedFieldOptions, Mode=OneTime}"
                SelectedIndex="{Binding LinkedFieldOptionSelectedIndex}"
                ItemDisplayBinding="{Binding Key}"
                StyleClass="box-value" />
        </StackLayout>
        <controls:IconButton 
            StyleClass="box-row-button, box-row-button-platform"
            Text="{Binding Source={x:Static core:BitwardenIcons.Cog}}"
            Command="{Binding FieldOptionsCommand}"
            IsVisible="{Binding IsEditing}"
            Grid.Row="0"
            Grid.Column="1"
            Grid.RowSpan="2"
            AutomationProperties.IsInAccessibleTree="True"
            AutomationProperties.Name="{u:I18n Options}" />
    </Grid>
    <BoxView StyleClass="box-row-separator" IsVisible="{Binding IsEditing, Mode=OneWay, Converter={StaticResource inverseBool}}" />
</StackLayout>
