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

@*
    EN: Onboarding Step 3 — Add initial products (quick form, CSV import, product list preview).
    VI: Bước 3 thiết lập — Thêm sản phẩm ban đầu (form nhanh, import CSV, danh sách).
    Design: pencil-design/src/pages/tPOS/admin/onboarding-products.pen
*@

<PageTitle>Thêm sản phẩm — 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 < 3;
                var isCurrent = step.Index == 3;
                <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 sản phẩm</h2>
                <p style="font-size:14px;color:var(--admin-text-tertiary);margin:0;">Thêm sản phẩm vào cửa hàng hoặc bỏ qua để thêm sau</p>
            </div>

            @* Import options *@
            <div style="display:flex;gap:16px;">
                <div style="flex:1;height:80px;border-radius:12px;background-color:var(--admin-bg-interactive);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;cursor:pointer;">
                    <i data-lucide="file-spreadsheet" style="width:24px;height:24px;color:var(--admin-text-tertiary);"></i>
                    <span style="font-size:13px;color:var(--admin-text-tertiary);">Import từ CSV</span>
                </div>
                <div style="flex:1;height:80px;border-radius:12px;background-color:rgba(255,92,0,0.08);border:2px solid var(--admin-orange-primary);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;cursor:pointer;">
                    <i data-lucide="pencil" style="width:24px;height:24px;color:var(--admin-orange-primary);"></i>
                    <span style="font-size:13px;color:var(--admin-orange-primary);font-weight:600;">Nhập thủ công</span>
                </div>
            </div>

            @* Quick add form *@
            <div style="display:flex;gap:12px;align-items:flex-end;">
                <div class="admin-form-group" style="flex:1;">
                    <label class="admin-form-label">Tên sản phẩm</label>
                    <input class="admin-form-input" type="text" placeholder="VD: Cà phê sữa đá" @bind="_newProductName" />
                </div>
                <div class="admin-form-group" style="width:140px;">
                    <label class="admin-form-label">Giá bán</label>
                    <input class="admin-form-input" type="text" placeholder="35,000" @bind="_newProductPrice" />
                </div>
                <div class="admin-form-group" style="width:140px;">
                    <label class="admin-form-label">Danh mục</label>
                    <select class="admin-form-input" @bind="_newProductCategory">
                        <option value="">Chọn</option>
                        <option value="drink">Đồ uống</option>
                        <option value="food">Đồ ăn</option>
                        <option value="dessert">Tráng miệng</option>
                    </select>
                </div>
                <button style="width:40px;height:40px;min-width:40px;border-radius:10px;background-color:var(--admin-orange-primary);border:none;display:flex;align-items:center;justify-content:center;cursor:pointer;" @onclick="AddProduct">
                    <i data-lucide="plus" style="width:20px;height:20px;color:#FFF;"></i>
                </button>
            </div>

            @* Product list preview *@
            <div style="display:flex;flex-direction:column;">
                <span style="font-size:13px;font-weight:600;color:var(--admin-text-secondary);margin-bottom:8px;">Sản phẩm đã thêm (@_products.Count)</span>
                @foreach (var product in _products)
                {
                    var p = product;
                    <div style="display:flex;align-items:center;justify-content:space-between;padding:12px 0;border-bottom:1px solid var(--admin-border-subtle);">
                        <div style="display:flex;align-items:center;gap:12px;">
                            <div style="width:36px;height:36px;border-radius:8px;background-color:var(--admin-bg-interactive);display:flex;align-items:center;justify-content:center;">
                                <i data-lucide="package" style="width:16px;height:16px;color:var(--admin-text-tertiary);"></i>
                            </div>
                            <div style="display:flex;flex-direction:column;gap:2px;">
                                <span style="font-size:14px;font-weight:600;">@p.Name</span>
                                <span style="font-size:12px;color:var(--admin-text-tertiary);">@p.Category</span>
                            </div>
                        </div>
                        <span style="font-size:14px;font-weight:600;color:var(--admin-orange-primary);">@p.Price</span>
                    </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/store"))">
                        <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/staff"))">
                        <span>Bỏ qua</span>
                    </button>
                    <button class="admin-btn-primary" @onclick="@(() => NavigateTo("onboarding/staff"))">
                        <span>Tiếp tục</span>
                        <i data-lucide="arrow-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

@code {
    private string _newProductName = "";
    private string _newProductPrice = "";
    private string _newProductCategory = "";

    private record ProductItem(string Name, string Price, string Category);
    private List<ProductItem> _products = new()
    {
        new("Cà phê sữa đá", "35,000đ", "Đồ uống"),
        new("Trà sen vàng", "45,000đ", "Đồ uống"),
        new("Bánh mì thịt", "25,000đ", "Đồ ăn"),
    };

    private void AddProduct()
    {
        if (!string.IsNullOrWhiteSpace(_newProductName))
        {
            _products.Add(new(_newProductName, $"{_newProductPrice}đ", _newProductCategory));
            _newProductName = "";
            _newProductPrice = "";
        }
    }

    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"),
    };
}
