/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/*!***********************************************!*\
  !*** ./js/sign-in-with-google.ts + 1 modules ***!
  \***********************************************/

;// ./js/sign-in-with-google/sign-in-with-google.ts
/**
 * Sign in with Google web tag frontend script.
 *
 * Site Kit by Google, Copyright 2026 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function getCommentTextKey(element) {
  if (!element.form) {
    return 'siwg-comment-text-0';
  }
  const formData = new FormData(element.form);
  const postID = formData.get('comment_post_ID');
  return `siwg-comment-text-${postID}`;
}
function restoreCommentText(element) {
  const key = getCommentTextKey(element);
  const commentText = sessionStorage.getItem(key);
  if (commentText) {
    element.value = commentText;
    sessionStorage.removeItem(key);
  }
}
function saveCommentText(element) {
  const key = getCommentTextKey(element);
  if (element.value) {
    sessionStorage.setItem(key, element.value);
  }
}
async function handleCredentialResponse(response, config) {
  const {
    connectNonce,
    followsPostRedirect,
    isExistingUserFlow,
    isPreview,
    isWooCommerce,
    isWPLogin,
    loginURI,
    redirectTo
  } = config;
  if (isPreview) {
    return;
  }
  const body = new URLSearchParams(); // eslint-disable-line sitekit/acronym-case

  body.append('credential', response.credential);
  body.append('select_by', response.select_by);
  if (isExistingUserFlow) {
    body.append('integration', 'existing_user');
    body.append('connect_nonce', connectNonce);
  } else if (isWooCommerce && !isWPLogin) {
    body.append('integration', 'woocommerce');
  }
  const comment = document.getElementById('comment');
  if (comment) {
    saveCommentText(comment);
  }
  try {
    const res = await fetch(loginURI, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body
    });
    if (!redirectTo && !followsPostRedirect) {
      location.reload();
    } else if (res.ok && res.redirected) {
      location.assign(res.url);
    }
  } catch (error) {
    globalThis.console.error(error);
  }
}
function setupSignInWithGoogle(identityServices, config) {
  const {
    initialize,
    prompt,
    renderButton
  } = identityServices;
  const {
    clientID,
    defaultButtonOptions,
    isExistingUserFlow,
    isPreview,
    isUserLoggedIn,
    isWPLogin,
    redirectTo,
    redirectCookieTTL,
    redirectCookieName,
    redirectCookiePath,
    shouldShowOneTapPrompt
  } = config;
  const idConfig = {
    client_id: clientID,
    callback: response => handleCredentialResponse(response, config),
    library_name: 'Site-Kit'
  };
  initialize(idConfig);
  const login = document.getElementById('login');
  const shouldInsertButton = isWPLogin && login;
  if (shouldInsertButton) {
    const button = document.createElement('div');
    const loginForm = document.getElementById('loginform');
    button.classList.add('googlesitekit-sign-in-with-google__frontend-output-button');
    button.dataset.googlesitekitSiwgWidth = '320';
    login.insertBefore(button, loginForm);
  }
  const shouldRenderButton = !isUserLoggedIn || isWPLogin || isPreview || isExistingUserFlow;
  if (shouldRenderButton) {
    const buttons = document.querySelectorAll('.googlesitekit-sign-in-with-google__frontend-output-button');

    // eslint-disable-next-line sitekit/acronym-case
    buttons.forEach(element => {
      const {
        googlesitekitSiwgShape: shape = defaultButtonOptions.shape,
        googlesitekitSiwgText: text = defaultButtonOptions.text,
        googlesitekitSiwgTheme: theme = defaultButtonOptions.theme,
        googlesitekitSiwgWidth
      } = element.dataset;
      const buttonOptions = {
        shape,
        text,
        theme
      };
      const width = Number(googlesitekitSiwgWidth);
      if (!isNaN(width) && width > 0) {
        buttonOptions.width = width;
        element.style.maxInlineSize = `${width}px`;
      }
      renderButton(element, buttonOptions);
    });
  }
  if (shouldShowOneTapPrompt) {
    prompt();
  }
  if (redirectTo) {
    document.cookie = `${redirectCookieName}=${redirectTo};max-age=${redirectCookieTTL};path=${redirectCookiePath}`;
  }
  const comment = document.getElementById('comment');
  if (comment) {
    restoreCommentText(comment);
  }
}
;// ./js/sign-in-with-google.ts
/**
 * Sign in with Google web tag frontend script.
 *
 * Site Kit by Google, Copyright 2026 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Internal dependencies
 */

try {
  const configJSON = document.currentScript?.dataset.siwgConfig;
  if (!configJSON) {
    throw new Error('Configuration data not found.');
  }
  const identityServices = globalThis.google?.accounts?.id;
  if (!identityServices) {
    throw new Error('Google identity services not found.');
  }
  const config = JSON.parse(configJSON);
  setupSignInWithGoogle(identityServices, config);
} catch (error) {
  globalThis.console.error(error);
}
/******/ })()
;
//# sourceMappingURL=sign-in-with-google.js.map