@page "/memberManagement/individualCustomer"
@attribute [ReuseTabsPage(Title = "个人用户")]


<PageHeader Title="个人用户" SubTitle=""></PageHeader>

<div class="customer-management-container">
    <!-- 查询区域 -->
    <div class="search-section">
        <div class="ant-row ant-row-start" style="margin-bottom: 20px;">
            <div class="ant-col ant-col-3" style="padding-right: 8px;">
                <input type="text"
                       class="ant-input"
                       placeholder="客户名称"
                       @bind="SearchCustomerName"
                       @bind:event="oninput" />
            </div>
            <div class="ant-col ant-col-3" style="padding-right: 8px;">
                <input type="text"
                       class="ant-input"
                       placeholder="客户编号"
                       @bind="SearchCustomerCode"
                       @bind:event="oninput" />
            </div>
            <div class="ant-col ant-col-3" style="padding-right: 8px;">
                <input type="text"
                       class="ant-input"
                       placeholder="客户手机号"
                       @bind="SearchCustomerMobile"
                       @bind:event="oninput" />
            </div>
            <!-- 操作按钮 -->
            <div class="ant-col ant-col-12" style="text-align: right;">
                <Button Type="@ButtonType.Primary" Icon="search" OnClick="HandleSearch">
                    查询
                </Button>
            </div>
        </div>
    </div>

    <!-- 客户列表表格 -->
    <div class="table-section">
        @if (Loading)
        {
            <div class="loading-container">
                <div class="ant-spin ant-spin-lg" style="margin: 20px auto;">
                    <span class="ant-spin-dot ant-spin-dot-spin">
                        <i class="ant-spin-dot-item"></i>
                        <i class="ant-spin-dot-item"></i>
                        <i class="ant-spin-dot-item"></i>
                        <i class="ant-spin-dot-item"></i>
                    </span>
                    <div class="ant-spin-text">加载中...</div>
                </div>
            </div>
        }
        else
        {
            <div class="ant-table-wrapper">
                <div class="ant-table">
                    <div class="ant-table-container">
                        <!-- 使用单个表格，确保表头和内容列对齐 -->
                        <div class="ant-table-content">
                            <table style="width: 100%; table-layout: fixed;">
                                <colgroup>
                                    <col style="width: 15%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 15%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 15%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 10%;" />
                                    <col style="width: 10%;" />
                                </colgroup>
                                <thead class="ant-table-thead">
                                    <tr>
                                        <th class="ant-table-cell">客户名称</th>
                                        <th class="ant-table-cell">客户编号</th>
                                        <th class="ant-table-cell">站点</th>
                                        <th class="ant-table-cell">手机号</th>
                                        <th class="ant-table-cell">注册时间</th>
                                        <th class="ant-table-cell">账户余额</th>
                                        <th class="ant-table-cell">微信头像</th>
                                        <th class="ant-table-cell">最近行为</th>
                                        <th class="ant-table-cell">最后活跃时间</th>
                                        <th class="ant-table-cell">操作</th>
                                    </tr>
                                </thead>
                                <tbody class="ant-table-tbody">
                                    @foreach (var customer in FilteredCustomers)
                                    {
                                        <tr class="ant-table-row">
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.Name
                                            </td>
                                            <td class="ant-table-cell">@customer.AccountNo</td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.StationName
                                            </td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.Mobile
                                            </td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.RegisterTime
                                            </td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.Balance
                                            </td>
                                            <td class="ant-table-cell">@customer.AvatarUrl</td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.RecentBehavior
                                            </td>
                                            <td class="ant-table-cell" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                                                @customer.LastActiveTime
                                            </td>
                                            <td class="ant-table-cell">
                                                <div style="display: flex; gap: 4px; flex-wrap: nowrap;">
                                                    <button type="button" class="ant-btn ant-btn-link ant-btn-sm"
                                                            @onclick="() => ShowCardManagement(customer)"
                                                            title="卡管理">
                                                        卡管理
                                                    </button>
                                                    <button type="button" class="ant-btn ant-btn-link ant-btn-sm"
                                                            @onclick="() => ShowEditModal(customer)"
                                                            title="编辑">
                                                        编辑
                                                    </button>
                                                </div>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- 分页 -->
                @if (TotalCount > 0)
                {
                    <div style="margin-top: 16px; text-align: right;">
                        <Pagination Total="@TotalCount"
                                    PageSize="@PageSize"
                                    Current="@CurrentPage"
                                    OnChange="@HandlePageChange"
                                    OnShowSizeChange="@HandlePageSizeChange"
                                    ShowSizeChanger
                                    ShowQuickJumper />
                    </div>
                }
            </div>
        }
    </div>
</div>
}

<style>
    /* 页面基础样式 */
    .customer-management-container {
        padding: 24px;
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        min-height: calc(100vh - 100px);
    }

    .search-section {
        margin-bottom: 30px;
        background: white;
        padding: 20px;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    }

    /* 表格样式 */
    .table-section {
        background: white;
        padding: 20px;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    }

    /* 模态框基础样式 */
    .modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        backdrop-filter: blur(5px);
        animation: fadeIn 0.3s ease;
    }

    /* 优雅的模态框样式 */
    .elegant-modal {
        background: white;
        border-radius: 16px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
        overflow: hidden;
        animation: slideUp 0.4s ease;
        max-height: 85vh;
        display: flex;
        flex-direction: column;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .modal-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 24px 30px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
    }

        .modal-header::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 5%;
            right: 5%;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
        }

    .modal-title {
        font-size: 20px;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .modal-icon {
        font-size: 24px;
    }

    .modal-close-btn {
        background: rgba(255, 255, 255, 0.2);
        border: none;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 20px;
        cursor: pointer;
        transition: all 0.3s ease;
    }

        .modal-close-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: rotate(90deg);
        }

    .modal-body {
        padding: 30px;
        flex: 1;
        overflow-y: auto;
        max-height: calc(85vh - 150px);
    }

        /* 移除滚动条样式 */
        .modal-body::-webkit-scrollbar {
            display: none;
        }

    .modal-body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    /* 表单卡片样式 */
    .form-card {
        background: white;
        border-radius: 12px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        margin-bottom: 24px;
        border: 1px solid #f0f0f0;
        transition: all 0.3s ease;
    }

        .form-card:hover {
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
            transform: translateY(-2px);
        }

    .card-header {
        padding: 20px 24px;
        border-bottom: 1px solid #f0f0f0;
        background: linear-gradient(to right, #f8f9ff, #ffffff);
    }

    .card-title {
        font-size: 16px;
        font-weight: 600;
        color: #2d3748;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .card-icon {
        font-size: 18px;
    }

    .card-body {
        padding: 24px;
    }

    /* 表单布局 */
    .form-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
    }

    .form-row {
        margin-bottom: 24px;
    }

        .form-row:last-child {
            margin-bottom: 0;
        }

    .form-group {
        margin-bottom: 0;
    }

        .form-group.full-width {
            grid-column: 1 / -1;
        }

    .form-label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
        color: #4a5568;
        font-size: 14px;
    }

        .form-label.required::after {
            content: '*';
            color: #ff4d4f;
            margin-left: 4px;
        }

    /* 表单控件样式 */
    .form-input, .form-select, .form-textarea {
        width: 100%;
        padding: 12px 16px;
        border: 2px solid #e2e8f0;
        border-radius: 8px;
        font-size: 14px;
        color: #2d3748;
        background: white;
        transition: all 0.3s ease;
        box-sizing: border-box;
    }

        .form-input:focus, .form-select:focus, .form-textarea:focus {
            outline: none;
            border-color: #4299e1;
            box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
        }

        .form-input:hover, .form-select:hover, .form-textarea:hover {
            border-color: #cbd5e0;
        }

    .form-textarea {
        resize: vertical;
        min-height: 80px;
    }

    .form-select {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%234a5568' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 16px center;
        background-size: 12px;
        padding-right: 40px;
    }

    /* 按钮样式 */
    .modal-footer {
        padding: 24px 30px;
        background: #f8fafc;
        border-top: 1px solid #e2e8f0;
        display: flex;
        justify-content: flex-end;
        gap: 12px;
    }

    .btn {
        padding: 12px 28px;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 500;
        border: none;
        cursor: pointer;
        transition: all 0.3s ease;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 100px;
    }

        .btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .btn:active {
            transform: translateY(0);
        }

    .btn-secondary {
        background: white;
        color: #4a5568;
        border: 2px solid #e2e8f0;
    }

        .btn-secondary:hover {
            background: #f7fafc;
            border-color: #cbd5e0;
        }

    .btn-primary {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
    }

        .btn-primary:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
            box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
        }

    .btn-icon {
        font-size: 16px;
    }

    /* 删除确认对话框样式 */
    .delete-confirm-modal {
        background: white;
        border-radius: 16px;
        padding: 40px;
        text-align: center;
        max-width: 400px;
        width: 90%;
        animation: slideUp 0.4s ease;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    }

    .delete-modal-content {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .delete-icon {
        font-size: 48px;
        margin-bottom: 20px;
        color: #fc8181;
    }

    .delete-title {
        font-size: 24px;
        font-weight: 600;
        color: #2d3748;
        margin-bottom: 16px;
    }

    .delete-message {
        font-size: 16px;
        color: #4a5568;
        margin-bottom: 12px;
        line-height: 1.5;
    }

    .delete-customer-name {
        color: #667eea;
        font-weight: 600;
    }

    .delete-warning {
        font-size: 14px;
        color: #718096;
        margin-bottom: 24px;
    }

    .delete-actions {
        display: flex;
        gap: 12px;
        width: 100%;
        justify-content: center;
    }

    .btn-cancel {
        background: white;
        color: #4a5568;
        border: 2px solid #e2e8f0;
        padding: 12px 28px;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s ease;
        min-width: 100px;
    }

        .btn-cancel:hover {
            background: #f7fafc;
            border-color: #cbd5e0;
        }

    .btn-delete {
        background: linear-gradient(135deg, #f56565 0%, #ed64a6 100%);
        color: white;
        border: none;
        padding: 12px 28px;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s ease;
        min-width: 100px;
    }

        .btn-delete:hover {
            background: linear-gradient(135deg, #e53e3e 0%, #d53f8c 100%);
            box-shadow: 0 4px 20px rgba(245, 101, 101, 0.3);
        }

    /* 动画效果 */
    @@keyframes fadeIn {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    @@keyframes slideUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* 响应式设计 */
    @@media (max-width: 850px) {
        .elegant-modal {
            width: 95% !important;
            margin: 20px;
        }

        .form-grid {
            grid-template-columns: 1fr;
        }
    }

    @@media (max-width: 600px) {
        .customer-management-container {
            padding: 12px;
        }

        .search-section,
        .table-section {
            padding: 16px;
        }

        .modal-header,
        .modal-body,
        .modal-footer {
            padding: 20px;
        }

        .form-grid {
            gap: 16px;
        }

        .card-body {
            padding: 16px;
        }

        .btn {
            padding: 10px 20px;
            min-width: 80px;
        }
    }

    /* 输入验证状态 */
    .form-input:invalid:not(:placeholder-shown),
    .form-select:invalid {
        border-color: #fc8181;
    }

    .form-input:valid:not(:placeholder-shown),
    .form-select:valid {
        border-color: #48bb78;
    }

    /* 表单分组间距优化 */
    .form-group + .form-group {
        margin-top: 0;
    }

    /* 添加一些细节装饰 */
    .form-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(90deg, #667eea, #764ba2);
        border-radius: 12px 12px 0 0;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .form-card:hover::before {
        opacity: 1;
    }
</style>
