@inherits ViewModelTemplate<PageViewModel>
@using Dynamicweb.Frontend
@using Dynamicweb.Rendering

@{
    var savedCardId = Dynamicweb.Context.Current?.Request.QueryString.Get("SavedCardId");
    var baseUrl = SearchEngineFriendlyURLs.GetFriendlyUrl($"default.aspx?ID={Pageview.Page.ID}");
}

<div class="modal fade" id="setAsDefaultModal" tabindex="-1" aria-labelledby="SetAsDefault" aria-hidden="true" 
  hx-on::load="bootstrap.Modal.getOrCreateInstance(this).show();"
  x-on:hide-bs-modal.dot="
    const el = document.activeElement;
    if (el && $el.contains(el)) el.blur();
  "
  x-on:hidden-bs-modal.dot="
    bootstrap.Modal.getOrCreateInstance($el).dispose();
    $el.remove();
  ">
  <div class="modal-dialog pt-8">
    <form method="post" class="modal-content"
          hx-post="@(baseUrl)"
          hx-swap="outerHTML"
          hx-target="[data-swift-saved-cards-list]"
          hx-select="[data-swift-saved-cards-list]"
          hx-replace-url="false">
      <input type="hidden" name="SavedCardId" value="@(savedCardId)" />
      <input type="hidden" name="SavedCardCmd" value="CardSetAsDefault" />
      
      <div class="modal-header">
        <h5 class="modal-title">@Translate("Set as default")</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Translate("Cancel")"></button>
      </div>
      <div class="modal-body">
        <p class="mb-0 text-muted lh-sm fs-7">@Translate("Are you sure you want to set this saved card as default?")</p>
      </div>
      <div class="modal-footer border-0">
        <button type="button" class="btn btn-outline-secondary btn-sm" data-dw-button data-bs-dismiss="modal">@Translate("Cancel")</button>
        <button type="submit" class="btn btn-primary btn-sm" data-dw-button data-bs-dismiss="modal">@Translate("Set as default")</button>
      </div>
    </form>
  </div>
</div>

