@using Microsoft.Extensions.Configuration
@inject IConfiguration configuration

@if (Datas != null)
{
    <AntDesign.Table @ref="table" @bind-PageIndex="_pageIndex" @bind-PageSize="_pageSize"
                     TItem="AppealRecord"
                     Loading="_loading"
                     DataSource="@Datas"
                     OnRow="OnRow"
                     Total="_total"
                     ScrollX="1150" Size="TableSize.Small" Bordered
                     >
        <ChildContent>
            <AntDesign.Column Title="序号" TData="string" Width="80">
                <center> @serialNumber(_pageIndex, _pageSize, context)</center>
            </AntDesign.Column>
            <AntDesign.Column Title="申诉时间"  Width="150" @bind-Field="@context.CreateTime" Format="yyyy-MM-dd hh:mm:ss" Sortable Filterable />
            <AntDesign.Column Title="申诉类型"  Width="160" DataIndex="Type.Name" TData="string" Sortable Filterable />
            <AntDesign.Column Title="申诉人" Width="90" DataIndex="Creater.Name" TData="string" Sortable Filterable />
            <AntDesign.Column Title="案号" Width="100" DataIndex="Item.CaseNo" TData="string" Sortable Filterable />
            <AntDesign.Column Title="案件名称" Width="300" DataIndex="Item.CaseName" TData="string" Sortable Filterable />
            <AntDesign.Column Title="审核人" Width="90" DataIndex="Reviewer.Name" TData="string" Sortable Filterable />
            <AntDesign.Column Title="状态"  Width="80" TData="string" Sortable>
                <Template>
                    @if (context.State == 0)
                    {
                        <span>待审核</span>
                    }
                    else
                    {
                        <span>已审核</span>
                    }
                </Template>
            </AntDesign.Column>
            @if (ShowAction) { 
            <ActionColumn>
                <Space>
                    @if (context.State == 0 && context.ReviewerId == UserId)
                    {
                        <SpaceItem><Button Type="@ButtonType.Link" OnClick="() => _OnReview(context)">审核</Button></SpaceItem>
                    }
                    @if (context.State == 0 && (context.ReviewerId == UserId || context.CreaterId == UserId))
                    {
                        <SpaceItem><Button Type="@ButtonType.Link" OnClick="() => _OnChangeReviewer(context)">变更审核人</Button></SpaceItem>
                    }
                </Space>
            </ActionColumn>
            }
        </ChildContent>
        <PaginationTemplate>
            <div style="display: flex; align-items: center">
                <Pagination Class="my-custom-pagination"
                            Total="@_total"
                            PageSize="@_pageSize"
                            Current="@_pageIndex"
                            ShowSizeChanger="@true"
                            OnChange="HandlePageChange" />
            </div>
        </PaginationTemplate>
    </AntDesign.Table>
}
else
{
    <Spin></Spin>
}

<Drawer Width="600" Visible="_ShowDetail" Placement="right" Title='("申诉详情")' OnClose="_=>CloseDetail()">


    @if (CurrentAppealRecord != null && CurrentAppealRecord.Item != null)
    {

        <div>
            <Row>
                <AntDesign.Col Span="4"><b>我方文号:</b></AntDesign.Col>
                <AntDesign.Col Span="8">@CurrentAppealRecord.Item.CaseNo</AntDesign.Col>
                <AntDesign.Col Span="4"><b>处理事项:</b></AntDesign.Col>
                <AntDesign.Col Span="8">@CurrentAppealRecord.Item.DoItem</AntDesign.Col>
            </Row>

            <Row>
                <AntDesign.Col Span="4"><b>案件名称:</b></AntDesign.Col>
                <AntDesign.Col Span="20">@CurrentAppealRecord.Item.CaseName</AntDesign.Col>
            </Row>
        </div>

    }


    @if (_FieldValues != null)
    {
        <Divider Orientation="left" Style="font-weight:bold">申诉人：@CurrentAppealRecord.Creater.Name  申诉时间：@CurrentAppealRecord.CreateTime.ToString("yyyy-MM-dd")  </Divider>

        foreach (InputFieldValue temValue in _FieldValues)
        {
            <Row>
                <AntDesign.Col Span="2"></AntDesign.Col>
                <AntDesign.Col Span="8"><b>@temValue.InputField.FieldName:</b></AntDesign.Col>
                <AntDesign.Col Span="14">@temValue.Value</AntDesign.Col>
            </Row>
        }
    }
    <Divider />

    @if (_ReviewValues != null)
    {
        <Divider Orientation="left" Style="font-weight:bold">审核人：@CurrentAppealRecord.Reviewer.Name  审核时间：@CurrentAppealRecord.ReviewTime?.ToString("yyyy-MM-dd")  </Divider>
        foreach (InputFieldValue temValue in _ReviewValues)
        {
            <Row>
                <AntDesign.Col Span="2"></AntDesign.Col>
                <AntDesign.Col Span="8"><b>@temValue.InputField.FieldName:</b></AntDesign.Col>
                <AntDesign.Col Span="14">@temValue.Value</AntDesign.Col>
            </Row>
        }
    }

    @if (attachFiles != null && attachFiles.Count > 0)
    {
        <Divider Orientation="left" Style="font-weight:bold">附件</Divider>

        <Row>
            <AntDesign.Col Span="2"></AntDesign.Col>
            <AntDesign.Col Span="14">文件名称</AntDesign.Col>
            <AntDesign.Col Span="8">上传人</AntDesign.Col>
        </Row>
        @foreach (AttachFile file in attachFiles)
        {
            <Row>
                <AntDesign.Col Span="2"></AntDesign.Col>
                <AntDesign.Col Span="14"><a href="@($"{configuration.GetValue<string>("APIUrl")}AttachFiles/Download?id={file.Id}")">@file.Name </a></AntDesign.Col>
                <AntDesign.Col Span="8">@file.UploadUser.Name</AntDesign.Col>
            </Row>
        }
    }
</Drawer>

<style>
    .my-custom-pagination {
        margin: 15px 0;
    }

        .my-custom-pagination .ant-pagination-item,
        .my-custom-pagination .ant-pagination-item-link {
            border-radius: 100%;
        }
</style>