<Project Sdk="Microsoft.NET.Sdk.Razor">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>disable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Set RadzenLocalProject=true to reference the local Radzen.Blazor source even in Release.
         Keeps the whole graph on one Radzen.Blazor (project, not package), avoiding duplicate
         _content/Radzen.Blazor static web assets when the demos publish trimmed against local source. -->
    <UseRadzenPackage Condition="'$(RadzenLocalProject)' != 'true' AND '$(Configuration)' == 'Release'">true</UseRadzenPackage>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Radzen.Blazor" Version="*" GeneratePathProperty="true" Condition="'$(UseRadzenPackage)' == 'true'" />
    <ProjectReference Include="..\Radzen.Blazor\Radzen.Blazor.csproj" Condition="'$(UseRadzenPackage)' != 'true'" />
  </ItemGroup>

  <PropertyGroup>
    <GeneratorProject>$(MSBuildThisFileDirectory)..\Radzen.Blazor.Api.Generator\Radzen.Blazor.Api.Generator.csproj</GeneratorProject>
    <GeneratedPagesDir>$(MSBuildThisFileDirectory)Generated\Pages</GeneratedPagesDir>
  </PropertyGroup>

  <!-- Release reflects over the published package (what the site ships); Debug (or RadzenLocalProject) over the source build. -->
  <PropertyGroup Condition="'$(UseRadzenPackage)' == 'true'">
    <RadzenBlazorDll>$(PkgRadzen_Blazor)/lib/net10.0/Radzen.Blazor.dll</RadzenBlazorDll>
    <RadzenBlazorXml>$(PkgRadzen_Blazor)/lib/net10.0/Radzen.Blazor.xml</RadzenBlazorXml>
  </PropertyGroup>
  <PropertyGroup Condition="'$(UseRadzenPackage)' != 'true'">
    <RadzenBlazorDll>$(MSBuildThisFileDirectory)..\Radzen.Blazor\bin\$(Configuration)\net10.0\Radzen.Blazor.dll</RadzenBlazorDll>
    <RadzenBlazorXml>$(MSBuildThisFileDirectory)..\Radzen.Blazor\bin\$(Configuration)\net10.0\Radzen.Blazor.xml</RadzenBlazorXml>
  </PropertyGroup>

  <!-- Usage: dotnet build -p:GenerateApiPages=true -->
  <Target Name="GenerateApiPages" BeforeTargets="ResolveProjectStaticWebAssets;AssignTargetPaths"
          Inputs="$(RadzenBlazorDll)"
          Outputs="$(GeneratedPagesDir)\ApiIndex.razor"
          Condition="Exists('$(RadzenBlazorDll)') AND ('$(Configuration)' == 'Release' OR '$(GenerateApiPages)' == 'true')">
    <Message Text="Generating API reference pages..." Importance="high" />
    <MakeDir Directories="$(GeneratedPagesDir)" />
    <Exec Command="dotnet run --project &quot;$(GeneratorProject)&quot; -- &quot;$(RadzenBlazorDll)&quot; &quot;$(RadzenBlazorXml)&quot; &quot;$(GeneratedPagesDir)&quot;"
          ContinueOnError="false" />
    <Message Text="API reference pages generated in $(GeneratedPagesDir)" Importance="high" />
  </Target>
</Project>
