@namespace AntSK.Pages.FunPage
@using AntSK.Domain.Repositories
@using AntSK.Domain.Domain.Model.Enum
@using AntSK.Domain.Domain.Model.Fun
@page "/plugins/funlist"
@using AntSK.Services.Auth
@inherits AuthComponentBase

<PageContainer Title="函数列表">
    <Content>
        <div style="text-align: center;">
            <Search Placeholder="输入回车"
                    EnterButton="@("搜索")"
                    Size="large"
                    Style="max-width: 522px; width: 100%;"
                    OnSearch="Search" />
        </div>
    </Content>
    <ChildContent>
        <div class="cardList">
            <AntList TItem="FunDto"
                     DataSource="_data"
                     ItemLayout="ListItemLayout.Horizontal"
                     Grid="LayoutModel._listGridType">
                <ListItem NoFlex>
                    @if (string.IsNullOrEmpty(context.Name))
                    {
                        <Card Hoverable Bordered Class="card" Style="height:160px; display:flex; align-items:center; justify-content:center;">
                            <div style="display:flex; gap:12px; flex-wrap:wrap; justify-content:center;">
                                <Button Type="dashed" class="newButton" @onclick="AddFun">
                                    <Icon Type="plus" Theme="outline" /> 创建函数
                                </Button>
                                <Button Type="dashed" class="newButton" @onclick="ClearFun">
                                    <Icon Type="clear" Theme="outline" /> 清空导入函数
                                </Button>
                            </div>
                        </Card>
                    }
                    else
                    {
                        <Card Hoverable Bordered Class="card" Style="height:160px; overflow:hidden;">
                             <CardMeta>
                                 <AvatarTemplate>

                                 </AvatarTemplate>
                                 <TitleTemplate>
                                     <a>@context.Name</a>
                                </TitleTemplate>
                                <DescriptionTemplate>
                                    <Paragraph class="item" Ellipsis Style="margin-bottom:8px;">
                                     <!--todo: Ellipsis not working-->
                                     @context.Description
                                    </Paragraph>
                                    @if (context.Parameters?.Count > 0)
                                    {
                                        <div style="margin-top:8px; max-height:140px; overflow:auto; padding-right:4px;">
                                            <span style="font-weight:600;">参数：</span>
                                            <ul style="margin: 6px 0 0 18px; padding:0;">
                                                @foreach (var p in context.Parameters)
                                                {
                                                    <li style="list-style: disc;">
                                                        <span style="color:#3b3b3b">@p.Name</span>
                                                        <span style="color:#999"> (@p.Type)</span>
                                                        @if (!string.IsNullOrWhiteSpace(p.Description))
                                                        {
                                                            <span style="color:#666"> - @p.Description</span>
                                                        }
                                                    </li>
                                                }
                                            </ul>
                                        </div>
                                    }
                                </DescriptionTemplate>
                            </CardMeta>
                        </Card>
                    }
                </ListItem>
            </AntList>
        </div>
    </ChildContent>
</PageContainer>


<Modal Title="插件导入"
       Visible="@_fileVisible"
       OnOk="@FileHandleOk"
       OnCancel="@FileHandleCancel"
       ConfirmLoading="@_fileConfirmLoading">
    <Upload Action="@("api/File/UploadFile")"
            Name="file"
            Drag
            Multiple
             Accept="*/*"
             BeforeUpload="BeforeUpload"
             OnSingleCompleted="OnSingleCompleted">
         <p class="ant-upload-drag-icon">
             <Icon Type="inbox" />
         </p>
         <p class="ant-upload-text">单击或拖动文件到此区域进行上传</p>
         <p class="ant-upload-hint">
             请上传dll文件
         </p>
     </Upload>
 </Modal>
@code
{
 
}
