<Window
  x:Class="VPet.ModMaker.Views.ModEdit.AnimeEdit.AnimeEditWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"
  xmlns:local="clr-namespace:VPet.ModMaker.Views.ModEdit.AnimeEdit"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:pu="https://opensource.panuon.com/wpf-ui"
  xmlns:vm="clr-namespace:VPet.ModMaker.ViewModels.ModEdit.AnimeEdit"
  Title="{ll:Str 编辑动画}"
  Width="1000"
  Height="600"
  d:DataContext="{d:DesignInstance Type=vm:AnimeEditWindowVM}"
  WindowStartupLocation="CenterScreen"
  mc:Ignorable="d">
  <Window.Resources>
    <Style
      x:Key="ListBoxItem_Style"
      BasedOn="{StaticResource {x:Type ListBoxItem}}"
      TargetType="ListBoxItem">
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
      <Setter Property="VerticalContentAlignment" Value="Stretch" />
    </Style>
    <DataTemplate x:Key="Expander_AnimeItem" DataType="Expander">
      <Expander
        HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        d:DataContext=""
        Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
        <Expander.ContextMenu>
          <ContextMenu d:DataContext="">
            <MenuItem
              d:Header="添加图片"
              Command="{Binding PlacementTarget.Tag.AddImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              Header="{ll:Str 添加图片}"
              IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
            <MenuItem
              d:Header="清空图片"
              Command="{Binding PlacementTarget.Tag.ClearImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              Header="{ll:Str 清空图片}"
              IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
            <MenuItem
              d:Header="删除此项"
              Command="{Binding PlacementTarget.Tag.RemoveAnimeCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
              Header="{ll:Str 删除此项}"
              IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
          </ContextMenu>
        </Expander.ContextMenu>
        <Expander.Header>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="Auto" MinWidth="200" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock Margin="10,0,10,0">
              <TextBlock.Text>
                <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
                  <Binding Path="Images.Count" />
                </MultiBinding>
              </TextBlock.Text>
            </TextBlock>
            <TextBox
              Grid.Column="1"
              pu:TextBoxHelper.Watermark="{ll:Str 动画Id(非必要)}"
              Text="{Binding Id.Value, UpdateSourceTrigger=PropertyChanged}" />
            <!--  pu:TextBoxHelper.Watermark="{ll:Str 动画Id(非必要)}"  -->
            <ComboBox
              Grid.Column="2"
              Margin="10,0,0,0"
              ItemsSource="{Binding DataContext.Anime.Value.AnimatTypes, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
              SelectedItem="{Binding AnimeType.Value}"
              Visibility="{Binding DataContext.HasMultiType.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}, Converter={StaticResource FalseToHiddenConverter}}" />
          </Grid>
        </Expander.Header>
        <ListBox
          d:ItemsSource="{d:SampleData ItemCount=5}"
          AllowDrop="True"
          Drop="ListBox_Drop"
          ItemsSource="{Binding Images, IsAsync=True}"
          PreviewMouseMove="ListBox_PreviewMouseMove"
          PreviewMouseWheel="ListBox_PreviewMouseWheel"
          SelectedItem="{Binding DataContext.CurrentImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
          SelectionChanged="ListBox_SelectionChanged">
          <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
              <WrapPanel />
            </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
          <ListBox.ItemTemplate>
            <DataTemplate>
              <Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Expander, Mode=FindAncestor}}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
                <Grid.ContextMenu>
                  <ContextMenu>
                    <MenuItem
                      d:Header="修改图片"
                      Command="{Binding PlacementTarget.Tag.ChangeImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
                      CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
                      Header="{ll:Str 修改图片}"
                      IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
                    <MenuItem
                      d:Header="删除图片"
                      Command="{Binding PlacementTarget.Tag.RemoveImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
                      CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
                      Header="{ll:Str 删除图片}"
                      IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
                  </ContextMenu>
                </Grid.ContextMenu>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition />
                </Grid.RowDefinitions>
                <Image
                  Width="150"
                  Height="150"
                  d:DataContext=""
                  DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
                  Source="{Binding Image.Value, IsAsync=True}">
                  <Image.ToolTip>
                    <Image
                      Width="250"
                      Height="250"
                      Source="{Binding Image.Value, IsAsync=True}" />
                  </Image.ToolTip>
                </Image>
                <Grid Grid.Row="1">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                  </Grid.ColumnDefinitions>
                  <Label d:Content="持续时间(ms)" Content="{ll:Str 持续时间(ms)}" />
                  <pu:NumberInput Grid.Column="1" Value="{Binding DataContext.Duration.Value, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" />
                </Grid>
              </Grid>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
      </Expander>
    </DataTemplate>
  </Window.Resources>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition />
      </Grid.RowDefinitions>
      <Image
        Width="250"
        Height="250"
        Source="{Binding CurrentImageModel.Value.Image.Value}">
        <Image.ToolTip>
          <Image
            Width="500"
            Height="500"
            Source="{Binding CurrentImageModel.Value.Image.Value}" />
        </Image.ToolTip>
      </Image>
      <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Button Command="{Binding StopCommand}" Content="{ll:Str 停止}" />
        <Button
          Grid.Column="1"
          Command="{Binding PlayCommand}"
          Content="{ll:Str 播放}" />
        <ToggleButton
          Grid.Column="2"
          Content="{ll:Str 循环}"
          IsChecked="{Binding Loop.Value}" />
      </Grid>
      <Grid Grid.Row="2">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <!--<Label Content="{ll:Str 动画Id}" />
        <TextBox Grid.Column="1" />-->
        <Label Content="{ll:Str 动画类型}" />
        <TextBlock Grid.Column="1" Text="{Binding Anime.Value.GraphType.Value}" />
        <Label
          Grid.Row="1"
          Content="{ll:Str 动画名称}"
          Visibility="{Binding HasAnimeName.Value, Converter={StaticResource FalseToHiddenConverter}}" />
        <TextBox
          Grid.Row="1"
          Grid.Column="1"
          pu:TextBoxHelper.Watermark="{ll:Str 动画名称}"
          Text="{Binding Anime.Value.Name.Value, UpdateSourceTrigger=PropertyChanged}"
          Visibility="{Binding HasAnimeName.Value, Converter={StaticResource FalseToHiddenConverter}}" />
      </Grid>
    </Grid>
    <Grid Grid.Column="1">
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <TabControl SelectionChanged="TabControl_SelectionChanged">
        <TabItem d:Header="Happy (0)" Tag="Happy">
          <TabItem.Header>
            <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0} ({1})">
              <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}" />
              <Binding Path="Anime.Value.HappyAnimes.Count" />
            </MultiBinding>
          </TabItem.Header>
          <ListBox
            x:Name="ListBox_Animes"
            d:ItemsSource="{d:SampleData ItemCount=5}"
            d:SelectedIndex="0"
            ItemContainerStyle="{StaticResource ListBoxItem_Style}"
            ItemTemplate="{StaticResource Expander_AnimeItem}"
            ItemsSource="{Binding Anime.Value.HappyAnimes, IsAsync=True}"
            SelectionChanged="ListBox_Animes_SelectionChanged" />
        </TabItem>
        <TabItem d:Header="Nomal (0)" Tag="Nomal">
          <TabItem.Header>
            <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0} ({1})">
              <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}" />
              <Binding Path="Anime.Value.NomalAnimes.Count" />
            </MultiBinding>
          </TabItem.Header>
          <ListBox
            d:ItemsSource="{d:SampleData ItemCount=5}"
            d:SelectedIndex="0"
            ItemContainerStyle="{StaticResource ListBoxItem_Style}"
            ItemTemplate="{StaticResource Expander_AnimeItem}"
            ItemsSource="{Binding Anime.Value.NomalAnimes, IsAsync=True}" />
        </TabItem>
        <TabItem d:Header="PoorCondition (0)" Tag="PoorCondition">
          <TabItem.Header>
            <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0} ({1})">
              <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}" />
              <Binding Path="Anime.Value.PoorConditionAnimes.Count" />
            </MultiBinding>
          </TabItem.Header>
          <ListBox
            d:ItemsSource="{d:SampleData ItemCount=5}"
            d:SelectedIndex="0"
            ItemContainerStyle="{StaticResource ListBoxItem_Style}"
            ItemTemplate="{StaticResource Expander_AnimeItem}"
            ItemsSource="{Binding Anime.Value.PoorConditionAnimes, IsAsync=True}" />
        </TabItem>
        <TabItem d:Header="Ill (0)" Tag="Ill">
          <TabItem.Header>
            <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0} ({1})">
              <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}" />
              <Binding Path="Anime.Value.IllAnimes.Count" />
            </MultiBinding>
          </TabItem.Header>
          <ListBox
            d:ItemsSource="{d:SampleData ItemCount=5}"
            d:SelectedIndex="0"
            ItemContainerStyle="{StaticResource ListBoxItem_Style}"
            ItemTemplate="{StaticResource Expander_AnimeItem}"
            ItemsSource="{Binding Anime.Value.IllAnimes, IsAsync=True}" />
        </TabItem>
      </TabControl>
      <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Button
          x:Name="Button_AddAnime"
          Margin="10"
          Command="{Binding AddAnimeCommand}"
          Content="{ll:Str 添加动画}" />
        <Button
          x:Name="Button_Cancel"
          Grid.Column="1"
          Margin="10"
          Click="Button_Cancel_Click"
          Content="{ll:Str 取消}" />
        <Button
          x:Name="Button_Yes"
          Grid.Column="2"
          Margin="10"
          Click="Button_Yes_Click"
          Content="{ll:Str 确定}" />
      </Grid>
    </Grid>
  </Grid>
</Window>
