<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
    <AssemblyName>DiplomovaPrace.Web.Customer</AssemblyName>
    <RootNamespace>DiplomovaPrace.Web.Customer</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.5" />
    <PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.5.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <!-- Don't publish the SPA source files, but do show them in the project files list -->
    <Content Remove="$(SpaRoot)**" />
    <Content Remove="ClientApp\src\components\User\components\common\**" />
    <None Remove="$(SpaRoot)**" />
    <None Remove="ClientApp\src\components\User\components\common\**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
  </ItemGroup>

  <ItemGroup>
    <Compile Remove="ClientApp\src\components\User\components\common\**" />
    <EmbeddedResource Remove="ClientApp\src\components\User\components\common\**" />
    <TypeScriptCompile Remove="ClientApp\src\components\User\components\common\**" />
  </ItemGroup>

  <ItemGroup>
    <None Remove="ClientApp\history.ts" />
    <None Remove="ClientApp\src\apiClient\routes.ts" />
    <None Remove="ClientApp\src\apiModels\ViewModels.ts" />
    <None Remove="ClientApp\src\App.tsx" />
    <None Remove="ClientApp\src\components\common\ConfirmationModal.tsx" />
    <None Remove="ClientApp\src\components\common\MyCarousel.tsx" />
    <None Remove="ClientApp\src\components\common\pager.tsx" />
    <None Remove="ClientApp\src\components\common\WarningModal.tsx" />
    <None Remove="ClientApp\src\components\layout\Footer.tsx" />
    <None Remove="ClientApp\src\components\layout\Header.tsx" />
    <None Remove="ClientApp\src\components\layout\humberger.tsx" />
    <None Remove="ClientApp\src\components\layout\SideBar.tsx" />
    <None Remove="ClientApp\src\components\UserLayout.tsx" />
    <None Remove="ClientApp\src\components\User\components\AboutUs.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\AccountHeader.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\AccountInfo.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\AddressFormModal.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\AddressManagement.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\ChangePasswordForm.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\OrderDetail.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\OrderList.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\Orders\OrderDetailAddresses.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\Orders\OrderDetailHeader.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\Orders\OrderListHeader.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\Orders\OrderListItem.tsx" />
    <None Remove="ClientApp\src\components\User\components\Account\Orders\OrderListTable.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout\CreateAccountForm.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout\DeliveryAddressForm.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout\DeliveryAndPaymentTypeForm.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout\InvoicingAddressForm.tsx" />
    <None Remove="ClientApp\src\components\User\components\Checkout\OrderSummary.tsx" />
    <None Remove="ClientApp\src\components\User\components\Contacts.tsx" />
    <None Remove="ClientApp\src\components\User\components\Delivery.tsx" />
    <None Remove="ClientApp\src\components\User\components\OrderCompleted.tsx" />
    <None Remove="ClientApp\src\components\User\components\ProductDetail.tsx" />
    <None Remove="ClientApp\src\components\User\components\ProductList.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\AddToCartIcon.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\ProductCategoryDropdown.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\ProductCategoryDropdownItem.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\ProductDetailFooter.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\ProductListHeader.tsx" />
    <None Remove="ClientApp\src\components\User\components\products\ProductListItem.tsx" />
    <None Remove="ClientApp\src\components\User\components\Security\Login.tsx" />
    <None Remove="ClientApp\src\components\User\components\Security\PasswordRecovery.tsx" />
    <None Remove="ClientApp\src\components\User\components\Security\PasswordReset.tsx" />
    <None Remove="ClientApp\src\components\User\components\Security\Signup.tsx" />
    <None Remove="ClientApp\src\components\User\components\ShoppingCart.tsx" />
    <None Remove="ClientApp\src\components\User\components\ShoppingCart\ShoppingCartList.tsx" />
    <None Remove="ClientApp\src\components\User\components\ShoppingCart\ShoppingCartListItem.tsx" />
    <None Remove="ClientApp\src\components\User\components\TradeTerms.tsx" />
    <None Remove="ClientApp\src\routes\userRoutes.tsx" />
    <None Remove="ClientApp\src\services\httpService.ts" />
    <None Remove="ClientApp\src\services\localStorageService.ts" />
  </ItemGroup>

  <ItemGroup>
    <TypeScriptCompile Remove="ClientApp\src\index.tsx" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Facades.Customer\Facades.Customer.csproj" />
    <ProjectReference Include="..\Services\Services.csproj" />
  </ItemGroup>

  <ItemGroup>
    <TypeScriptCompile Include="ClientApp\src\history.ts" />
    <TypeScriptCompile Include="ClientApp\src\routes\userRoutes.tsx" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="ClientApp\public\img\" />
    <Folder Include="ClientApp\public\img-temp\" />
    <Folder Include="ClientApp\public\js\" />
  </ItemGroup>

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
  </Target>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)build\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

</Project>
