@namespace ThingsGateway.Gateway.Razor
@using ThingsGateway.Admin.Application
@using ThingsGateway.Admin.Razor
@using ThingsGateway.Foundation
@using ThingsGateway.Gateway.Application
@inherits ComponentDefault

<div class="channel">

    @if (ValidateEnable)
    {
        <ValidateForm Model="Model" OnValidSubmit="ValidSubmit">


            <EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=200 Model="Model">

                <FieldItems>
                    <EditorItem TValue="string" TModel="Channel" @bind-Field="@context.Name">
                        <EditTemplate Context="value">
                            <div class="col-12">
                                <h6>@GatewayLocalizer["BasicInformation"]</h6>
                            </div>
                        </EditTemplate>
                    </EditorItem>

                    <EditorItem @bind-Field="@context.Name" Readonly=BatchEditEnable />


                    <EditorItem @bind-Field="@context.PluginName">
                        <EditTemplate Context="value">
                            <div class="col-12  col-md-6">
                                <Select @bind-Value="@value.PluginName"
                                        Items="@PluginNames" IsDisabled=BatchEditEnable
                                        ShowSearch="true">
                                    <ItemTemplate Context="name">
                                        @if (PluginDcit.TryGetValue(name.Value, out var pluginOutput))
                                        {
                                            if (pluginOutput.EducationPlugin)
                                            {
                                                <div class="d-flex">
                                                    <span>@name.Text</span>
                                                    <div style="flex-grow: 1;"></div>
                                                    <Tag Color="Color.Primary">PRO</Tag>
                                                </div>
                                            }
                                            else
                                            {
                                                <span>@name.Text</span>
                                            }
                                        }
                                        else
                                        {
                                            <span>@name.Value</span>
                                        }
                                    </ItemTemplate>
                                </Select>
                            </div>
                        </EditTemplate>
                    </EditorItem>

                    <EditorItem @bind-Field="@context.Enable" />
                    <EditorItem @bind-Field="@context.LogEnable" />
                    <EditorItem @bind-Field="@context.LogLevel" />

                    <EditorItem TValue="string" TModel="Channel" @bind-Field="@context.Name">
                        <EditTemplate Context="value">
                            <div class="col-12">
                                <h6>@GatewayLocalizer["Connection"]</h6>
                            </div>
                        </EditTemplate>
                    </EditorItem>

                    <EditorItem @bind-Field="@context.ChannelType">

                        <EditTemplate Context="value">
                            <div class="col-12 col-sm-6 col-md-6">
                                <Select SkipValidate="true" @bind-Value="@value.ChannelType" OnSelectedItemChanged=@((a)=>InvokeAsync(StateHasChanged)) />
                            </div>
                        </EditTemplate>

                    </EditorItem>


                    <EditorItem @bind-Field="@context.RemoteUrl" Ignore=@(context.ChannelType!=ChannelTypeEnum.TcpClient&&context.ChannelType!=ChannelTypeEnum.UdpSession) />
                    <EditorItem @bind-Field="@context.BindUrl" Ignore=@(context.ChannelType!=ChannelTypeEnum.TcpClient&&context.ChannelType!=ChannelTypeEnum.UdpSession&&context.ChannelType!=ChannelTypeEnum.TcpService) />

                    <EditorItem @bind-Field="@context.PortName" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.BaudRate" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.DataBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.Parity" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />
                    <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) />


                    <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) />
                    <EditorItem @bind-Field="@context.ConnectTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.TcpService||context.ChannelType==ChannelTypeEnum.Other) />
                    <EditorItem @bind-Field="@context.MaxConcurrentCount" Ignore=@(context.ChannelType==ChannelTypeEnum.Other) />

                </FieldItems>
                <Buttons>
                    <Button ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" IsAsync Text=@RazorLocalizer["Save"] />
                </Buttons>
            </EditorForm>

        </ValidateForm>


    }
</div>