@model LittleShop.DTOs.UpdateProductDto

@{
    ViewData["Title"] = "Edit Product";
    var categories = ViewData["Categories"] as IEnumerable<LittleShop.DTOs.CategoryDto>;
    var productId = ViewData["ProductId"];
}

<div class="row mb-4">
    <div class="col">
        <h1><i class="fas fa-edit"></i> Edit Product</h1>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-body">
                <form method="post" action="@Url.Action("Edit", new { id = productId })">
                    @Html.AntiForgeryToken()
                    @if (ViewData.ModelState[""] != null && ViewData.ModelState[""].Errors.Count > 0)
                    {
                        <div class="alert alert-danger" role="alert">
                            @foreach (var error in ViewData.ModelState[""].Errors)
                            {
                                <div>@error.ErrorMessage</div>
                            }
                        </div>
                    }
                    
                    <div class="mb-3">
                        <label for="Name" class="form-label">Product Name</label>
                        <input name="Name" id="Name" value="@Model?.Name" class="form-control" required />
                    </div>
                    
                    <div class="mb-3">
                        <label for="Description" class="form-label">Description</label>
                        <textarea name="Description" id="Description" class="form-control" rows="4" required>@Model?.Description</textarea>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="Price" class="form-label">Price (£)</label>
                                <input name="Price" id="Price" value="@Model?.Price" type="number" step="0.01" class="form-control" required />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="CategoryId" class="form-label">Category</label>
                                <select name="CategoryId" id="CategoryId" class="form-select" required>
                                    <option value="">Select a category</option>
                                    @if (categories != null)
                                    {
                                        @foreach (var category in categories)
                                        {
                                            <option value="@category.Id" selected="@(Model?.CategoryId == category.Id)">@category.Name</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="Weight" class="form-label">Weight/Volume</label>
                                <input name="Weight" id="Weight" value="@Model?.Weight" type="number" step="0.01" class="form-control" required />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="WeightUnit" class="form-label">Unit</label>
                                <select name="WeightUnit" id="WeightUnit" class="form-select">
                                    <option value="0" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Unit)">Unit</option>
                                    <option value="1" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Micrograms)">Micrograms</option>
                                    <option value="2" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Grams)">Grams</option>
                                    <option value="3" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Ounces)">Ounces</option>
                                    <option value="4" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Pounds)">Pounds</option>
                                    <option value="5" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Millilitres)">Millilitres</option>
                                    <option value="6" selected="@(Model?.WeightUnit == LittleShop.Enums.ProductWeightUnit.Litres)">Litres</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input name="IsActive" type="checkbox" class="form-check-input" checked="@(Model?.IsActive == true)" value="true" />
                            <input name="IsActive" type="hidden" value="false" />
                            <label for="IsActive" class="form-check-label">Active</label>
                        </div>
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="@Url.Action("Index")" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> Back to Products
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> Save Changes
                        </button>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- Photo Upload Section -->
        <div class="card mt-4">
            <div class="card-header">
                <h5><i class="fas fa-camera"></i> Product Photos</h5>
            </div>
            <div class="card-body">
                <form method="post" action="@Url.Action("UploadPhoto", new { id = productId })" enctype="multipart/form-data">
                    @Html.AntiForgeryToken()
                    <div class="row">
                        <div class="col-md-8">
                            <div class="mb-3">
                                <label for="file" class="form-label">Choose Photo</label>
                                <input name="file" id="file" type="file" class="form-control" accept="image/*" required />
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="mb-3">
                                <label for="altText" class="form-label">Alt Text</label>
                                <input name="altText" id="altText" class="form-control" placeholder="Image description" />
                            </div>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-upload"></i> Upload Photo
                    </button>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5><i class="fas fa-info-circle"></i> Product Information</h5>
            </div>
            <div class="card-body">
                <ul class="list-unstyled">
                    <li><strong>Name:</strong> Product identifier</li>
                    <li><strong>Description:</strong> Supports Unicode and emojis</li>
                    <li><strong>Price:</strong> Base price in GBP</li>
                    <li><strong>Weight/Volume:</strong> For shipping calculations</li>
                    <li><strong>Category:</strong> Product organization</li>
                    <li><strong>Status:</strong> Active products appear in catalog</li>
                </ul>
            </div>
        </div>
    </div>
</div>