{"version":3,"file":"trust-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/trust-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,MAAM,gCAAgC,CAAC;AAKxC,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;AAE7E,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC7C,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,SAAS,EAAE,cAAc,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB;AAaD,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgC;IAC9D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsC;IACvE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAa;IAE9C,YAAY,OAAO,EAAE,oBAAoB,EAkDxC;IAED,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,UAAU;IAiBlB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAgBjC;CACD","sourcesContent":["import { Container, getKeybindings, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport {\n\tgetProjectTrustOptions,\n\ttype ProjectTrustOption,\n\ttype ProjectTrustStoreEntry,\n} from \"../../../core/trust-manager.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport type TrustSelection = Pick<ProjectTrustOption, \"trusted\" | \"updates\">;\n\nexport interface TrustSelectorOptions {\n\tcwd: string;\n\tsavedDecision: ProjectTrustStoreEntry | null;\n\tprojectTrusted: boolean;\n\tonSelect: (selection: TrustSelection) => void;\n\tonCancel: () => void;\n}\n\nfunction formatDecision(trustPath: string | undefined, decision: ProjectTrustStoreEntry | null): string {\n\tif (decision === null) {\n\t\treturn \"none\";\n\t}\n\tconst label = decision.decision ? \"trusted\" : \"untrusted\";\n\tif (trustPath !== undefined && decision.path !== trustPath) {\n\t\treturn `${label} (inherited from ${decision.path})`;\n\t}\n\treturn `${label} (${decision.path})`;\n}\n\nexport class TrustSelectorComponent extends Container {\n\tprivate selectedIndex: number;\n\tprivate readonly listContainer: Container;\n\tprivate readonly trustOptions: ProjectTrustOption[];\n\tprivate readonly savedDecision: ProjectTrustStoreEntry | null;\n\tprivate readonly onSelectCallback: (selection: TrustSelection) => void;\n\tprivate readonly onCancelCallback: () => void;\n\n\tconstructor(options: TrustSelectorOptions) {\n\t\tsuper();\n\n\t\tthis.savedDecision = options.savedDecision;\n\t\tthis.trustOptions = getProjectTrustOptions(options.cwd);\n\t\tthis.selectedIndex = Math.max(\n\t\t\t0,\n\t\t\tthis.trustOptions.findIndex((option) => this.isSavedOption(option)),\n\t\t);\n\t\tthis.onSelectCallback = options.onSelect;\n\t\tthis.onCancelCallback = options.onCancel;\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(\"Project trust\")), 1, 0));\n\t\tthis.addChild(new Text(theme.fg(\"muted\", options.cwd), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`Saved decision: ${formatDecision(this.trustOptions[0]?.savedPath, options.savedDecision)}`,\n\t\t\t\t),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"muted\", `Current session: ${options.projectTrusted ? \"trusted\" : \"untrusted\"}`), 1, 0),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\"  \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"save\") +\n\t\t\t\t\t\"  \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"cancel\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate isSavedOption(option: ProjectTrustOption): boolean {\n\t\treturn (\n\t\t\toption.savedPath !== undefined &&\n\t\t\tthis.savedDecision?.decision === option.trusted &&\n\t\t\tthis.savedDecision.path === option.savedPath\n\t\t);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tfor (let i = 0; i < this.trustOptions.length; i++) {\n\t\t\tconst option = this.trustOptions[i];\n\t\t\tif (!option) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst isCurrent = this.isSavedOption(option);\n\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \"  \";\n\t\t\tconst label = isSelected ? theme.fg(\"accent\", option.label) : theme.fg(\"text\", option.label);\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${label}${checkmark}`, 1, 0));\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.selectedIndex = Math.min(this.trustOptions.length - 1, this.selectedIndex + 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tconst selected = this.trustOptions[this.selectedIndex];\n\t\t\tif (selected) {\n\t\t\t\tthis.onSelectCallback({ trusted: selected.trusted, updates: selected.updates });\n\t\t\t}\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t}\n}\n"]}