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

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

<PageTitle>Tạo cửa hàng — aPOS Admin</PageTitle>

<div class="admin-content" style="padding:40px;">
    <div class="admin-panel" style="max-width:980px;margin:0 auto;display:flex;flex-direction:column;gap:32px;">

        <section>
            <div style="display:flex;gap:8px;align-items:center;margin-bottom:12px;">
                @for (int i = 1; i <= 6; i++)
                {
                    <div style="width:40px;height:40px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:14px;
                        background-color:@(i == currentStep ? "var(--admin-orange-primary)" : i < currentStep ? "rgba(34,197,94,0.2)" : "var(--admin-bg-interactive)");
                        color:@(i == currentStep ? "#FFF" : i < currentStep ? "#22C55E" : "var(--admin-text-tertiary)");">
                        @(i < currentStep ? "✓" : i)
                    </div>
                    @if (i < 6)
                    {
                        <div style="flex:1;height:2px;background-color:@(i < currentStep ? "#22C55E" : "var(--admin-border-subtle)");"></div>
                    }
                }
            </div>
            <div style="display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:6px;margin-bottom:6px;">
                @for (int i = 1; i <= 6; i++)
                {
                    <span style="text-align:center;font-size:12px;font-weight:@(i == currentStep ? "600" : "500");color:@(i == currentStep ? "var(--admin-orange-primary)" : "var(--admin-text-tertiary)");">
                        @_steps[i - 1].Label
                    </span>
                }
            </div>
            <p style="font-size:12px;color:var(--admin-text-tertiary);margin:0;">Bước 2/6 — Khởi tạo cửa hàng dựa trên thông tin doanh nghiệp hiện tại</p>
        </section>

        <section class="admin-panel" style="padding:32px;display:flex;flex-direction:column;gap:24px;">
            <div style="display:flex;flex-direction:column;gap:6px;">
                <h2 style="font-size:24px;margin:0;font-weight:700;">Tạo cửa hàng đầu tiên</h2>
                <p style="margin:0;font-size:14px;color:var(--admin-text-tertiary);">Phiên bản đầu tiên của cửa hàng sẽ thừa hưởng từ <strong>@_parentBusinessName</strong>.</p>
            </div>

            <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px;">
                <div class="admin-form-group">
                    <label class="admin-form-label">Tên cửa hàng</label>
                    <input class="admin-form-input" type="text" @bind="_storeName" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Địa chỉ</label>
                    <input class="admin-form-input" type="text" @bind="_storeAddress" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Số điện thoại</label>
                    <input class="admin-form-input" type="tel" @bind="_storePhone" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Giờ hoạt động</label>
                    <input class="admin-form-input" type="text" @bind="_storeHours" />
                </div>
            </div>

            <div>
                <label class="admin-form-label">Loại hình cửa hàng</label>
                <div style="display:flex;flex-wrap:wrap;gap:12px;padding-top:8px;">
                    @foreach (var type in _storeTypes)
                    {
                        <button type="button" class="admin-btn-secondary" style="min-width:140px;border:1px solid var(--admin-border-default);display:flex;flex-direction:column;align-items:flex-start;gap:4px;padding:14px;background-color:@(type.Key == _storeType ? "var(--admin-orange-primary)" : "var(--admin-bg-interactive)");
                            color:@(type.Key == _storeType ? "#FFF" : "var(--admin-text-primary)");" @onclick="() => _storeType = type.Key">
                            <span style="font-size:14px;font-weight:600;">@type.Label</span>
                            <span style="font-size:12px;color:@(type.Key == _storeType ? "rgba(255,255,255,0.8)" : "var(--admin-text-tertiary)");">@type.Description</span>
                        </button>
                    }
                </div>
            </div>

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

@code {
    private int currentStep = 2;
    private string _parentBusinessName = "aPOS Bistro";
    private string _storeName = "aPOS Coffee Q1";
    private string _storeAddress = "123 Nguyễn Huệ, Quận 1, TP.HCM";
    private string _storePhone = "0901 234 567";
    private string _storeHours = "08:00 - 22:00";
    private string _storeType = "cafe";

    private record StepInfo(int Index, string Label);
    private readonly StepInfo[] _steps =
    {
        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"),
    };

    private record StoreType(string Key, string Label, string Description);
    private readonly StoreType[] _storeTypes =
    {
        new StoreType("cafe", "Café", "Cà phê, trà sữa"),
        new StoreType("restaurant", "Nhà hàng", "Đồ ăn, buffet"),
        new StoreType("retail", "Kinh doanh", "Bán lẻ, cửa hàng"),
        new StoreType("services", "Dịch vụ", "Spa, salon, gym"),
    };
}
