<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
    <PropertyGroup>
        <RootNamespace>AliasVault.Client</RootNamespace>
        <TargetFramework>net9.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
        <BuildVersion>$([System.DateTime]::UtcNow.ToString("yyyy-MM-dd HH:mm:ss"))</BuildVersion>
        <WasmBuildNative>true</WasmBuildNative>
        <LangVersion>13</LangVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
        <DocumentationFile>bin\Debug\net9.0\AliasVault.Client.xml</DocumentationFile>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
        <CacheBuster>dev</CacheBuster>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <DebugSymbols>true</DebugSymbols>
        <DocumentationFile>bin\Release\net9.0\AliasVault.Client.xml</DocumentationFile>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
        <Optimize>True</Optimize>
        <CacheBuster>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</CacheBuster>
    </PropertyGroup>

    <UsingTask TaskName="ReplaceText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
        <ParameterGroup>
            <InputFile ParameterType="System.String" Required="true" />
            <OutputFile ParameterType="System.String" Required="true" />
            <CacheBuster ParameterType="System.String" Required="true" />
            <BuildVersion ParameterType="System.String" Required="true" />
        </ParameterGroup>
        <Task>
            <Code Type="Fragment" Language="cs">
                <![CDATA[
        string content = File.ReadAllText(InputFile);
        content = content.Replace("@CacheBuster", CacheBuster).Replace("@BuildVersion", BuildVersion);
        File.WriteAllText(OutputFile, content);
        Log.LogMessage(MessageImportance.High, "Replaced content in " + OutputFile);
]]>
            </Code>
        </Task>
    </UsingTask>

    <Target Name="GenerateCacheBustedIndexHtml" BeforeTargets="Build">
        <ReplaceText InputFile="wwwroot/index.template.html" OutputFile="wwwroot/index.html" CacheBuster="$(CacheBuster)" BuildVersion="$(BuildVersion)" />
    </Target>

    <ItemGroup>
        <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
        <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="9.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
        <PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
        <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="System.Private.Uri" Version="4.3.2" />
    </ItemGroup>

    <ItemGroup>
      <Content Update="wwwroot\appsettings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
      <Content Update="wwwroot\appsettings.Development.json" Condition="Exists('wwwroot\appsettings.Development.json')">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
      <Content Include="..\..\.dockerignore">
        <Link>.dockerignore</Link>
      </Content>
      <AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Databases\AliasClientDb\AliasClientDb.csproj" />
      <ProjectReference Include="..\Generators\AliasVault.Generators.Identity\AliasVault.Generators.Identity.csproj" />
      <ProjectReference Include="..\Generators\AliasVault.Generators.Password\AliasVault.Generators.Password.csproj" />
      <ProjectReference Include="..\Shared\AliasVault.RazorComponents\AliasVault.RazorComponents.csproj" />
      <ProjectReference Include="..\Shared\AliasVault.Shared.Core\AliasVault.Shared.Core.csproj" />
      <ProjectReference Include="..\Shared\AliasVault.Shared\AliasVault.Shared.csproj" />
      <ProjectReference Include="..\Utilities\Cryptography\AliasVault.Cryptography.Client\AliasVault.Cryptography.Client.csproj" />
      <ProjectReference Include="..\Utilities\AliasVault.CsvImportExport\AliasVault.CsvImportExport.csproj" />
      <ProjectReference Include="..\Utilities\AliasVault.FaviconExtractor\AliasVault.FaviconExtractor.csproj" />
      <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
      <ServiceWorker Include="wwwroot\service-worker.published.js">
        <PublishedContent>wwwroot/service-worker.published.js</PublishedContent>
      </ServiceWorker>
    </ItemGroup>
</Project>
