@page "/admin/onboarding/staff"
@layout AdminLayout
@inherits AdminBase

@*
    EN: Onboarding Step 4 — Add staff members (name, role, email, PIN, staff list preview).
    VI: Bước 4 thiết lập — Thêm nhân viên (tên, vai trò, email, PIN, danh sách).
    Design: pencil-design/src/pages/tPOS/admin/onboarding-staff.pen
*@

<PageTitle>Thêm nhân viên — GoodGo Admin</PageTitle>

<div style="display:flex;height:100vh;overflow:hidden;">

    @* ═══ SIDEBAR — Step Progress ═══ *@
    <div style="width:260px;min-width:260px;background-color:var(--admin-bg-elevated);border-right:1px solid var(--admin-border-subtle);display:flex;flex-direction:column;height:100vh;">
        <div style="display:flex;align-items:center;gap:12px;padding:24px;border-bottom:1px solid var(--admin-border-subtle);">
            <div style="width:40px;height:40px;border-radius:12px;background:var(--admin-orange-gradient);display:flex;align-items:center;justify-content:center;color:#FFF;font-size:20px;font-weight:800;">G</div>
            <div style="display:flex;flex-direction:column;gap:2px;">
                <span style="font-size:16px;font-weight:700;">GoodGo Admin</span>
                <span style="font-size:11px;color:var(--admin-text-tertiary);">Thiết lập ban đầu</span>
            </div>
        </div>
        <div style="flex:1;padding:32px 24px;display:flex;flex-direction:column;">
            <span style="font-size:10px;font-weight:700;color:var(--admin-text-tertiary);letter-spacing:0.05em;margin-bottom:16px;">TIẾN TRÌNH</span>
            @foreach (var s in _steps)
            {
                var step = s;
                var isCompleted = step.Index < 4;
                var isCurrent = step.Index == 4;
                <div style="display:flex;align-items:center;gap:14px;padding:10px 8px;border-radius:10px;
                    background-color:@(isCurrent ? "rgba(255,92,0,0.08)" : "transparent");">
                    <div style="width:32px;height:32px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:700;
                        background-color:@(isCompleted ? "#22C55E" : isCurrent ? "var(--admin-orange-primary)" : "var(--admin-bg-interactive)");
                        color:@(isCompleted || isCurrent ? "#FFF" : "var(--admin-text-tertiary)");
                        border:@(!isCompleted && !isCurrent ? "2px solid var(--admin-border-default)" : "none");">
                        @(isCompleted ? "✓" : step.Index)
                    </div>
                    <span style="font-size:14px;font-weight:@(isCurrent ? "600" : "500");color:@(isCompleted ? "var(--admin-text-primary)" : isCurrent ? "var(--admin-orange-primary)" : "var(--admin-text-tertiary)");">@step.Label</span>
                </div>
                @if (step.Index < 6)
                {
                    <div style="width:2px;height:24px;margin-left:23px;background-color:@(isCompleted ? "#22C55E" : "var(--admin-border-default)");"></div>
                }
            }
        </div>
    </div>

    @* ═══ MAIN CONTENT ═══ *@
    <div style="flex:1;display:flex;align-items:center;justify-content:center;padding:40px;overflow-y:auto;">
        <div class="admin-panel" style="width:720px;max-width:100%;padding:32px;border-radius:16px;display:flex;flex-direction:column;gap:24px;">

            <div style="display:flex;flex-direction:column;gap:8px;">
                <h2 style="font-size:22px;font-weight:700;margin:0;">Thêm nhân viên</h2>
                <p style="font-size:14px;color:var(--admin-text-tertiary);margin:0;">Mời nhân viên tham gia hệ thống hoặc bỏ qua để thêm sau</p>
            </div>

            @* Invite form *@
            <div style="display:flex;gap:12px;align-items:flex-end;">
                <div class="admin-form-group" style="flex:1;">
                    <label class="admin-form-label">Email nhân viên</label>
                    <input class="admin-form-input" type="email" placeholder="nhanvien@email.com" @bind="_newStaffEmail" />
                </div>
                <div class="admin-form-group" style="width:200px;">
                    <label class="admin-form-label">Vai trò</label>
                    <select class="admin-form-input" @bind="_newStaffRole">
                        <option value="cashier">Thu ngân</option>
                        <option value="manager">Quản lý</option>
                        <option value="barista">Barista</option>
                        <option value="waiter">Phục vụ</option>
                    </select>
                </div>
                <button class="admin-btn-primary" style="height:44px;" @onclick="InviteStaff">
                    <i data-lucide="user-plus" style="width:18px;height:18px;"></i>
                    <span>Mời</span>
                </button>
            </div>

            @* Staff list *@
            <div style="display:flex;flex-direction:column;">
                <span style="font-size:13px;font-weight:600;color:var(--admin-text-secondary);margin-bottom:8px;">Đã mời (@_staffList.Count)</span>
                @foreach (var staff in _staffList)
                {
                    var s = staff;
                    <div style="display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-bottom:1px solid var(--admin-border-subtle);">
                        <div style="display:flex;align-items:center;gap:12px;">
                            <div class="admin-user-avatar" style="width:36px;height:36px;font-size:13px;background-color:@s.Color;">@s.Initials</div>
                            <div style="display:flex;flex-direction:column;gap:2px;">
                                <span style="font-size:14px;font-weight:600;">@s.Email</span>
                                <span style="font-size:12px;color:var(--admin-text-tertiary);">@s.Role</span>
                            </div>
                        </div>
                        <div class="admin-status-badge admin-status-badge--setup">
                            <div class="admin-status-badge__dot"></div>
                            Đang chờ
                        </div>
                    </div>
                }
            </div>

            @* Footer *@
            <div style="display:flex;justify-content:space-between;padding-top:8px;">
                <div style="display:flex;gap:12px;">
                    <button class="admin-btn-secondary" @onclick="@(() => NavigateTo("onboarding/products"))">
                        <i data-lucide="arrow-left"></i>
                        <span>Quay lại</span>
                    </button>
                </div>
                <div style="display:flex;gap:12px;">
                    <button class="admin-btn-secondary" @onclick="@(() => NavigateTo("onboarding/device"))">
                        <span>Bỏ qua</span>
                    </button>
                    <button class="admin-btn-primary" @onclick="@(() => NavigateTo("onboarding/device"))">
                        <span>Tiếp tục</span>
                        <i data-lucide="arrow-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

@code {
    private string _newStaffEmail = "";
    private string _newStaffRole = "cashier";

    private record StaffItem(string Email, string Role, string Initials, string Color);
    private List<StaffItem> _staffList = new()
    {
        new("nguyenvana@email.com", "Quản lý", "NA", "#3B82F6"),
        new("tranthib@email.com", "Thu ngân", "TB", "#8B5CF6"),
    };

    private void InviteStaff()
    {
        if (!string.IsNullOrWhiteSpace(_newStaffEmail))
        {
            var initials = _newStaffEmail[..2].ToUpper();
            var roleName = _newStaffRole switch { "manager" => "Quản lý", "barista" => "Barista", "waiter" => "Phục vụ", _ => "Thu ngân" };
            _staffList.Add(new(_newStaffEmail, roleName, initials, "#EC4899"));
            _newStaffEmail = "";
        }
    }

    private record StepInfo(int Index, string Label);
    private readonly StepInfo[] _steps = new[]
    {
        new StepInfo(1, "Doanh nghiệp"),
        new StepInfo(2, "Cửa hàng"),
        new StepInfo(3, "Sản phẩm"),
        new StepInfo(4, "Nhân viên"),
        new StepInfo(5, "Thiết bị"),
        new StepInfo(6, "Hoàn tất"),
    };
}
