# Logs + Feedback POC

Standalone proof of concept with two modules: a **Log Viewer** (with a guided tour) and a **Feedback** popup (4-step star-rating survey that opens automatically). All data is mock and lives in memory.

## Use as a package

```bash
npm install @shiva004/surveys
```

```tsx
import { LogsApp, FeedbackApp } from '@shiva004/surveys';
import '@shiva004/surveys/style.css';

export default function Page() {
  return <LogsApp />;      // or <FeedbackApp />
}
```

`LogsApp` accepts `autoStart` (default `true`) to open the tutorial once on first load.
`LogsFeedbackApp` renders both modules behind tabs.

`FeedbackApp` opens its popup automatically on mount (no button). The popup header and footer stay pinned, and the middle scrolls on short screens. Props:

| Prop | Default | Description |
| --- | --- | --- |
| `autoOpen` | `true` | Open the popup when the component mounts |
| `onClose` | – | Called after the popup is closed (X, Cancel, Done, Esc, backdrop) |
| `onSubmit` | – | Called with `{ rating, topics, otherTopic, comment, email, contactOk, submittedAt }` when the person submits |

### Walkthrough tour + analytics

```tsx
import { JourneyProvider, useJourney, WalkthroughDemo } from '@shiva004/surveys';
```

Unchanged from 0.4.0. Needs `react` and `react-dom` 18+.

## Run the demo

```bash
npm install
npm run dev      # http://localhost:5173
npm run build    # production build + type declarations
```

## What changed in 0.5.0

- Removed: Survey and User Journey modules (`SurveyApp`, `JourneyApp`, `SurveyJourneyApp`, NPS helpers, journey analytics, types, `UserJourneyDocs`).
- Added: `LogsApp`, `FeedbackApp`, `LogsFeedbackApp`.

## What changed in 0.6.0

- `FeedbackApp` no longer shows a "Preview Feedback" button; the popup auto-opens. New optional props `autoOpen` and `onClose`.
- Removed dead legacy source (`journey/`, `survey/`, `docs/`, `types.ts`) so `tsc` type-checks cleanly.
- Added `license`, `keywords`, `publishConfig` to `package.json`.

- New fields: "Something else" reveals a required text box, optional email (validated) with a "you can contact me" checkbox, comment counter (500 max). New `onSubmit` prop and `FeedbackResponse` type.
- New look: pinned header/footer so Back/Next are never cut off, 2-column topic chips, glow and focus rings.

## Logger for your own app code

```ts
import { createLogger } from '@shiva004/surveys';

const log = createLogger('login');           // adds a live "login.logger.log" file to the Log Viewer
log.info('Login request received', { email });
log.warn('Password attempt 2 of 3');
log.error('Authentication failed', err);     // Error objects keep their stack trace
```

Every call prints to the browser console and appears live in the Log Viewer with the real time.
`import { logger } from '@shiva004/surveys'` gives a default app-wide logger (source `app`).

## Environment capture (network, IP, local time, storage)

The Log Viewer records the tester's environment automatically, in the same way as `RouteRecorderWatcher`:

- Date/time from the laptop's own clock, with timezone offset (`2026-11-10 14:32:05.123 (UTC+05:30)`)
- Network: online/offline, connection type, speed class, downlink, RTT
- Public IP, ISP and location, plus local (LAN) IP via WebRTC
- Wi-Fi name: browsers cannot read it, so the tester types it once in the Environment panel (remembered, logged)
- localStorage and sessionStorage: a snapshot at start, then every add / update / remove / clear (sensitive keys masked as `***`)

Lines appear live in `network.logger.log` and `storage.logger.log`, and in `console.log`. A collapsible Environment panel shows the current values.

## Logging inside your own functions

```ts
import { createLogger } from '@shiva004/surveys';
const log = createLogger('login');

// 1) Wrap: start / success + duration / failure are logged for you (sync or async)
export const login = log.wrap('login', async (email: string, password: string) => {
  const res = await api.post('/login', { email, password });
  return res.data;
});

// 2) Manual: log only the steps you care about
export async function checkout(cart) {
  log.info('Checkout started', { items: cart.length });
  try {
    const order = await api.post('/orders', cart);
    log.info('Order created', { id: order.id });
    return order;
  } catch (err) {
    log.error('Checkout failed', err);
    throw err;
  }
}
```

Arguments and results are not logged unless you pass `{ logArgs: true }` / `{ logResult: true }`. Never enable them for passwords or tokens.

## Heatmap (mouse, clicks, scroll, time per section)

```tsx
import { HeatmapApp, startHeatmapCapture } from '@shiva004/surveys';

startHeatmapCapture();   // call once at app start, so every page is recorded
<HeatmapApp />           // the report: heatmap, scroll time per page part, most hovered elements
```

Recorded per page (route): where the mouse rests (20px grid, time in ms), where people click, scroll depth,
which tenth of the page is in the middle of the screen the longest, and the elements the mouse hovers longest.
Time only counts while the tab is visible and active (5s idle stops the clock). Typed input values are never recorded.
Data is kept in localStorage (`pulseLogs.heatmap.v1`) and a summary line per page goes to `heatmap.logger.log`.
The viewer shows one tile map of the page (each square coloured by mouse time or clicks, strongest spots numbered 1-3) with Mouse time / Clicks buttons and a Details panel.
