// @bun
var u=Object.defineProperty;var v=(e)=>e;function w(e,g){this[e]=v.bind(null,g)}var $=(e,g)=>{for(var o in g)u(e,o,{get:g[o],enumerable:!0,configurable:!0,set:w.bind(g,o)})};var F=(e,g)=>()=>(e&&(g=e(e=0)),g);import{CodeBlock as m,InstallCommand as y}from"@contractspec/lib.design-system";import{HStack as z,VStack as f}from"@contractspec/lib.design-system/layout";import{Code as r,H1 as B,H2 as h,P as l,Text as p}from"@contractspec/lib.design-system/typography";import q from"@contractspec/lib.ui-link";import{ChevronRight as J}from"lucide-react";import{jsx as b,jsxs as d}from"react/jsx-runtime";var Q=`import { DataViewRenderer } from '@contractspec/lib.design-system';
import { resolveDataViewPreferences } from '@contractspec/lib.personalization/data-view-preferences';

const resolved = resolveDataViewPreferences({
  spec: AccountsDataView,
  preferences: profile.canonical,
  insights,
  record: savedAccountViewPreference,
});

return (
  <DataViewRenderer
    spec={AccountsDataView}
    items={accounts}
    defaultViewMode={resolved.viewMode}
    defaultDensity={resolved.density}
    defaultDataDepth={resolved.dataDepth}
    pagination={{
      page,
      pageSize: resolved.pageSize ?? 25,
      total,
    }}
  />
);`,U=`tracker.trackDataViewInteraction({
  dataViewKey: AccountsDataView.meta.key,
  dataViewVersion: AccountsDataView.meta.version,
  action: 'view_mode_changed',
  viewMode: 'grid',
});

tracker.trackDataViewInteraction({
  dataViewKey: AccountsDataView.meta.key,
  action: 'data_depth_changed',
  dataDepth: 'detailed',
});

tracker.trackDataViewInteraction({
  dataViewKey: AccountsDataView.meta.key,
  action: 'filter_changed',
  filterKey: 'status',
});`,Y=`Add DataView personalization for <screen>.

Acceptance criteria:
- Resolve viewMode, density, dataDepth, and pageSize with resolveDataViewPreferences.
- Apply resolved values to DataViewRenderer as default or controlled props.
- Track opened, view_mode_changed, density_changed, data_depth_changed, search_changed, filter_changed, sort_changed, and page_changed actions with trackDataViewInteraction.
- Persist only the dimensions allowed by view.collection.personalization.persist.
- Ignore behavior-derived modes that are not allowed by view.collection.viewModes.allowedModes.
- Do not import React or design-system code into @contractspec/lib.personalization helpers.`;function i(){return d(f,{className:"space-y-8",children:[d(f,{className:"space-y-4",children:[b(B,{className:"font-bold text-4xl",children:"@contractspec/lib.personalization"}),b(l,{className:"text-lg text-muted-foreground",children:"Track field/feature/workflow usage, analyze drop-offs, and convert insights into OverlaySpecs or workflow tweaks."})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"Installation"}),b(y,{package:"@contractspec/lib.personalization"})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"Tracker"}),b(l,{className:"text-muted-foreground",children:"Buffer events per tenant/user and emit OpenTelemetry counters automatically."}),b(m,{language:"typescript",code:`import { createBehaviorTracker } from '@contractspec/lib.personalization';

const tracker = createBehaviorTracker({
  store,
  context: { tenantId: ctx.tenant.id, userId: ctx.identity.id },
});

tracker.trackFieldAccess({ operation: 'billing.createOrder', field: 'items' });
tracker.trackWorkflowStep({ workflow: 'invoice', step: 'review', status: 'entered' });`})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"DataView Preferences"}),d(l,{className:"text-muted-foreground",children:["Use ",b(r,{children:"resolveDataViewPreferences"})," when a collection DataView should honor a user's preferred list/grid/table mode, compact or comfortable density, data depth, and page size. The helper returns plain values that can be passed into the renderer without coupling the design-system package to personalization. Start from the"," ",b(q,{href:"/docs/libraries/data-views",className:"text-[color:var(--rust)] underline underline-offset-4",children:b(p,{children:"DataViews runtime guide"})})," ","when you need the contract and renderer shape."]}),b(m,{language:"tsx",code:Q})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"DataView Interaction Events"}),d(l,{className:"text-muted-foreground",children:["Track ",b(r,{children:"data_view_interaction"})," events for view mode, density, data depth, search, filters, sorting, and pagination. The in-memory store summarizes those events, and the analyzer can derive a scoped preferred collection mode from valid interaction counts."]}),b(m,{language:"typescript",code:U})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"Analyzer"}),b(l,{className:"text-muted-foreground",children:"Summarize events and highlight unused UI, frequent fields, and workflow bottlenecks."}),b(m,{language:"typescript",code:`import { BehaviorAnalyzer } from '@contractspec/lib.personalization/analyzer';

const analyzer = new BehaviorAnalyzer(store);
const insights = await analyzer.analyze({ tenantId: 'acme', userId: 'ops-42' });
// {
//   unusedFields: ['internalNotes'],
//   workflowBottlenecks: [...],
//   dataViewPreferences: {
//     'crm.accounts': { preferredViewMode: 'grid' }
//   }
// }`})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"Adapter"}),b(l,{className:"text-muted-foreground",children:"Convert insights into overlays or workflow extension hints."}),b(m,{language:"typescript",code:`import { insightsToOverlaySuggestion } from '@contractspec/lib.personalization/adapter';

const overlay = insightsToOverlaySuggestion(insights, {
  overlayId: 'acme-order-form',
  tenantId: 'acme',
  capability: 'billing.createOrder',
});`})]}),d(f,{className:"space-y-4",children:[b(h,{className:"font-bold text-2xl",children:"Agent Prompt"}),b(l,{className:"text-muted-foreground",children:"Use this when asking an agent to wire DataView preferences while preserving the personalization/design-system boundary."}),b(m,{language:"markdown",code:Y})]}),d(z,{className:"items-center gap-4 pt-4",children:[b(q,{href:"/docs/libraries",className:"btn-ghost",children:b(p,{children:"Back to Libraries"})}),d(q,{href:"/docs/libraries/overlay-engine",className:"btn-primary",children:[b(p,{children:"Next: Overlay Engine"})," ",b(J,{size:16})]})]})]})}export{i as LibrariesPersonalizationPage};
