import React, { FC, useMemo, useRef, useState } from "react";
import { PopupWindow, ScreenProps } from "../PopupWindow";
import { useAtom } from "jotai/index";
import { __, CouponsPlus } from "../globals";
import { NewTreeActions } from "./NewTreeActions";
import { MultiSelect } from "./fields/MultiSelect";
import { BuyXGetYSpecificProductConfigFields } from "./BuyXGetYSpecificProductConfigFields";
import { merge } from "lodash";
import { BuyXGetYNotInCartNotificationWindowStateAtom, PrivacyPolicyWindowStateAtom } from "./atoms";
import { BuyXGetYNotInCartNotificationConfigFields } from "./BuyXGetYNotInCartNotificationConfigFields";
import { NotInCartNotification } from "./cards/BuyXGetY";
import { getPopupStackDimensionCalculators } from "./ulitilies";
import { useOpenPopupsCount } from "./hooks";


export const PrivacyPolicyPopupWindow: FC<{}> = ({ }) => {
    const [windowContext, setWindowContext] = useAtom(PrivacyPolicyWindowStateAtom)
    const popupsCount = useOpenPopupsCount()
    const stackDimensions = getPopupStackDimensionCalculators(popupsCount)
    const apiDomain = CouponsPlus.domains.api

    let isOpen = !!windowContext;

    return <PopupWindow id="privacy-policy"
        isOpen={isOpen}
        onClose={() => setWindowContext(false)}
        zIndex={1000000 + 10}
        screens={useMemo<ScreenProps[]>(() => [
            {
                id: 1,
                title: '',
                content: () => <div className="h-full max-w-100 overflow-scroll pb-10 space-y-4 text-gray-700">
                    <h1 className="text-5x text-gray-700 font-medium">Coupons+ Services Privacy Policy</h1>
                    <div className="coupons-plus-privacy-policy text-justify grid grid-cols-1 gap-3">
                        <p className="text-gray-600 italic text-smaller-1">Note: due to the legal nature of this document, it is provided only in English.</p>
                        <p>
                            <strong>Coupons+</strong> is committed to preserving website security, operational performance,
                            and user privacy. This section outlines the minimal, non-personally identifiable technical data
                            exchanged when utilizing our dynamic preset library features.
                        </p>

                        <h3 className="text-2x font-medium text-gray-800">1. External API Communications</h3>
                        <p>
                            When you browse or import pre-configured coupon presets within
                            <strong> Coupons+</strong>, the plugin establishes a secure connection with our remote repository endpoint at{' '}
                            <code>{apiDomain}</code> to fetch available assets.
                        </p>

                        <h3 className="text-2x font-medium text-gray-800">2. Data Transmitted &amp; Technical Metadata</h3>
                        <p>
                            To authenticate API requests, enforce service availability, prevent abuse, and deliver the correct preset assets,
                            the following non-sensitive, anonymous telemetry is transmitted to our endpoints:
                        </p>
                        <ul>
                            <li>
                                <strong>Requesting Origin:</strong> The website URL requesting the preset library. Uses may include origin verification and abuse prevention enforcement.
                            </li>
                            <li>
                                <strong>Anonymized Cryptographic Request Tokens:</strong> A salted, one-way
                                cryptographic hash generated from transient local session state identifiers and target object
                                referencing IDs.
                            </li>
                        </ul>

                        <h3 className="text-2x font-medium text-gray-800">3. Privacy Guarantees &amp; Non-Irreversibility</h3>
                        <p>
                            <strong>No Personally Identifiable Information (PII) is ever collected, stored, or transmitted.</strong>{' '}
                            The anonymous, non-personal cryptographic verification payload is strictly one-way and mathematical in nature—it is impossible
                            to reverse, link to internal store database entries, or trace to any individual site administrator, customer,
                            or user of this service.
                        </p>

                        <h3 className="text-2x font-semibold text-gray-800">4. Service Availability &amp; Access</h3>
                        <p>
                            Access to the hosted preset repository and remote API endpoints is provided as a complimentary convenience feature. We reserve the exclusive right to throttle, suspend, restrict, or permanently terminate service access to any requesting origin at any time, with or without cause or prior notice, at our sole discretion.
                        </p>

                        <h3 className="text-2x font-medium text-gray-800">5. Data Usage &amp; Retention</h3>
                        <p>
                            Some transmitted technical meta-data may or may not be retained in server logs and operational storage. This data is utilized for purposes including service diagnostics, security auditing, rate limiting, and infrastructure optimization. No persistent user tracking cookies or personal profile databases are created.
                        </p>
                    </div>
                </div>,
                primaryBottom() {
                    return {
                        label: __('Done'),
                        onClick() {
                            setWindowContext(false)
                        },
                    }
                },
            }
        ], [windowContext])}
        screenId={1}
        defaultScreenId={1}
        setCurrentScreenId={() => { }}
        customTop={stackDimensions.top}
        customWidth={stackDimensions.width}
    />
}
