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

@*
    EN: Onboarding Step 2 — First store setup (name, address, phone, business type).
    VI: Bước 2 thiết lập — Tạo cửa hàng đầu tiên (tên, địa chỉ, SĐT, loại hình).
    Design: pencil-design/src/pages/tPOS/admin/onboarding-store.pen
*@

<PageTitle>Tạo cửa hàng — 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 < 2;
                var isCurrent = step.Index == 2;
                <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;">Tạo cửa hàng đầu tiên</h2>
                <p style="font-size:14px;color:var(--admin-text-tertiary);margin:0;">Thiết lập thông tin cửa hàng và chọn loại hình kinh doanh</p>
            </div>

            @* Store name *@
            <div class="admin-form-group">
                <label class="admin-form-label">Tên cửa hàng <span style="color:var(--admin-danger);">*</span></label>
                <input class="admin-form-input" type="text" placeholder="VD: Coffee House Q1" @bind="_storeName" />
            </div>

            @* Address *@
            <div class="admin-form-group">
                <label class="admin-form-label">Địa chỉ <span style="color:var(--admin-danger);">*</span></label>
                <input class="admin-form-input" type="text" placeholder="123 Nguyễn Huệ, Quận 1, TP.HCM" @bind="_storeAddress" />
            </div>

            @* Phone *@
            <div class="admin-form-group">
                <label class="admin-form-label">Số điện thoại <span style="color:var(--admin-danger);">*</span></label>
                <input class="admin-form-input" type="tel" placeholder="0901 234 567" @bind="_storePhone" />
            </div>

            @* Business type selector *@
            <div class="admin-form-group">
                <label class="admin-form-label">Chọn loại hình kinh doanh <span style="color:var(--admin-danger);">*</span></label>
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;">
                    @foreach (var type in _storeTypes)
                    {
                        var t = type;
                        <button class="admin-type-card @(_selectedType == t.Key ? "admin-type-card--active" : "")" @onclick="@(() => _selectedType = t.Key)">
                            <i data-lucide="@t.Icon" style="width:24px;height:24px;color:@(t.Color);"></i>
                            <span style="font-weight:600;font-size:14px;">@t.Label</span>
                            <span style="font-size:12px;color:var(--admin-text-tertiary);">@t.Desc</span>
                        </button>
                    }
                </div>
            </div>

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

@code {
    private string _storeName = "";
    private string _storeAddress = "";
    private string _storePhone = "";
    private string? _selectedType;

    private record StoreType(string Key, string Label, string Icon, string Color, string Desc);
    private readonly StoreType[] _storeTypes = new[]
    {
        new StoreType("cafe", "Café", "coffee", "#FF5C00", "Quán cà phê, trà sữa"),
        new StoreType("restaurant", "Nhà hàng", "utensils", "#3B82F6", "Nhà hàng, quán ăn"),
        new StoreType("karaoke", "Karaoke", "mic", "#8B5CF6", "Karaoke, giải trí"),
        new StoreType("retail", "Bán lẻ", "shopping-bag", "#22C55E", "Cửa hàng bán lẻ"),
    };

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