@namespace Oqtane.Modules.Admin.Themes
@using System.Net
@inherits ModuleBase
@inject IThemeService ThemeService
@inject NavigationManager NavigationManager

<table class="table table-borderless">
    <tr>
        <td>
            <Label For="name" HelpText="The name of the theme">Name: </Label>
        </td>
        <td>
            <input id="name" class="form-control" @bind="@_name" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="themename" HelpText="The internal name of the module">Internal Name: </Label>
        </td>
        <td>
            <input id="themename" class="form-control" @bind="@_themeName" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="version" HelpText="The version of the thene">Version: </Label>
        </td>
        <td>
            <input id="version" class="form-control" @bind="@_version" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="owner" HelpText="The owner or creator of the theme">Owner: </Label>
        </td>
        <td>
            <input id="owner" class="form-control" @bind="@_owner" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="url" HelpText="The reference url of the theme">Reference Url: </Label>
        </td>
        <td>
            <input id="url" class="form-control" @bind="@_url" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="contact" HelpText="The contact for the theme">Contact: </Label>
        </td>
        <td>
            <input id="contact" class="form-control" @bind="@_contact" disabled />
        </td>
    </tr>
    <tr>
        <td>
            <Label For="license" HelpText="The license of the theme">License: </Label>
        </td>
        <td>
            <textarea id="license" class="form-control" @bind="@_license" rows="5" disabled></textarea>
        </td>
    </tr>
</table>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>

@code {
    private string _themeName = "";
    private string _name;
    private string _version;
    private string _owner = "";
    private string _url = "";
    private string _contact = "";
    private string _license = "";

    public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;

    protected override async Task OnInitializedAsync()
    {
        try
        {
            _themeName = WebUtility.UrlDecode(PageState.QueryString["name"]);
            var themes = await ThemeService.GetThemesAsync();
            var theme = themes.FirstOrDefault(item => item.ThemeName == _themeName);
            if (theme != null)
            {
                _name = theme.Name;
                _version = theme.Version;
                _owner = theme.Owner;
                _url = theme.Url;
                _contact = theme.Contact;
                _license = theme.License;
            }
        }
        catch (Exception ex)
        {
            await logger.LogError(ex, "Error Loading Theme {ThemeName} {Error}", _themeName, ex.Message);
            AddModuleMessage("Error Loading Theme", MessageType.Error);
        }
    }
}
