@using Website.Components.Alerts
@using Website.Client.Shared.Components.Products;


<div class="modal fade" id="@nameof(CreateProductModal)" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <EditForm Model="Model" OnValidSubmit="SubmitAsync">
                <div class="modal-header">
                    <h5 class="modal-title">Create new Product</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">

                    <div class="mb-3">
                        <label class="form-label">Name</label>
                        <InputText class="form-control" @bind-Value="Model.Name" />
                        <div class="form-text">Name should be short up to 20 characters</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Description</label>
                        <InputText class="form-control" @bind-Value="Model.Description" />
                        <div class="form-text">This is a short description of your product, for detailed information use tabs</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Category</label>
                        <InputSelect class="form-control" @bind-Value="Model.Category">
                            @foreach (string category in ProductCategoryConstants.Categories)
                            {
                                <option value="@category">@category</option>
                            }
                        </InputSelect>
                        <div class="form-text">Set the category of your product</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Tags</label>
                        <SelectProductTags @bind-Tags="Model.Tags" ProductTags="ProductTags" Width="0" />
                        <div class="form-text">Set the tags of your product</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">GitHub Repo URL</label>
                        <InputText class="form-control" @bind-Value="Model.GithubUrl" />
                        <div class="form-text">Optional</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Price</label>
                        <input type="number" class="form-control" @oninput="OnPriceInput" />
                        <div class="form-text">Price of your product in USD ($)</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Image</label>
                        <InputFile class="form-control" OnChange="@OnInputFileChange" accept="image/png" required />
                        <div class="form-text">Image for your product, has to be .png</div>
                    </div>

                    @if (Model.ImageId != 0)
                    {
                        <img class="mb-3" src="api/images/@Model.ImageId" width="250" height="250" />
                    }

                    <AlertBox ID="products-modal-image" Group="productspage" />

                    <div class="mb-3 form-check">
                        <InputCheckbox @bind-Value="Model.IsLoaderEnabled" class="form-check-input" disabled="@(Model.Price == 0)" id="check-enableloader" />
                        <label class="form-check-label" for="check-enableloader">                             
                            Use Loader
                        </label>
                        <div class="form-text">Determines whether your plugin uses UnturnedStore loader. You can't change it later!</div>
                        @if (Model.Price == 0)
                        {
                            <div class="form-text text-danger">You can enable loader only for paid products!</div>    
                        }
                    </div>

                    <DataAnnotationsValidator />
                    <ValidationSummary />
                </div>

                <div class="mx-2">
                    <AlertBox ID="products-modal-create" Group="productspage" />
                </div>
                

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>

                    @if (isLoading)
                    {
                        <LoadingButton />
                    }
                    else
                    {
                        <button type="submit" class="btn btn-primary">Create</button>
                    }
                </div>
            </EditForm>            
        </div>
    </div>
</div>
