(globalThis["__googlesitekit_webpackJsonp"] = globalThis["__googlesitekit_webpackJsonp"] || []).push([["googlesitekit-vendor-lazy-pdf"],{

/***/ "./js/components/PDFExport/components/PDFMetricTile.tsx"
/*!**************************************************************!*\
  !*** ./js/components/PDFExport/components/PDFMetricTile.tsx ***!
  \**************************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @react-pdf/renderer */ "../node_modules/@react-pdf/renderer/lib/react-pdf.browser.js");
/* provided dependency */ var React = __webpack_require__(/*! @wordpress/element */ "../node_modules/@wordpress/element/build-module/index.js");
/**
 * PDFMetricTile component for @react-pdf/renderer.
 *
 * 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.
 */

/**
 * External dependencies
 */

const COLORS = {
  text: '#212121',
  secondary: '#646464',
  success: '#34a853',
  error: '#ea4335',
  cardBg: '#f8f9fa'
};
const tileStyles = _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.StyleSheet.create({
  container: {
    backgroundColor: COLORS.cardBg,
    borderRadius: 4,
    padding: 12
  },
  title: {
    fontSize: 9,
    color: COLORS.secondary,
    marginBottom: 4
  },
  value: {
    fontSize: 28,
    fontWeight: 'bold',
    color: COLORS.text
  },
  changeLabel: {
    fontSize: 9,
    color: COLORS.secondary,
    marginTop: 4
  },
  changeRow: {
    flexDirection: 'row',
    alignItems: 'center',
    marginTop: 4,
    gap: 3
  },
  changeText: {
    fontSize: 9
  }
});
function ChangeArrow({
  direction,
  color
}) {
  return /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Svg, {
    width: 8,
    height: 8,
    viewBox: "0 0 8 8"
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Path, {
    d: direction === 'up' ? 'M4,0 L8,8 L0,8 Z' : 'M0,0 L8,0 L4,8 Z',
    fill: color
  }));
}
const PDFMetricTile = ({
  title,
  value,
  change,
  changeDirection,
  changeLabel
}) => {
  const changeColor = changeDirection === 'up' ? COLORS.success : COLORS.error;
  return /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.View, {
    style: tileStyles.container
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: tileStyles.title
  }, title), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: tileStyles.value
  }, value), changeLabel && /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: tileStyles.changeLabel
  }, changeLabel), change !== undefined && change !== null && changeDirection && /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.View, {
    style: tileStyles.changeRow
  }, /*#__PURE__*/React.createElement(ChangeArrow, {
    direction: changeDirection,
    color: changeColor
  }), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: [tileStyles.changeText, {
      color: changeColor
    }]
  }, change)));
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PDFMetricTile);

/***/ },

/***/ "./js/components/pdf-export/PDFExportOrchestrator.tsx"
/*!************************************************************!*\
  !*** ./js/components/pdf-export/PDFExportOrchestrator.tsx ***!
  \************************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @react-pdf/renderer */ "../node_modules/@react-pdf/renderer/lib/react-pdf.browser.js");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "../node_modules/react/index.js");
/* harmony import */ var googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! googlesitekit-data */ "googlesitekit-data");
/* harmony import */ var googlesitekit_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _js_googlesitekit_datastore_pdf_constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @/js/googlesitekit/datastore/pdf/constants */ "./js/googlesitekit/datastore/pdf/constants.ts");
/* harmony import */ var _js_googlesitekit_datastore_site_constants__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @/js/googlesitekit/datastore/site/constants */ "./js/googlesitekit/datastore/site/constants.js");
/* harmony import */ var _js_googlesitekit_datastore_user_constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @/js/googlesitekit/datastore/user/constants */ "./js/googlesitekit/datastore/user/constants.js");
/* harmony import */ var _components_DashboardReport__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./components/DashboardReport */ "./js/components/pdf-export/components/DashboardReport.tsx");
/* harmony import */ var _pdf_utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./pdf-utils */ "./js/components/pdf-export/pdf-utils.ts");
/* provided dependency */ var React = __webpack_require__(/*! @wordpress/element */ "../node_modules/@wordpress/element/build-module/index.js");
/**
 * PDF export orchestrator: drives the MVP export pipeline.
 *
 * 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.
 */

/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */


/**
 * Internal dependencies
 */






const STAGE_IDLE = 'IDLE';
const STAGE_LOADING = 'LOADING';
const STAGE_BUILDING = 'BUILDING';
const STAGE_COMPLETE = 'COMPLETE';
const STAGE_ERROR = 'ERROR';
const VALID_TRANSITIONS = {
  [STAGE_IDLE]: [STAGE_LOADING],
  [STAGE_LOADING]: [STAGE_BUILDING, STAGE_ERROR, STAGE_IDLE],
  [STAGE_BUILDING]: [STAGE_COMPLETE, STAGE_ERROR, STAGE_IDLE],
  [STAGE_COMPLETE]: [],
  [STAGE_ERROR]: []
};
const LOADING_TIMEOUT_MS = 45 * 1000;
const BUILDING_TIMEOUT_MS = 15 * 1000;
const COMPLETE_UNMOUNT_DELAY_MS = 2 * 1000;
const BLOB_REVOKE_DELAY_MS = 30 * 1000;
// TODO: Replace with real data-loading progress in #12631.
const LOADING_MOCK_PROGRESS = 35;
const initialState = {
  stage: STAGE_IDLE
};

/**
 * Validates and applies stage transitions for the export state machine.
 *
 * @since n.e.x.t
 *
 * @param state  Current reducer state.
 * @param action Dispatched action with a `nextStage` payload.
 * @return Next state, unchanged when the transition is invalid.
 */
function reducer(state, action) {
  if (action.type === 'TRANSITION') {
    const allowed = VALID_TRANSITIONS[state.stage];
    if (!allowed.includes(action.nextStage)) {
      return state;
    }
    return {
      stage: action.nextStage
    };
  }
  return state;
}

/**
 * Determines whether the given error is an `AbortError` DOMException.
 *
 * @since n.e.x.t
 *
 * @param error The caught value.
 * @return `true` when the error is an AbortError.
 */
function isAbortError(error) {
  return error instanceof DOMException && error.name === 'AbortError';
}

/**
 * Returns a promise that resolves on the next animation frame, or rejects
 * if the signal is aborted before the frame fires.
 *
 * @since n.e.x.t
 *
 * @param signal Abort signal to observe.
 * @return Resolves on the next frame, rejects on abort.
 */
function nextFrame(signal) {
  return new Promise((resolve, reject) => {
    if (signal.aborted) {
      reject(new DOMException('Aborted', 'AbortError'));
      return;
    }
    function onAbort() {
      globalThis.cancelAnimationFrame(frameID);
      reject(new DOMException('Aborted', 'AbortError'));
    }
    const frameID = globalThis.requestAnimationFrame(() => {
      signal.removeEventListener('abort', onAbort);
      resolve();
    });
    signal.addEventListener('abort', onAbort, {
      once: true
    });
  });
}
const PDFExportOrchestrator = ({
  onComplete
}) => {
  const [, dispatch] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useReducer)(reducer, initialState);
  const {
    setStatus,
    setProgress,
    setBlob,
    clearExport,
    clearCancelRequest
  } = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useDispatch)(_js_googlesitekit_datastore_pdf_constants__WEBPACK_IMPORTED_MODULE_3__.CORE_PDF);
  const cancelRequested = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => select(_js_googlesitekit_datastore_pdf_constants__WEBPACK_IMPORTED_MODULE_3__.CORE_PDF).isCancelRequested(), []);
  const siteName = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => select(_js_googlesitekit_datastore_site_constants__WEBPACK_IMPORTED_MODULE_4__.CORE_SITE).getSiteName(), []);
  const referenceSiteURL = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => select(_js_googlesitekit_datastore_site_constants__WEBPACK_IMPORTED_MODULE_4__.CORE_SITE).getReferenceSiteURL(), []);
  const dateRange = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => select(_js_googlesitekit_datastore_user_constants__WEBPACK_IMPORTED_MODULE_5__.CORE_USER).getDateRange(), []);
  const userName = (0,googlesitekit_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => select(_js_googlesitekit_datastore_user_constants__WEBPACK_IMPORTED_MODULE_5__.CORE_USER).getName(), []);
  const abortControllerRef = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useRef)(null);
  const stageTimeoutRef = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useRef)(null);
  const completeTimeoutRef = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useRef)(null);
  const timeoutAbortRef = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useRef)(false);
  const onCompleteRef = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useRef)(onComplete);
  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
    onCompleteRef.current = onComplete;
  }, [onComplete]);
  const clearStageTimeout = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useCallback)(() => {
    if (stageTimeoutRef.current !== null) {
      clearTimeout(stageTimeoutRef.current);
      stageTimeoutRef.current = null;
    }
  }, []);
  const armStageTimeout = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useCallback)(durationMS => {
    clearStageTimeout();
    stageTimeoutRef.current = setTimeout(() => {
      stageTimeoutRef.current = null;
      timeoutAbortRef.current = true;
      abortControllerRef.current?.abort();
    }, durationMS);
  }, [clearStageTimeout]);
  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
    if (cancelRequested) {
      abortControllerRef.current?.abort();
      clearCancelRequest();
    }
  }, [cancelRequested, clearCancelRequest]);
  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
    const controller = new AbortController();
    abortControllerRef.current = controller;
    const {
      signal
    } = controller;
    function beforeUnloadHandler(event) {
      event.preventDefault();
      // Most browsers ignore the string, but assigning it keeps the legacy contract.
      event.returnValue = '';
    }
    globalThis.addEventListener('beforeunload', beforeUnloadHandler);
    const referenceName = typeof siteName === 'string' && siteName.length > 0 ? siteName : referenceSiteURL || '';
    async function run() {
      try {
        dispatch({
          type: 'TRANSITION',
          nextStage: STAGE_LOADING
        });
        setStatus('progress');
        setProgress(0);
        armStageTimeout(LOADING_TIMEOUT_MS);
        await nextFrame(signal);
        setProgress(LOADING_MOCK_PROGRESS);
        if (signal.aborted) {
          throw new DOMException('Aborted', 'AbortError');
        }
        dispatch({
          type: 'TRANSITION',
          nextStage: STAGE_BUILDING
        });
        armStageTimeout(BUILDING_TIMEOUT_MS);

        // Footer timestamp uses the real generation time, not the dashboard date range.
        // eslint-disable-next-line sitekit/no-direct-date
        const generatedAt = new Date().toLocaleString();
        const filename = (0,_pdf_utils__WEBPACK_IMPORTED_MODULE_7__.getPDFFilename)(referenceName, typeof dateRange === 'string' ? dateRange : undefined);
        const document = /*#__PURE__*/React.createElement(_components_DashboardReport__WEBPACK_IMPORTED_MODULE_6__["default"], {
          siteName: referenceName,
          dateRange: typeof dateRange === 'string' ? dateRange : undefined,
          userName: typeof userName === 'string' ? userName : undefined,
          generatedAt: generatedAt
        });
        const blob = await (0,_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.pdf)(document).toBlob();
        if (signal.aborted) {
          throw new DOMException('Aborted', 'AbortError');
        }
        const blobURL = URL.createObjectURL(blob);
        setBlob({
          url: blobURL,
          filename
        });
        (0,_pdf_utils__WEBPACK_IMPORTED_MODULE_7__.triggerDownload)(blobURL, filename);
        setTimeout(() => {
          URL.revokeObjectURL(blobURL);
        }, BLOB_REVOKE_DELAY_MS);
        clearStageTimeout();
        dispatch({
          type: 'TRANSITION',
          nextStage: STAGE_COMPLETE
        });
        setStatus('success');
        completeTimeoutRef.current = setTimeout(() => {
          completeTimeoutRef.current = null;
          onCompleteRef.current();
        }, COMPLETE_UNMOUNT_DELAY_MS);
      } catch (error) {
        clearStageTimeout();

        // User cancel is silent (IDLE). Timeout abort routes to ERROR
        // so the snackbar shows the failure.
        if (isAbortError(error) && !timeoutAbortRef.current) {
          dispatch({
            type: 'TRANSITION',
            nextStage: STAGE_IDLE
          });
          clearExport();
          onCompleteRef.current();
          return;
        }

        // Stop any request that is still running, so it ends now
        // instead of finishing in the background after the user sees
        // the error. On the stage-timeout path, `abort()` already ran,
        // so this call does nothing.
        abortControllerRef.current?.abort();
        dispatch({
          type: 'TRANSITION',
          nextStage: STAGE_ERROR
        });
        setStatus('error');
        onCompleteRef.current();
      }
    }
    run();
    return () => {
      globalThis.removeEventListener('beforeunload', beforeUnloadHandler);
      clearStageTimeout();
      if (completeTimeoutRef.current !== null) {
        clearTimeout(completeTimeoutRef.current);
        completeTimeoutRef.current = null;
      }
      controller.abort();
    };
    // Runs once on mount. Site and user data are read at start, not re-fetched mid-export.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  return null;
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PDFExportOrchestrator);

/***/ },

/***/ "./js/components/pdf-export/components/DashboardReport.tsx"
/*!*****************************************************************!*\
  !*** ./js/components/pdf-export/components/DashboardReport.tsx ***!
  \*****************************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @react-pdf/renderer */ "../node_modules/@react-pdf/renderer/lib/react-pdf.browser.js");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
/* provided dependency */ var React = __webpack_require__(/*! @wordpress/element */ "../node_modules/@wordpress/element/build-module/index.js");
/**
 * DashboardReport: minimal `react-pdf` Document used by the MVP export.
 *
 * 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.
 */

/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

const DEFAULT_PAGE_HEIGHT = 792;
const styles = _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.StyleSheet.create({
  page: {
    paddingTop: 48,
    paddingBottom: 48,
    paddingHorizontal: 48,
    fontSize: 12
  },
  header: {
    marginBottom: 32
  },
  headerSiteName: {
    fontSize: 20,
    fontWeight: 700,
    marginBottom: 4
  },
  headerDateRange: {
    fontSize: 11,
    color: '#5f6368'
  },
  body: {
    flexGrow: 1
  },
  bodyHeading: {
    fontSize: 16,
    marginBottom: 8
  },
  bodyText: {
    lineHeight: 1.5
  },
  footer: {
    borderTopWidth: 1,
    borderTopColor: '#dadce0',
    paddingTop: 12,
    fontSize: 9,
    color: '#5f6368'
  }
});
const DashboardReport = ({
  siteName,
  dateRange,
  userName,
  generatedAt,
  pageHeight = DEFAULT_PAGE_HEIGHT
}) => {
  const footerLine = userName ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.sprintf)(/* translators: 1: Date and time string. 2: User name. */
  (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Generated %1$s by %2$s', 'google-site-kit'), generatedAt, userName) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.sprintf)(/* translators: %s: Date and time string. */
  (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Generated %s', 'google-site-kit'), generatedAt);
  return /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Document, {
    title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Site Kit Dashboard Report', 'google-site-kit'),
    author: "Site Kit by Google"
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Page, {
    size: [612, pageHeight],
    style: styles.page,
    wrap: false
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: styles.headerSiteName
  }, siteName), dateRange ? /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: styles.headerDateRange
  }, dateRange) : null), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.View, {
    style: styles.body
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: styles.bodyHeading
  }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Site Kit Dashboard Report', 'google-site-kit')), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, {
    style: styles.bodyText
  }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('This is an MVP placeholder for the upcoming Site Kit PDF report. The full layout, charts, and metrics land in follow-up tickets.', 'google-site-kit'))), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.View, {
    style: styles.footer
  }, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_0__.Text, null, footerLine))));
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (DashboardReport);

/***/ },

/***/ "./js/components/pdf-export/pdf-utils.ts"
/*!***********************************************!*\
  !*** ./js/components/pdf-export/pdf-utils.ts ***!
  \***********************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   getPDFFilename: () => (/* binding */ getPDFFilename),
/* harmony export */   triggerDownload: () => (/* binding */ triggerDownload)
/* harmony export */ });
/**
 * PDF export utilities.
 *
 * 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.
 */

/**
 * Sanitizes a free-form string into a lowercase, hyphen-separated slug
 * suitable for use inside a filename.
 *
 * @since n.e.x.t
 *
 * @param value Input string. Empty and non-string values become an empty slug.
 * @return The sanitized slug.
 */
function slugify(value) {
  if (typeof value !== 'string' || value.length === 0) {
    return '';
  }
  const withoutScheme = value.replace(/^[a-z][a-z0-9+\-.]*:\/\//i, '');
  return withoutScheme.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
}

/**
 * Returns the current date as `YYYY-MM-DD` using the local timezone.
 *
 * @since n.e.x.t
 *
 * @param [now] Optional date instance, defaults to `new Date()`.
 * @return The formatted date.
 */
function getISODate(
// The filename's date stamp is the actual generation moment, not the
// dashboard's analytics reference date.
// eslint-disable-next-line sitekit/no-direct-date
now = new Date()) {
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}

/**
 * Builds a sanitized PDF filename for the dashboard export.
 *
 * The result is `site-kit-<site>-<dateRange>-<date>.pdf` when a date range
 * is supplied, or `site-kit-<site>-<date>.pdf` otherwise. The site and date
 * range are passed through `slugify` so the filename is filesystem-safe on
 * every supported OS.
 *
 * @since n.e.x.t
 *
 * @param siteName    Site name or URL.
 * @param [dateRange] Optional date range slug, e.g. `last-28-days`.
 * @param [now]       Optional date instance, defaults to `new Date()`.
 * @return The composed filename.
 */
function getPDFFilename(siteName, dateRange,
// The filename's date stamp is the actual generation moment, not the
// dashboard's analytics reference date.
// eslint-disable-next-line sitekit/no-direct-date
now = new Date()) {
  const siteSlug = slugify(siteName) || 'report';
  const rangeSlug = slugify(dateRange);
  const date = getISODate(now);
  const segments = ['site-kit', siteSlug];
  if (rangeSlug) {
    segments.push(rangeSlug);
  }
  segments.push(date);
  return `${segments.join('-')}.pdf`;
}

/**
 * Triggers a browser download for the given blob URL by creating a temporary
 * anchor element with the `download` attribute, clicking it programmatically,
 * and removing it from the DOM.
 *
 * @since n.e.x.t
 *
 * @param  url      Blob URL pointing to the generated file.
 * @param  filename Suggested filename for the downloaded file.
 * @return {void}
 */
function triggerDownload(url, filename) {
  const link = globalThis.document.createElement('a');
  link.href = url;
  link.download = filename;
  link.rel = 'noopener';
  link.style.display = 'none';
  globalThis.document.body.appendChild(link);
  link.click();
  globalThis.document.body.removeChild(link);
}

/***/ },

/***/ "./js/googlesitekit/datastore/pdf/constants.ts"
/*!*****************************************************!*\
  !*** ./js/googlesitekit/datastore/pdf/constants.ts ***!
  \*****************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   CORE_PDF: () => (/* binding */ CORE_PDF)
/* harmony export */ });
/**
 * 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.
 */

const CORE_PDF = 'core/pdf';

/***/ },

/***/ "./js/modules/analytics-4/components/dashboard/DashboardAllTrafficWidgetGA4/indexPDF.tsx"
/*!***********************************************************************************************!*\
  !*** ./js/modules/analytics-4/components/dashboard/DashboardAllTrafficWidgetGA4/indexPDF.tsx ***!
  \***********************************************************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ DashboardAllTrafficWidgetGA4PDF)
/* harmony export */ });
/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "../node_modules/@babel/runtime/helpers/esm/extends.js");
/* harmony import */ var _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @react-pdf/renderer */ "../node_modules/@react-pdf/renderer/lib/react-pdf.browser.js");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _js_components_PDFExport_components_PDFMetricTile__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @/js/components/PDFExport/components/PDFMetricTile */ "./js/components/PDFExport/components/PDFMetricTile.tsx");
/* harmony import */ var _js_util__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @/js/util */ "./js/util/index.js");
/* provided dependency */ var React = __webpack_require__(/*! @wordpress/element */ "../node_modules/@wordpress/element/build-module/index.js");

/**
 * DashboardAllTrafficWidgetGA4 PDF component for @react-pdf/renderer.
 *
 * 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.
 */

/**
 * External dependencies
 */


/**
 * WordPress dependencies
 */


/**
 * Internal dependencies
 */


const styles = _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__.StyleSheet.create({
  chartPlaceholder: {
    width: '100%',
    height: 200,
    backgroundColor: '#f5f5f5',
    marginTop: 12
  },
  noData: {
    fontSize: 9,
    color: '#646464'
  }
});
function DashboardAllTrafficWidgetGA4PDF({
  data
}) {
  if (!data) {
    return /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__.View, null, /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__.Text, {
      style: styles.noData
    }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('No data available.', 'google-site-kit')));
  }
  const {
    totalsReport,
    graphReport
  } = data;
  const [current, previous] = totalsReport?.totals || [];
  const currentValue = Number(current?.metricValues?.[0]?.value);
  const previousValue = Number(previous?.metricValues?.[0]?.value);
  const change = (0,_js_util__WEBPACK_IMPORTED_MODULE_4__.calculateChange)(previousValue, currentValue);
  const changeData = typeof change === 'number' ? {
    change: (0,_js_util__WEBPACK_IMPORTED_MODULE_4__.numFmt)(Math.abs(change), {
      style: 'percent',
      maximumFractionDigits: 1
    }),
    changeDirection: change >= 0 ? 'up' : 'down'
  } : undefined;
  const graphRowCount = graphReport?.rows?.length || 0;
  const comparisonLabel = graphRowCount > 0 ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.sprintf)(/* translators: %d: number of days */
  (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('compared to the previous %d days', 'google-site-kit'), graphRowCount) : undefined;
  const formattedValue = (0,_js_util__WEBPACK_IMPORTED_MODULE_4__.numFmt)(currentValue || 0);
  return /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__.View, null, /*#__PURE__*/React.createElement(_js_components_PDFExport_components_PDFMetricTile__WEBPACK_IMPORTED_MODULE_3__["default"], (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({
    title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('All Visitors', 'google-site-kit'),
    value: formattedValue,
    changeLabel: comparisonLabel
  }, changeData || {})), /*#__PURE__*/React.createElement(_react_pdf_renderer__WEBPACK_IMPORTED_MODULE_1__.View, {
    style: styles.chartPlaceholder
  }));
}

/***/ },

/***/ "?69d4"
/*!************************!*\
  !*** buffer (ignored) ***!
  \************************/
() {

/* (ignored) */

/***/ },

/***/ "?1709"
/*!************************!*\
  !*** crypto (ignored) ***!
  \************************/
() {

/* (ignored) */

/***/ }

}]);
//# sourceMappingURL=googlesitekit-vendor-lazy-pdf.js.map