@page "/admin/finance/tax"
@layout AdminLayout
@inherits AdminBase

@*
    EN: Tax Configuration — tax rate settings, categories, exemptions, report preview.
    VI: Cấu hình thuế — cài đặt thuế suất, danh mục, miễn thuế, xem trước báo cáo.
    Design: pencil-design/src/pages/tPOS/admin/tax-configuration.pen
*@

<PageTitle>Cấu hình thuế — GoodGo Admin</PageTitle>

@* ═══ TOP BAR ═══ *@
<div class="admin-topbar">
    <div class="admin-topbar__left">
        <h1 class="admin-topbar__title">Cấu hình thuế</h1>
        <p class="admin-topbar__subtitle">Quản lý thuế suất & danh mục thuế</p>
    </div>
    <div class="admin-topbar__right">
        <button class="admin-btn-secondary">
            <i data-lucide="file-text"></i>
            <span>Xem báo cáo thuế</span>
        </button>
        <button class="admin-btn-primary">
            <i data-lucide="save"></i>
            <span>Lưu cấu hình</span>
        </button>
    </div>
</div>

@* ═══ CONTENT ═══ *@
<div class="admin-content" style="display:flex;flex-direction:column;gap:24px;">

    @* Tax Rate Settings + Tax Categories *@
    <div style="display:flex;gap:24px;">

        @* LEFT: Tax Rate Settings *@
        <div class="admin-panel" style="flex:1;">
            <div class="admin-panel__header">
                <h3 class="admin-panel__title">
                    <i data-lucide="settings" style="color:var(--admin-orange-primary);"></i>
                    Cài đặt thuế suất
                </h3>
            </div>
            <div class="admin-panel__body" style="display:flex;flex-direction:column;gap:16px;">
                <div class="admin-form-group">
                    <label class="admin-form-label">Thuế VAT (%)</label>
                    <input type="text" class="admin-form-input" value="10" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Phí dịch vụ (%)</label>
                    <input type="text" class="admin-form-input" value="5" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Thuế TNCN (%)</label>
                    <input type="text" class="admin-form-input" value="10" />
                </div>
                <div class="admin-form-group">
                    <label class="admin-form-label">Thuế môi trường</label>
                    <input type="text" class="admin-form-input" value="0" />
                </div>
            </div>
        </div>

        @* RIGHT: Tax Categories *@
        <div class="admin-panel" style="flex:1;">
            <div class="admin-panel__header">
                <h3 class="admin-panel__title">
                    <i data-lucide="tags" style="color:#3B82F6;"></i>
                    Danh mục thuế
                </h3>
                <button class="admin-panel__action">+ Thêm danh mục</button>
            </div>
            <div class="admin-panel__body" style="display:flex;flex-direction:column;gap:10px;">
                @foreach (var cat in _taxCategories)
                {
                    <div style="display:flex;align-items:center;justify-content:space-between;padding:12px 14px;background-color:var(--admin-bg-interactive);border-radius:var(--admin-radius-md);">
                        <div style="display:flex;align-items:center;gap:10px;">
                            <i data-lucide="@cat.Icon" style="width:16px;height:16px;color:@cat.Color;"></i>
                            <div>
                                <div style="font-size:13px;font-weight:600;">@cat.Name</div>
                                <div style="font-size:11px;color:var(--admin-text-tertiary);">@cat.Desc</div>
                            </div>
                        </div>
                        <div style="font-size:14px;font-weight:700;color:var(--admin-orange-primary);">@cat.Rate</div>
                    </div>
                }
            </div>
        </div>
    </div>

    @* Tax-exempt Products + Tax Report Preview *@
    <div style="display:flex;gap:24px;">

        @* LEFT: Tax-exempt Products *@
        <div class="admin-panel" style="flex:1;">
            <div class="admin-panel__header">
                <h3 class="admin-panel__title">
                    <i data-lucide="shield-off" style="color:#F59E0B;"></i>
                    Sản phẩm miễn thuế
                </h3>
                <button class="admin-panel__action">+ Thêm SP</button>
            </div>
            <div class="admin-panel__body" style="padding:0;">
                <table class="admin-table">
                    <thead>
                        <tr>
                            <th>Sản phẩm</th>
                            <th>Danh mục</th>
                            <th>Lý do</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in _exemptProducts)
                        {
                            <tr>
                                <td style="font-weight:600;">@item.Name</td>
                                <td style="color:var(--admin-text-tertiary);">@item.Category</td>
                                <td style="font-size:12px;">@item.Reason</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>

        @* RIGHT: Tax Report Preview *@
        <div class="admin-panel" style="flex:1;">
            <div class="admin-panel__header">
                <h3 class="admin-panel__title">
                    <i data-lucide="file-bar-chart" style="color:#22C55E;"></i>
                    Xem trước báo cáo thuế
                </h3>
            </div>
            <div class="admin-panel__body" style="display:flex;flex-direction:column;gap:12px;">
                @foreach (var line in _taxPreview)
                {
                    <div style="display:flex;justify-content:space-between;padding:10px 14px;background-color:var(--admin-bg-interactive);border-radius:var(--admin-radius-md);">
                        <span style="font-size:13px;color:var(--admin-text-secondary);">@line.Label</span>
                        <span style="font-size:13px;font-weight:@(line.IsBold ? "700" : "500");color:@(line.IsBold ? "var(--admin-orange-primary)" : "var(--admin-text-primary)");">@line.Value</span>
                    </div>
                }
            </div>
        </div>
    </div>
</div>

@code {
    private record TaxCategory(string Name, string Desc, string Rate, string Icon, string Color);
    private readonly TaxCategory[] _taxCategories = new[]
    {
        new TaxCategory("VAT", "Thuế giá trị gia tăng", "10%", "receipt", "#FF5C00"),
        new TaxCategory("Phí dịch vụ", "Áp dụng cho dine-in", "5%", "utensils", "#3B82F6"),
        new TaxCategory("TNCN", "Thuế thu nhập cá nhân", "10%", "user", "#8B5CF6"),
        new TaxCategory("Đồ uống có cồn", "Thuế tiêu thụ đặc biệt", "35%", "wine", "#EF4444"),
    };

    private record ExemptProduct(string Name, string Category, string Reason);
    private readonly ExemptProduct[] _exemptProducts = new[]
    {
        new ExemptProduct("Nước lọc", "Đồ uống", "Miễn VAT theo QĐ"),
        new ExemptProduct("Cơm trắng", "Đồ ăn", "Lương thực thiết yếu"),
        new ExemptProduct("Trà đá", "Đồ uống", "Đồ uống cơ bản"),
    };

    private record TaxPreviewLine(string Label, string Value, bool IsBold);
    private readonly TaxPreviewLine[] _taxPreview = new[]
    {
        new TaxPreviewLine("Doanh thu trước thuế", "256.8M", false),
        new TaxPreviewLine("VAT (10%)", "25.7M", false),
        new TaxPreviewLine("Phí dịch vụ (5%)", "8.4M", false),
        new TaxPreviewLine("Thuế TTĐB", "2.1M", false),
        new TaxPreviewLine("Tổng thuế phải nộp", "36.2M", true),
        new TaxPreviewLine("Doanh thu sau thuế", "220.6M", true),
    };
}
