Nessuna descrizione

CVMakerPageView.swift 60KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. //
  2. // CVMakerPageView.swift
  3. // App for Indeed
  4. //
  5. // Template gallery for the CV Maker sidebar destination: page header, category
  6. // toggle, style chips, thumbnail grid, and a sticky bottom CTA. Follows the
  7. // active dashboard light / dark appearance via `AppDashboardTheme`.
  8. //
  9. import Cocoa
  10. import QuartzCore
  11. // MARK: - Data model
  12. enum CVCategoryGroup: Hashable {
  13. case designBased
  14. case professionBased
  15. var title: String {
  16. switch self {
  17. case .designBased: return "Design-Based"
  18. case .professionBased: return "Profession-Based"
  19. }
  20. }
  21. }
  22. enum CVDesignFamily: String, CaseIterable, Hashable {
  23. case professional, modern, creative, minimal, executive
  24. var title: String {
  25. switch self {
  26. case .professional: return "Professional"
  27. case .modern: return "Modern"
  28. case .creative: return "Creative"
  29. case .minimal: return "Minimal"
  30. case .executive: return "Executive"
  31. }
  32. }
  33. }
  34. /// High-level layout bucket for catalog metadata and filtering.
  35. enum CVTemplateLayoutType: String, Hashable {
  36. case atsSingleColumn
  37. case twoColumnSidebarLeading
  38. case twoColumnSidebarTrailing
  39. var gallerySubtitle: String {
  40. switch self {
  41. case .atsSingleColumn: return "ATS layout"
  42. case .twoColumnSidebarLeading: return "Sidebar left"
  43. case .twoColumnSidebarTrailing: return "Sidebar right"
  44. }
  45. }
  46. }
  47. /// Visual recipe used by the mini preview renderer so every template can vary
  48. /// the headline style, accent line, and sidebar layout without bespoke views.
  49. struct CVTemplate: Hashable {
  50. enum Headline: Hashable {
  51. /// Big name centered above the body.
  52. case centered
  53. /// Name aligned to the leading edge, role beneath it.
  54. case leftAligned
  55. /// Name on the leading edge with circular initials avatar on the trailing edge.
  56. case leftWithInitials
  57. /// Initials avatar above a centered name (single column).
  58. case avatarStacked
  59. }
  60. enum Accent: Hashable {
  61. case none
  62. case redUnderline
  63. case redBar
  64. case blueBar
  65. }
  66. enum SidebarSide: Hashable { case leading, trailing }
  67. enum Layout: Hashable {
  68. case singleColumn
  69. case twoColumn(sidebar: SidebarSide, tinted: Bool)
  70. }
  71. enum SectionLabelStyle: Hashable {
  72. case uppercase
  73. case slashed // "// EXPERIENCE"
  74. case bracketed // "[ EXPERIENCE ]"
  75. }
  76. let id: String
  77. let name: String
  78. let family: CVDesignFamily
  79. let headline: Headline
  80. let accent: Accent
  81. let layout: Layout
  82. let sectionLabelStyle: SectionLabelStyle
  83. /// sRGB accent used for headers, tags, and sidebar tints in the mini preview.
  84. let themeRed: CGFloat
  85. let themeGreen: CGFloat
  86. let themeBlue: CGFloat
  87. /// Shown on cards; mirrors the design family in this build.
  88. var category: String { family.title }
  89. var layoutType: CVTemplateLayoutType {
  90. switch layout {
  91. case .singleColumn: return .atsSingleColumn
  92. case .twoColumn(sidebar: .leading, _): return .twoColumnSidebarLeading
  93. case .twoColumn(sidebar: .trailing, _): return .twoColumnSidebarTrailing
  94. }
  95. }
  96. /// Top-level gallery tab: expressive layouts for design-led roles vs. conservative ATS-friendly styles.
  97. var galleryGroup: CVCategoryGroup {
  98. switch family {
  99. case .modern, .creative: return .designBased
  100. case .minimal, .professional, .executive: return .professionBased
  101. }
  102. }
  103. var themeColor: NSColor {
  104. NSColor(srgbRed: themeRed, green: themeGreen, blue: themeBlue, alpha: 1)
  105. }
  106. /// Optional bundle image name; `nil` means render a live vector/text preview.
  107. var previewImageAssetName: String? { nil }
  108. init(
  109. id: String,
  110. name: String,
  111. family: CVDesignFamily,
  112. headline: Headline,
  113. accent: Accent,
  114. layout: Layout,
  115. sectionLabelStyle: SectionLabelStyle,
  116. themeRed: CGFloat? = nil,
  117. themeGreen: CGFloat? = nil,
  118. themeBlue: CGFloat? = nil
  119. ) {
  120. self.id = id
  121. self.name = name
  122. self.family = family
  123. self.headline = headline
  124. self.accent = accent
  125. self.layout = layout
  126. self.sectionLabelStyle = sectionLabelStyle
  127. if let tr = themeRed, let tg = themeGreen, let tb = themeBlue {
  128. self.themeRed = tr
  129. self.themeGreen = tg
  130. self.themeBlue = tb
  131. } else {
  132. let rgb = Self.resolvedThemeRGB(family: family, id: id)
  133. self.themeRed = rgb.0
  134. self.themeGreen = rgb.1
  135. self.themeBlue = rgb.2
  136. }
  137. }
  138. private static func resolvedThemeRGB(family: CVDesignFamily, id: String) -> (CGFloat, CGFloat, CGFloat) {
  139. var hash: UInt64 = 1469598103934665603
  140. for b in id.utf8 {
  141. hash ^= UInt64(b)
  142. hash &*= 1_099_511_628_211
  143. }
  144. let t = Double(hash % 1000) / 1000.0
  145. switch family {
  146. case .professional:
  147. let r = 0.12 + t * 0.06
  148. let g = 0.32 + t * 0.08
  149. let b = 0.58 + t * 0.12
  150. return (r, g, b)
  151. case .modern:
  152. let r = 0.0 + t * 0.08
  153. let g = 0.45 + t * 0.12
  154. let bl = 0.85 + t * 0.1
  155. return (min(r, 1), min(g, 1), min(bl, 1))
  156. case .minimal:
  157. return (0.45 + t * 0.05, 0.48 + t * 0.04, 0.55 + t * 0.06)
  158. case .executive:
  159. let r = 0.08 + t * 0.06
  160. let g = 0.12 + t * 0.05
  161. let b = 0.22 + t * 0.08
  162. return (r, g, b)
  163. case .creative:
  164. let r = 0.25 + t * 0.2
  165. let g = 0.35 + t * 0.15
  166. let b = 0.72 + t * 0.15
  167. return (min(r, 1), min(g, 1), min(b, 1))
  168. }
  169. }
  170. }
  171. extension CVTemplate {
  172. /// Same 0…11 silhouette index as `CVTemplatePreviewView` so the filled résumé matches the gallery thumbnail for that template.
  173. var galleryLayoutVariant: Int {
  174. var h: UInt64 = 1469598103934665603
  175. let layoutDesc: String
  176. switch layout {
  177. case .singleColumn: layoutDesc = "1col"
  178. case .twoColumn(let s, let t): layoutDesc = "2col_\(s)_\(t)"
  179. }
  180. let blob = "\(id)|\(family.rawValue)|\(headline)|\(accent)|\(layoutDesc)|\(sectionLabelStyle)"
  181. for b in blob.utf8 {
  182. h ^= UInt64(b)
  183. h &*= 1_099_511_628_211
  184. }
  185. return Int(h % 12)
  186. }
  187. }
  188. // MARK: - Catalog
  189. enum CVTemplateCatalog {
  190. static let all: [CVTemplate] = [
  191. // Minimal family (matches the reference screenshot)
  192. CVTemplate(
  193. id: "paper-white",
  194. name: "Paper White",
  195. family: .minimal,
  196. headline: .centered,
  197. accent: .none,
  198. layout: .singleColumn,
  199. sectionLabelStyle: .uppercase
  200. ),
  201. CVTemplate(
  202. id: "swiss",
  203. name: "Swiss",
  204. family: .minimal,
  205. headline: .centered,
  206. accent: .redUnderline,
  207. layout: .twoColumn(sidebar: .leading, tinted: false),
  208. sectionLabelStyle: .uppercase
  209. ),
  210. CVTemplate(
  211. id: "mono",
  212. name: "Mono",
  213. family: .minimal,
  214. headline: .leftAligned,
  215. accent: .redUnderline,
  216. layout: .singleColumn,
  217. sectionLabelStyle: .slashed
  218. ),
  219. CVTemplate(
  220. id: "airy",
  221. name: "Airy",
  222. family: .minimal,
  223. headline: .leftWithInitials,
  224. accent: .none,
  225. layout: .twoColumn(sidebar: .trailing, tinted: false),
  226. sectionLabelStyle: .uppercase
  227. ),
  228. CVTemplate(
  229. id: "tabular",
  230. name: "Tabular",
  231. family: .minimal,
  232. headline: .leftAligned,
  233. accent: .none,
  234. layout: .singleColumn,
  235. sectionLabelStyle: .bracketed
  236. ),
  237. CVTemplate(
  238. id: "facet",
  239. name: "Facet",
  240. family: .minimal,
  241. headline: .avatarStacked,
  242. accent: .none,
  243. layout: .twoColumn(sidebar: .leading, tinted: true),
  244. sectionLabelStyle: .uppercase
  245. ),
  246. // Professional family
  247. CVTemplate(
  248. id: "corporate",
  249. name: "Corporate",
  250. family: .professional,
  251. headline: .leftAligned,
  252. accent: .blueBar,
  253. layout: .singleColumn,
  254. sectionLabelStyle: .uppercase
  255. ),
  256. CVTemplate(
  257. id: "atlas",
  258. name: "Atlas",
  259. family: .professional,
  260. headline: .centered,
  261. accent: .blueBar,
  262. layout: .twoColumn(sidebar: .leading, tinted: true),
  263. sectionLabelStyle: .uppercase
  264. ),
  265. CVTemplate(
  266. id: "ledger",
  267. name: "Ledger",
  268. family: .professional,
  269. headline: .leftAligned,
  270. accent: .blueBar,
  271. layout: .twoColumn(sidebar: .trailing, tinted: false),
  272. sectionLabelStyle: .uppercase
  273. ),
  274. CVTemplate(
  275. id: "harbor",
  276. name: "Harbor",
  277. family: .professional,
  278. headline: .leftWithInitials,
  279. accent: .none,
  280. layout: .twoColumn(sidebar: .leading, tinted: true),
  281. sectionLabelStyle: .uppercase
  282. ),
  283. CVTemplate(
  284. id: "metro",
  285. name: "Clear Path",
  286. family: .professional,
  287. headline: .centered,
  288. accent: .blueBar,
  289. layout: .singleColumn,
  290. sectionLabelStyle: .uppercase
  291. ),
  292. CVTemplate(
  293. id: "pinstripe",
  294. name: "Pinstripe",
  295. family: .professional,
  296. headline: .leftAligned,
  297. accent: .blueBar,
  298. layout: .twoColumn(sidebar: .leading, tinted: false),
  299. sectionLabelStyle: .uppercase
  300. ),
  301. CVTemplate(
  302. id: "briefing",
  303. name: "Briefing",
  304. family: .professional,
  305. headline: .leftAligned,
  306. accent: .blueBar,
  307. layout: .twoColumn(sidebar: .leading, tinted: true),
  308. sectionLabelStyle: .uppercase
  309. ),
  310. CVTemplate(
  311. id: "quorum",
  312. name: "Quorum",
  313. family: .professional,
  314. headline: .leftWithInitials,
  315. accent: .none,
  316. layout: .singleColumn,
  317. sectionLabelStyle: .bracketed
  318. ),
  319. CVTemplate(
  320. id: "docket",
  321. name: "Docket",
  322. family: .professional,
  323. headline: .centered,
  324. accent: .blueBar,
  325. layout: .twoColumn(sidebar: .trailing, tinted: false),
  326. sectionLabelStyle: .uppercase
  327. ),
  328. CVTemplate(
  329. id: "conduit",
  330. name: "Conduit",
  331. family: .professional,
  332. headline: .leftAligned,
  333. accent: .blueBar,
  334. layout: .singleColumn,
  335. sectionLabelStyle: .slashed
  336. ),
  337. CVTemplate(
  338. id: "principal",
  339. name: "Principal",
  340. family: .professional,
  341. headline: .leftWithInitials,
  342. accent: .blueBar,
  343. layout: .twoColumn(sidebar: .trailing, tinted: true),
  344. sectionLabelStyle: .uppercase
  345. ),
  346. CVTemplate(
  347. id: "charter",
  348. name: "Charter",
  349. family: .professional,
  350. headline: .leftAligned,
  351. accent: .none,
  352. layout: .twoColumn(sidebar: .leading, tinted: false),
  353. sectionLabelStyle: .uppercase
  354. ),
  355. // Modern family
  356. CVTemplate(
  357. id: "vertex",
  358. name: "Vertex",
  359. family: .modern,
  360. headline: .leftWithInitials,
  361. accent: .blueBar,
  362. layout: .twoColumn(sidebar: .leading, tinted: true),
  363. sectionLabelStyle: .slashed
  364. ),
  365. CVTemplate(
  366. id: "linea",
  367. name: "Linea",
  368. family: .modern,
  369. headline: .leftAligned,
  370. accent: .blueBar,
  371. layout: .singleColumn,
  372. sectionLabelStyle: .slashed
  373. ),
  374. CVTemplate(
  375. id: "prism",
  376. name: "Prism",
  377. family: .modern,
  378. headline: .avatarStacked,
  379. accent: .blueBar,
  380. layout: .twoColumn(sidebar: .trailing, tinted: true),
  381. sectionLabelStyle: .uppercase
  382. ),
  383. CVTemplate(
  384. id: "circuit",
  385. name: "Circuit",
  386. family: .modern,
  387. headline: .leftAligned,
  388. accent: .blueBar,
  389. layout: .twoColumn(sidebar: .trailing, tinted: false),
  390. sectionLabelStyle: .slashed
  391. ),
  392. CVTemplate(
  393. id: "north",
  394. name: "North",
  395. family: .modern,
  396. headline: .leftWithInitials,
  397. accent: .none,
  398. layout: .twoColumn(sidebar: .leading, tinted: false),
  399. sectionLabelStyle: .uppercase
  400. ),
  401. CVTemplate(
  402. id: "axis",
  403. name: "Axis",
  404. family: .modern,
  405. headline: .centered,
  406. accent: .blueBar,
  407. layout: .singleColumn,
  408. sectionLabelStyle: .bracketed
  409. ),
  410. // Creative family
  411. CVTemplate(
  412. id: "marigold",
  413. name: "Marigold",
  414. family: .creative,
  415. headline: .avatarStacked,
  416. accent: .redBar,
  417. layout: .twoColumn(sidebar: .leading, tinted: true),
  418. sectionLabelStyle: .slashed
  419. ),
  420. CVTemplate(
  421. id: "ember",
  422. name: "Ember",
  423. family: .creative,
  424. headline: .leftWithInitials,
  425. accent: .redBar,
  426. layout: .twoColumn(sidebar: .trailing, tinted: true),
  427. sectionLabelStyle: .slashed
  428. ),
  429. CVTemplate(
  430. id: "lattice",
  431. name: "Lattice",
  432. family: .creative,
  433. headline: .leftAligned,
  434. accent: .redUnderline,
  435. layout: .singleColumn,
  436. sectionLabelStyle: .bracketed
  437. ),
  438. CVTemplate(
  439. id: "bloom",
  440. name: "Bloom",
  441. family: .creative,
  442. headline: .avatarStacked,
  443. accent: .redBar,
  444. layout: .singleColumn,
  445. sectionLabelStyle: .slashed
  446. ),
  447. CVTemplate(
  448. id: "studio",
  449. name: "Studio",
  450. family: .creative,
  451. headline: .leftWithInitials,
  452. accent: .redUnderline,
  453. layout: .twoColumn(sidebar: .leading, tinted: true),
  454. sectionLabelStyle: .uppercase
  455. ),
  456. CVTemplate(
  457. id: "kite",
  458. name: "Kite",
  459. family: .creative,
  460. headline: .centered,
  461. accent: .redBar,
  462. layout: .twoColumn(sidebar: .trailing, tinted: false),
  463. sectionLabelStyle: .slashed
  464. ),
  465. // Executive family
  466. CVTemplate(
  467. id: "regent",
  468. name: "Regent",
  469. family: .executive,
  470. headline: .centered,
  471. accent: .blueBar,
  472. layout: .twoColumn(sidebar: .leading, tinted: true),
  473. sectionLabelStyle: .uppercase
  474. ),
  475. CVTemplate(
  476. id: "monarch",
  477. name: "Monarch",
  478. family: .executive,
  479. headline: .centered,
  480. accent: .blueBar,
  481. layout: .singleColumn,
  482. sectionLabelStyle: .uppercase
  483. ),
  484. CVTemplate(
  485. id: "sterling",
  486. name: "Sterling",
  487. family: .executive,
  488. headline: .leftAligned,
  489. accent: .blueBar,
  490. layout: .twoColumn(sidebar: .trailing, tinted: false),
  491. sectionLabelStyle: .uppercase
  492. ),
  493. CVTemplate(
  494. id: "summit",
  495. name: "Summit",
  496. family: .executive,
  497. headline: .centered,
  498. accent: .redUnderline,
  499. layout: .twoColumn(sidebar: .leading, tinted: false),
  500. sectionLabelStyle: .uppercase
  501. ),
  502. CVTemplate(
  503. id: "estate",
  504. name: "Estate",
  505. family: .executive,
  506. headline: .leftWithInitials,
  507. accent: .blueBar,
  508. layout: .twoColumn(sidebar: .trailing, tinted: true),
  509. sectionLabelStyle: .uppercase
  510. ),
  511. CVTemplate(
  512. id: "chairman",
  513. name: "Chairman",
  514. family: .executive,
  515. headline: .leftAligned,
  516. accent: .blueBar,
  517. layout: .singleColumn,
  518. sectionLabelStyle: .uppercase
  519. )
  520. ]
  521. }
  522. // MARK: - View
  523. /// Standalone NSView for the CV Maker route. Renders the template gallery with
  524. /// header, segmented category groups, family chips, a thumbnail grid, and a
  525. /// bottom CTA. Hosts inside the same `nonHomeHost` slot as Saved Jobs/Settings.
  526. final class CVMakerPageView: NSView {
  527. private enum Palette {
  528. static var primaryText: NSColor { AppDashboardTheme.primaryText }
  529. static var secondaryText: NSColor { AppDashboardTheme.secondaryText }
  530. static var cardBackground: NSColor { AppDashboardTheme.cardBackground }
  531. static var cardBorder: NSColor { AppDashboardTheme.border }
  532. static var cardBorderHover: NSColor { AppDashboardTheme.cvMakerCardBorderHover }
  533. static var cardBorderSelected: NSColor { AppDashboardTheme.brandBlue }
  534. static var cardFooter: NSColor { AppDashboardTheme.cvMakerCardFooter }
  535. static var previewSurface: NSColor { AppDashboardTheme.cvMakerPreviewSurface }
  536. static var previewPaper: NSColor { CVResumeAppearance.colors().paper }
  537. static var previewSidebarTint: NSColor { CVResumeAppearance.colors().sidebarTint }
  538. static var previewInk: NSColor { CVResumeAppearance.colors().ink }
  539. static var previewMuted: NSColor { CVResumeAppearance.colors().muted }
  540. static var previewAccentRed: NSColor { CVResumeAppearance.colors().accentRed }
  541. static var previewAccentBlue: NSColor { CVResumeAppearance.colors().accentBlue }
  542. static var ctaBackground: NSColor { AppDashboardTheme.brandBlue }
  543. static var ctaHover: NSColor { AppDashboardTheme.brandBlueHover }
  544. static var ctaText: NSColor { AppDashboardTheme.proCTAText }
  545. static var selectionGlow: NSColor { AppDashboardTheme.cvMakerSelectionGlow }
  546. static var gradientTop: NSColor { AppDashboardTheme.cvMakerPageGradientTop }
  547. static var gradientBottom: NSColor { AppDashboardTheme.cvMakerPageGradientBottom }
  548. static var filterChromeBorder: NSColor { AppDashboardTheme.cvMakerFilterChromeBorder }
  549. }
  550. private var appearanceObserver: NSObjectProtocol?
  551. private let pageGradientLayer = CAGradientLayer()
  552. private let filterChrome = NSVisualEffectView()
  553. private let filterStack = NSStackView()
  554. private let titleLabel = NSTextField(labelWithString: "Templates")
  555. private let subtitleLabel = NSTextField(labelWithString: "Polished layouts with live previews — pick a style that fits your story.")
  556. private let groupTabsRow = NSStackView()
  557. private let familyChipsRow = NSStackView()
  558. private let scrollView = NSScrollView()
  559. private let gridDocument = TopFlippedView()
  560. private let gridStack = NSStackView()
  561. private let ctaButton = CVHoverableButton(title: "Use Template & Select Profile →", target: nil, action: nil)
  562. private var selectedGroup: CVCategoryGroup = .professionBased
  563. private var selectedFamily: CVDesignFamily? = nil // nil == "All"
  564. private var selectedTemplateID: String? = "metro"
  565. /// Exactly one gallery card — avoids multiple highlighted cards when catalog entries share the same `template.id`.
  566. private var selectedTemplateCardToken: UUID?
  567. /// Shown immediately; replaced when `CVTemplateFetchService` returns AI-generated entries.
  568. private var activeCatalog: [CVTemplate] = CVTemplateCatalog.all
  569. private var groupTabButtons: [CVCategoryGroup: CVChipButton] = [:]
  570. private var familyChipButtons: [CVDesignFamily?: CVChipButton] = [:]
  571. /// Every visible gallery card (not keyed by id — duplicate AI ids would collapse in a dictionary and break single-selection visuals).
  572. private var templateCardsInGrid: [CVTemplateCard] = []
  573. /// Invoked when the user taps **Use Template & Select Profile** with a valid gallery selection. Delivers the same `CVTemplate` instance the card used for its thumbnail (not a re-lookup by id), so the filled résumé cannot drift from the user’s pick.
  574. var onContinueToProfileSelection: ((CVTemplate) -> Void)?
  575. func templateInGallery(withID id: String) -> CVTemplate? {
  576. resolvedTemplate(withID: id)
  577. }
  578. /// Resolves a template from the live gallery, then falls back to the built-in catalog when AI fetch replaces `activeCatalog` (so the user’s selection still previews correctly).
  579. func resolvedTemplate(withID id: String) -> CVTemplate? {
  580. if let match = activeCatalog.first(where: { $0.id == id }) { return match }
  581. return CVTemplateCatalog.all.first { $0.id == id }
  582. }
  583. private var appliedGridColumnCount: Int = 0
  584. /// Family filter row always renders this many slots so chip widths stay stable
  585. /// when switching between Design-Based (3 labels) and Profession-Based (4).
  586. private let familyChipSlotCount = 4
  587. private enum FilterChromeLayout {
  588. static let padding: CGFloat = 12
  589. static let rowGap: CGFloat = 12
  590. static let groupRowHeight: CGFloat = 38
  591. static let familyRowHeight: CGFloat = 30
  592. static var height: CGFloat {
  593. padding * 2 + groupRowHeight + rowGap + familyRowHeight
  594. }
  595. }
  596. override init(frame frameRect: NSRect) {
  597. super.init(frame: frameRect)
  598. configureLayout()
  599. reloadFamilyChips()
  600. reloadTemplateGrid()
  601. updateSelectedChipStates()
  602. beginLoadingAICatalogIfPossible()
  603. appearanceObserver = NotificationCenter.default.addObserver(
  604. forName: AppAppearanceManager.didChangeNotification,
  605. object: nil,
  606. queue: .main
  607. ) { [weak self] _ in
  608. self?.applyCurrentAppearance()
  609. }
  610. applyCurrentAppearance()
  611. }
  612. deinit {
  613. if let appearanceObserver {
  614. NotificationCenter.default.removeObserver(appearanceObserver)
  615. }
  616. }
  617. @available(*, unavailable)
  618. required init?(coder: NSCoder) {
  619. fatalError("init(coder:) has not been implemented")
  620. }
  621. override func viewDidChangeEffectiveAppearance() {
  622. super.viewDidChangeEffectiveAppearance()
  623. applyCurrentAppearance()
  624. }
  625. override func layout() {
  626. super.layout()
  627. pageGradientLayer.frame = bounds
  628. layoutGridCardsIfNeeded()
  629. }
  630. func applyCurrentAppearance() {
  631. pageGradientLayer.colors = [Palette.gradientBottom.cgColor, Palette.gradientTop.cgColor]
  632. filterChrome.layer?.borderColor = Palette.filterChromeBorder.cgColor
  633. titleLabel.textColor = Palette.primaryText
  634. subtitleLabel.textColor = Palette.secondaryText
  635. styleCTAButton(ctaButton)
  636. for chip in groupTabButtons.values { chip.applyCurrentAppearance() }
  637. for chip in familyChipButtons.values { chip.applyCurrentAppearance() }
  638. reloadTemplateGrid()
  639. updateSelectedChipStates()
  640. }
  641. // MARK: Setup
  642. private func configureLayout() {
  643. wantsLayer = true
  644. layer?.backgroundColor = NSColor.clear.cgColor
  645. pageGradientLayer.locations = [0, 1] as [NSNumber]
  646. pageGradientLayer.startPoint = CGPoint(x: 0.5, y: 0)
  647. pageGradientLayer.endPoint = CGPoint(x: 0.5, y: 1)
  648. layer?.insertSublayer(pageGradientLayer, at: 0)
  649. filterChrome.translatesAutoresizingMaskIntoConstraints = false
  650. filterChrome.material = .contentBackground
  651. filterChrome.blendingMode = .withinWindow
  652. filterChrome.state = .active
  653. filterChrome.wantsLayer = true
  654. filterChrome.layer?.cornerRadius = 18
  655. filterChrome.layer?.borderWidth = 1
  656. filterStack.orientation = .vertical
  657. filterStack.spacing = 12
  658. filterStack.alignment = .leading
  659. filterStack.translatesAutoresizingMaskIntoConstraints = false
  660. filterStack.addArrangedSubview(groupTabsRow)
  661. filterStack.addArrangedSubview(familyChipsRow)
  662. filterChrome.addSubview(filterStack)
  663. NSLayoutConstraint.activate([
  664. filterStack.leadingAnchor.constraint(equalTo: filterChrome.leadingAnchor, constant: 14),
  665. filterStack.trailingAnchor.constraint(equalTo: filterChrome.trailingAnchor, constant: -14),
  666. filterStack.topAnchor.constraint(equalTo: filterChrome.topAnchor, constant: 12),
  667. filterStack.bottomAnchor.constraint(equalTo: filterChrome.bottomAnchor, constant: -12),
  668. // On this SDK `alignment` is `NSLayoutConstraint.Attribute` (no `.fill`).
  669. // Pin row widths so group tabs stay full-width / equal split instead of
  670. // shrinking to intrinsic width when selection changes.
  671. groupTabsRow.widthAnchor.constraint(equalTo: filterStack.widthAnchor),
  672. familyChipsRow.widthAnchor.constraint(equalTo: filterStack.widthAnchor)
  673. ])
  674. titleLabel.font = .systemFont(ofSize: 22, weight: .bold)
  675. titleLabel.textColor = Palette.primaryText
  676. titleLabel.alignment = .left
  677. subtitleLabel.font = .systemFont(ofSize: 13, weight: .regular)
  678. subtitleLabel.textColor = Palette.secondaryText
  679. subtitleLabel.alignment = .left
  680. subtitleLabel.maximumNumberOfLines = 1
  681. let headerStack = NSStackView(views: [titleLabel, subtitleLabel])
  682. headerStack.orientation = .vertical
  683. headerStack.spacing = 4
  684. headerStack.alignment = .leading
  685. headerStack.translatesAutoresizingMaskIntoConstraints = false
  686. groupTabsRow.orientation = .horizontal
  687. groupTabsRow.spacing = 8
  688. groupTabsRow.alignment = .centerY
  689. groupTabsRow.distribution = .fillEqually
  690. groupTabsRow.translatesAutoresizingMaskIntoConstraints = false
  691. groupTabsRow.heightAnchor.constraint(equalToConstant: 38).isActive = true
  692. configureGroupTabs()
  693. familyChipsRow.orientation = .horizontal
  694. familyChipsRow.spacing = 8
  695. familyChipsRow.alignment = .centerY
  696. // Match the top row: equal-width segments, evenly spaced across the row.
  697. familyChipsRow.distribution = .fillEqually
  698. familyChipsRow.translatesAutoresizingMaskIntoConstraints = false
  699. familyChipsRow.heightAnchor.constraint(equalToConstant: 30).isActive = true
  700. gridStack.orientation = .vertical
  701. gridStack.spacing = 26
  702. gridStack.alignment = .leading
  703. gridStack.distribution = .fill
  704. gridStack.translatesAutoresizingMaskIntoConstraints = false
  705. gridDocument.translatesAutoresizingMaskIntoConstraints = false
  706. gridDocument.addSubview(gridStack)
  707. NSLayoutConstraint.activate([
  708. gridStack.leadingAnchor.constraint(equalTo: gridDocument.leadingAnchor),
  709. gridStack.trailingAnchor.constraint(equalTo: gridDocument.trailingAnchor),
  710. gridStack.topAnchor.constraint(equalTo: gridDocument.topAnchor),
  711. gridStack.bottomAnchor.constraint(equalTo: gridDocument.bottomAnchor)
  712. ])
  713. scrollView.translatesAutoresizingMaskIntoConstraints = false
  714. scrollView.hasVerticalScroller = true
  715. scrollView.hasHorizontalScroller = false
  716. scrollView.scrollerStyle = .legacy
  717. scrollView.autohidesScrollers = true
  718. scrollView.drawsBackground = false
  719. scrollView.borderType = .noBorder
  720. scrollView.documentView = gridDocument
  721. NSLayoutConstraint.activate([
  722. gridDocument.topAnchor.constraint(equalTo: scrollView.contentView.topAnchor),
  723. gridDocument.leadingAnchor.constraint(equalTo: scrollView.contentView.leadingAnchor),
  724. gridDocument.widthAnchor.constraint(equalTo: scrollView.contentView.widthAnchor)
  725. ])
  726. ctaButton.translatesAutoresizingMaskIntoConstraints = false
  727. styleCTAButton(ctaButton)
  728. ctaButton.target = self
  729. ctaButton.action = #selector(didTapUseTemplate)
  730. addSubview(headerStack)
  731. addSubview(filterChrome)
  732. addSubview(scrollView)
  733. addSubview(ctaButton)
  734. let horizontalInset: CGFloat = 32
  735. NSLayoutConstraint.activate([
  736. headerStack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  737. headerStack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  738. headerStack.topAnchor.constraint(equalTo: topAnchor, constant: 8),
  739. filterChrome.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  740. filterChrome.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  741. filterChrome.topAnchor.constraint(equalTo: headerStack.bottomAnchor, constant: 16),
  742. filterChrome.heightAnchor.constraint(equalToConstant: FilterChromeLayout.height),
  743. scrollView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  744. scrollView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  745. scrollView.topAnchor.constraint(equalTo: filterChrome.bottomAnchor, constant: 18),
  746. scrollView.bottomAnchor.constraint(equalTo: ctaButton.topAnchor, constant: -18),
  747. ctaButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  748. ctaButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  749. ctaButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -24),
  750. ctaButton.heightAnchor.constraint(equalToConstant: 52)
  751. ])
  752. }
  753. private func configureGroupTabs() {
  754. groupTabsRow.arrangedSubviews.forEach {
  755. groupTabsRow.removeArrangedSubview($0)
  756. $0.removeFromSuperview()
  757. }
  758. groupTabButtons.removeAll()
  759. let groups: [(CVCategoryGroup, String)] = [
  760. (.designBased, "rectangle.3.group"),
  761. (.professionBased, "person.2")
  762. ]
  763. for (group, symbolName) in groups {
  764. let count = templates(forGroup: group, family: nil).count
  765. let chip = CVChipButton(
  766. title: group.title,
  767. badgeText: "\(count)",
  768. leadingSymbol: symbolName,
  769. style: .pillLarge
  770. )
  771. chip.translatesAutoresizingMaskIntoConstraints = false
  772. chip.onSelect = { [weak self] in self?.didSelectGroup(group) }
  773. groupTabsRow.addArrangedSubview(chip)
  774. groupTabButtons[group] = chip
  775. }
  776. }
  777. private func reloadFamilyChips() {
  778. familyChipsRow.arrangedSubviews.forEach {
  779. familyChipsRow.removeArrangedSubview($0)
  780. $0.removeFromSuperview()
  781. }
  782. familyChipButtons.removeAll()
  783. let allCount = templates(forGroup: selectedGroup, family: nil).count
  784. let allChip = CVChipButton(title: "All", badgeText: "\(allCount)", leadingSymbol: nil, style: .pillSmall)
  785. allChip.translatesAutoresizingMaskIntoConstraints = false
  786. allChip.onSelect = { [weak self] in self?.didSelectFamily(nil) }
  787. familyChipsRow.addArrangedSubview(allChip)
  788. familyChipButtons[nil] = allChip
  789. for family in CVDesignFamily.allCases {
  790. let count = templates(forGroup: selectedGroup, family: family).count
  791. guard count > 0 else { continue }
  792. let chip = CVChipButton(title: family.title, badgeText: "\(count)", leadingSymbol: nil, style: .pillSmall)
  793. chip.translatesAutoresizingMaskIntoConstraints = false
  794. chip.onSelect = { [weak self] in self?.didSelectFamily(family) }
  795. familyChipsRow.addArrangedSubview(chip)
  796. familyChipButtons[family] = chip
  797. }
  798. // Pad to a fixed slot count so `fillEqually` chip widths never change when
  799. // the visible family count differs between category groups.
  800. while familyChipsRow.arrangedSubviews.count < familyChipSlotCount {
  801. let slot = NSView()
  802. slot.translatesAutoresizingMaskIntoConstraints = false
  803. slot.setContentHuggingPriority(.defaultLow, for: .horizontal)
  804. slot.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
  805. familyChipsRow.addArrangedSubview(slot)
  806. }
  807. if let f = selectedFamily, templates(forGroup: selectedGroup, family: f).isEmpty {
  808. selectedFamily = nil
  809. }
  810. }
  811. // MARK: Data filtering
  812. private func templates(forGroup group: CVCategoryGroup, family: CVDesignFamily?) -> [CVTemplate] {
  813. let base = activeCatalog.filter { $0.galleryGroup == group }
  814. guard let family else { return base }
  815. return base.filter { $0.family == family }
  816. }
  817. private var visibleTemplates: [CVTemplate] {
  818. templates(forGroup: selectedGroup, family: selectedFamily)
  819. }
  820. // MARK: Grid
  821. private func reloadTemplateGrid() {
  822. gridStack.arrangedSubviews.forEach {
  823. gridStack.removeArrangedSubview($0)
  824. $0.removeFromSuperview()
  825. }
  826. templateCardsInGrid.removeAll()
  827. let templates = visibleTemplates
  828. if templates.isEmpty {
  829. let empty = NSTextField(labelWithString: "No templates yet for this category.")
  830. empty.font = .systemFont(ofSize: 13)
  831. empty.textColor = Palette.secondaryText
  832. gridStack.addArrangedSubview(empty)
  833. selectedTemplateCardToken = nil
  834. return
  835. }
  836. let columns = resolvedGridColumnCount()
  837. var index = 0
  838. while index < templates.count {
  839. let row = NSStackView()
  840. row.orientation = .horizontal
  841. row.spacing = 22
  842. row.distribution = .fillEqually
  843. row.alignment = .top
  844. row.translatesAutoresizingMaskIntoConstraints = false
  845. row.setHuggingPriority(.defaultLow, for: .horizontal)
  846. for column in 0..<columns {
  847. let position = index + column
  848. if position < templates.count {
  849. let template = templates[position]
  850. let card = CVTemplateCard(template: template, palette: palette())
  851. card.translatesAutoresizingMaskIntoConstraints = false
  852. card.onSelect = { [weak self] in
  853. guard let self else { return }
  854. self.didSelectCard(card)
  855. }
  856. row.addArrangedSubview(card)
  857. templateCardsInGrid.append(card)
  858. } else {
  859. let filler = NSView()
  860. filler.translatesAutoresizingMaskIntoConstraints = false
  861. row.addArrangedSubview(filler)
  862. filler.heightAnchor.constraint(equalToConstant: CVTemplateCard.layoutHeight).isActive = true
  863. }
  864. }
  865. gridStack.addArrangedSubview(row)
  866. row.widthAnchor.constraint(equalTo: gridStack.widthAnchor).isActive = true
  867. row.heightAnchor.constraint(equalToConstant: CVTemplateCard.layoutHeight).isActive = true
  868. index += columns
  869. }
  870. if let sid = selectedTemplateID,
  871. let match = templateCardsInGrid.first(where: { $0.templateID == sid }) {
  872. selectedTemplateCardToken = match.selectionToken
  873. } else if let first = templateCardsInGrid.first {
  874. selectedTemplateCardToken = first.selectionToken
  875. selectedTemplateID = first.templateID
  876. } else {
  877. selectedTemplateCardToken = nil
  878. selectedTemplateID = nil
  879. }
  880. applySelectionToCards()
  881. }
  882. private func galleryLayoutWidth() -> CGFloat {
  883. if bounds.width > 8 { return bounds.width }
  884. if let s = superview, s.bounds.width > 8 { return max(s.bounds.width - 64, 400) }
  885. return 900
  886. }
  887. private func layoutGridCardsIfNeeded() {
  888. let cols = resolvedGridColumnCount()
  889. guard cols != appliedGridColumnCount else { return }
  890. appliedGridColumnCount = cols
  891. reloadTemplateGrid()
  892. updateSelectedChipStates()
  893. }
  894. private func resolvedGridColumnCount() -> Int {
  895. let w = max(galleryLayoutWidth(), 400)
  896. if w < 780 { return 2 }
  897. if w < 1080 { return 3 }
  898. return 4
  899. }
  900. private func applySelectionToCards() {
  901. let token = selectedTemplateCardToken
  902. for card in templateCardsInGrid {
  903. card.isSelected = (card.selectionToken == token)
  904. }
  905. }
  906. private func palette() -> CVTemplateCardPalette {
  907. CVTemplateCardPalette(
  908. border: Palette.cardBorder,
  909. borderHover: Palette.cardBorderHover,
  910. borderSelected: Palette.cardBorderSelected,
  911. selectionGlow: Palette.selectionGlow,
  912. cardShellBackground: Palette.cardBackground,
  913. footerBackground: Palette.cardFooter,
  914. previewSurface: Palette.previewSurface,
  915. previewPaper: Palette.previewPaper,
  916. previewSidebarTint: Palette.previewSidebarTint,
  917. previewInk: Palette.previewInk,
  918. previewMuted: Palette.previewMuted,
  919. previewAccentRed: Palette.previewAccentRed,
  920. previewAccentBlue: Palette.previewAccentBlue,
  921. primaryText: Palette.primaryText,
  922. secondaryText: Palette.secondaryText
  923. )
  924. }
  925. // MARK: Selection
  926. private func didSelectGroup(_ group: CVCategoryGroup) {
  927. guard selectedGroup != group else { return }
  928. selectedGroup = group
  929. selectedFamily = nil
  930. reloadFamilyChips()
  931. reloadTemplateGrid()
  932. updateSelectedChipStates()
  933. }
  934. private func didSelectFamily(_ family: CVDesignFamily?) {
  935. guard selectedFamily != family else { return }
  936. selectedFamily = family
  937. reloadTemplateGrid()
  938. updateSelectedChipStates()
  939. }
  940. private func didSelectCard(_ card: CVTemplateCard) {
  941. selectedTemplateCardToken = card.selectionToken
  942. selectedTemplateID = card.templateID
  943. applySelectionToCards()
  944. }
  945. @objc private func didTapUseTemplate() {
  946. let chosen: CVTemplate?
  947. if let token = selectedTemplateCardToken,
  948. let card = templateCardsInGrid.first(where: { $0.selectionToken == token }) {
  949. chosen = card.catalogTemplate
  950. } else if let id = selectedTemplateID {
  951. chosen = resolvedTemplate(withID: id)
  952. } else {
  953. chosen = nil
  954. }
  955. guard let template = chosen else {
  956. presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
  957. return
  958. }
  959. onContinueToProfileSelection?(template)
  960. }
  961. private func updateSelectedChipStates() {
  962. for (group, chip) in groupTabButtons {
  963. chip.isSelected = (group == selectedGroup)
  964. }
  965. for (family, chip) in familyChipButtons {
  966. chip.isSelected = (family == selectedFamily)
  967. }
  968. }
  969. private func styleCTAButton(_ button: CVHoverableButton) {
  970. button.title = "Use Template & Select Profile →"
  971. button.font = .systemFont(ofSize: 14, weight: .semibold)
  972. button.isBordered = false
  973. button.bezelStyle = .rounded
  974. button.focusRingType = .none
  975. button.contentTintColor = Palette.ctaText
  976. button.wantsLayer = true
  977. button.layer?.cornerRadius = 14
  978. button.layer?.backgroundColor = Palette.ctaBackground.cgColor
  979. button.pointerCursor = true
  980. let attrs: [NSAttributedString.Key: Any] = [
  981. .foregroundColor: Palette.ctaText,
  982. .font: NSFont.systemFont(ofSize: 14, weight: .semibold)
  983. ]
  984. button.attributedTitle = NSAttributedString(string: button.title, attributes: attrs)
  985. button.hoverHandler = { [weak button] hovering in
  986. button?.layer?.backgroundColor = (hovering ? Palette.ctaHover : Palette.ctaBackground).cgColor
  987. }
  988. }
  989. private func beginLoadingAICatalogIfPossible() {
  990. guard OpenAIConfiguration.hasAPIKey else { return }
  991. let defaultSubtitle = subtitleLabel.stringValue
  992. subtitleLabel.stringValue = "Fetching AI-curated templates…"
  993. CVTemplateFetchService.shared.fetchTemplates { [weak self] result in
  994. DispatchQueue.main.async {
  995. guard let self else { return }
  996. switch result {
  997. case .success(let list):
  998. self.subtitleLabel.stringValue = defaultSubtitle
  999. if !list.isEmpty {
  1000. self.activeCatalog = list
  1001. self.configureGroupTabs()
  1002. self.reloadFamilyChips()
  1003. self.reloadTemplateGrid()
  1004. self.updateSelectedChipStates()
  1005. }
  1006. case .failure:
  1007. self.subtitleLabel.stringValue = "Couldn’t load AI templates — showing the built-in gallery."
  1008. DispatchQueue.main.asyncAfter(deadline: .now() + 5.5) { [weak self] in
  1009. self?.subtitleLabel.stringValue = defaultSubtitle
  1010. }
  1011. }
  1012. }
  1013. }
  1014. }
  1015. private func presentPlaceholderAlert(title: String, message: String) {
  1016. let alert = NSAlert()
  1017. alert.messageText = title
  1018. alert.informativeText = message
  1019. alert.alertStyle = .informational
  1020. alert.addButton(withTitle: "OK")
  1021. if let window {
  1022. alert.beginSheetModal(for: window)
  1023. } else {
  1024. alert.runModal()
  1025. }
  1026. }
  1027. }
  1028. // MARK: - Chip / pill button
  1029. /// Reusable pill button used for both the top section toggle ("Design-Based"
  1030. /// vs "Profession-Based") and the family filter chips. Switches between an
  1031. /// active brand-blue state and a soft neutral state, with an inline count badge.
  1032. private final class CVChipButton: NSView {
  1033. enum Style { case pillLarge, pillSmall }
  1034. var onSelect: (() -> Void)?
  1035. var isSelected: Bool = false { didSet { applyState() } }
  1036. private let style: Style
  1037. private let titleLabel = NSTextField(labelWithString: "")
  1038. private let badgeLabel = NSTextField(labelWithString: "")
  1039. private let badgePill = NSView()
  1040. private let symbolView = NSImageView()
  1041. private let stack = NSStackView()
  1042. private var isHovering: Bool = false
  1043. private var didPushCursor: Bool = false
  1044. private var trackingArea: NSTrackingArea?
  1045. private enum Palette {
  1046. static var restFill: NSColor { AppDashboardTheme.cvMakerChipRestFill }
  1047. static var restBorder: NSColor { AppDashboardTheme.cvMakerChipRestBorder }
  1048. static var hoverFill: NSColor { AppDashboardTheme.cvMakerChipHoverFill }
  1049. static var activeFill: NSColor { AppDashboardTheme.brandBlue }
  1050. static var activeFillHover: NSColor { AppDashboardTheme.brandBlueHover }
  1051. static var activeBorder: NSColor { AppDashboardTheme.brandBlueHover }
  1052. static var restText: NSColor { AppDashboardTheme.primaryText }
  1053. static var activeText: NSColor { AppDashboardTheme.proCTAText }
  1054. static var restBadge: NSColor { AppDashboardTheme.cvMakerChipBadgeBackground }
  1055. static var restBadgeText: NSColor { AppDashboardTheme.cvMakerChipBadgeText }
  1056. static var activeBadge: NSColor { NSColor.white.withAlphaComponent(0.22) }
  1057. static var activeBadgeText: NSColor { AppDashboardTheme.proCTAText }
  1058. }
  1059. func applyCurrentAppearance() {
  1060. applyState()
  1061. }
  1062. private static let symbolSide: CGFloat = 18
  1063. private static let badgeWidthLarge: CGFloat = 28
  1064. private static let badgeWidthSmall: CGFloat = 26
  1065. init(title: String, badgeText: String, leadingSymbol: String?, style: Style) {
  1066. self.style = style
  1067. super.init(frame: .zero)
  1068. wantsLayer = true
  1069. translatesAutoresizingMaskIntoConstraints = false
  1070. let height: CGFloat = style == .pillLarge ? 38 : 30
  1071. layer?.cornerRadius = height / 2
  1072. layer?.borderWidth = 1
  1073. heightAnchor.constraint(equalToConstant: height).isActive = true
  1074. titleLabel.stringValue = title
  1075. titleLabel.font = .systemFont(ofSize: style == .pillLarge ? 13 : 12, weight: .semibold)
  1076. titleLabel.maximumNumberOfLines = 1
  1077. titleLabel.lineBreakMode = .byTruncatingTail
  1078. titleLabel.cell?.lineBreakMode = .byTruncatingTail
  1079. titleLabel.isBordered = false
  1080. titleLabel.drawsBackground = false
  1081. titleLabel.isEditable = false
  1082. titleLabel.isSelectable = false
  1083. badgeLabel.stringValue = badgeText
  1084. badgeLabel.font = .monospacedDigitSystemFont(ofSize: 10.5, weight: .semibold)
  1085. badgeLabel.alignment = .center
  1086. badgeLabel.isBordered = false
  1087. badgeLabel.drawsBackground = false
  1088. badgeLabel.isEditable = false
  1089. badgeLabel.isSelectable = false
  1090. badgePill.translatesAutoresizingMaskIntoConstraints = false
  1091. badgePill.wantsLayer = true
  1092. badgePill.layer?.cornerRadius = 9
  1093. badgePill.addSubview(badgeLabel)
  1094. badgeLabel.translatesAutoresizingMaskIntoConstraints = false
  1095. NSLayoutConstraint.activate([
  1096. badgeLabel.leadingAnchor.constraint(equalTo: badgePill.leadingAnchor, constant: 7),
  1097. badgeLabel.trailingAnchor.constraint(equalTo: badgePill.trailingAnchor, constant: -7),
  1098. badgeLabel.centerYAnchor.constraint(equalTo: badgePill.centerYAnchor),
  1099. badgePill.heightAnchor.constraint(equalToConstant: 18),
  1100. badgePill.widthAnchor.constraint(
  1101. equalToConstant: style == .pillLarge ? Self.badgeWidthLarge : Self.badgeWidthSmall
  1102. )
  1103. ])
  1104. stack.orientation = .horizontal
  1105. stack.spacing = 8
  1106. stack.alignment = .centerY
  1107. stack.translatesAutoresizingMaskIntoConstraints = false
  1108. if let symbol = leadingSymbol, style == .pillLarge {
  1109. symbolView.translatesAutoresizingMaskIntoConstraints = false
  1110. symbolView.image = NSImage(systemSymbolName: symbol, accessibilityDescription: nil)
  1111. symbolView.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
  1112. symbolView.setContentHuggingPriority(.required, for: .horizontal)
  1113. symbolView.setContentCompressionResistancePriority(.required, for: .horizontal)
  1114. stack.addArrangedSubview(symbolView)
  1115. NSLayoutConstraint.activate([
  1116. symbolView.widthAnchor.constraint(equalToConstant: Self.symbolSide),
  1117. symbolView.heightAnchor.constraint(equalToConstant: Self.symbolSide)
  1118. ])
  1119. }
  1120. stack.addArrangedSubview(titleLabel)
  1121. stack.addArrangedSubview(badgePill)
  1122. addSubview(stack)
  1123. let horizontalInset: CGFloat = style == .pillLarge ? 16 : 12
  1124. // Leading alignment for every chip so selected vs unselected pills share the
  1125. // same geometry (centered stacks shift when badge digits change).
  1126. if style == .pillLarge {
  1127. NSLayoutConstraint.activate([
  1128. stack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  1129. stack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  1130. stack.centerYAnchor.constraint(equalTo: centerYAnchor)
  1131. ])
  1132. setContentHuggingPriority(.defaultLow, for: .horizontal)
  1133. } else {
  1134. // Parent row uses `fillEqually`; center label + badge inside each segment.
  1135. NSLayoutConstraint.activate([
  1136. stack.centerXAnchor.constraint(equalTo: centerXAnchor),
  1137. stack.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: horizontalInset),
  1138. stack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  1139. stack.centerYAnchor.constraint(equalTo: centerYAnchor)
  1140. ])
  1141. setContentHuggingPriority(.defaultLow, for: .horizontal)
  1142. setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
  1143. }
  1144. applyState()
  1145. }
  1146. @available(*, unavailable)
  1147. required init?(coder: NSCoder) {
  1148. fatalError("init(coder:) has not been implemented")
  1149. }
  1150. override func hitTest(_ point: NSPoint) -> NSView? {
  1151. guard let superview else { return super.hitTest(point) }
  1152. let local = convert(point, from: superview)
  1153. return bounds.contains(local) ? self : nil
  1154. }
  1155. override func mouseDown(with event: NSEvent) {
  1156. onSelect?()
  1157. }
  1158. override func updateTrackingAreas() {
  1159. super.updateTrackingAreas()
  1160. if let area = trackingArea { removeTrackingArea(area) }
  1161. let area = NSTrackingArea(
  1162. rect: bounds,
  1163. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  1164. owner: self,
  1165. userInfo: nil
  1166. )
  1167. addTrackingArea(area)
  1168. trackingArea = area
  1169. }
  1170. override func mouseEntered(with event: NSEvent) {
  1171. super.mouseEntered(with: event)
  1172. isHovering = true
  1173. applyState()
  1174. if !didPushCursor {
  1175. NSCursor.pointingHand.push()
  1176. didPushCursor = true
  1177. }
  1178. }
  1179. override func mouseExited(with event: NSEvent) {
  1180. super.mouseExited(with: event)
  1181. isHovering = false
  1182. applyState()
  1183. if didPushCursor {
  1184. NSCursor.pop()
  1185. didPushCursor = false
  1186. }
  1187. }
  1188. override func viewWillMove(toWindow newWindow: NSWindow?) {
  1189. super.viewWillMove(toWindow: newWindow)
  1190. if newWindow == nil, didPushCursor {
  1191. NSCursor.pop()
  1192. didPushCursor = false
  1193. isHovering = false
  1194. }
  1195. }
  1196. private func applyState() {
  1197. let fill: NSColor
  1198. let border: NSColor
  1199. let textColor: NSColor
  1200. let badgeFill: NSColor
  1201. let badgeText: NSColor
  1202. if isSelected {
  1203. fill = isHovering ? Palette.activeFillHover : Palette.activeFill
  1204. border = Palette.activeBorder
  1205. textColor = Palette.activeText
  1206. badgeFill = Palette.activeBadge
  1207. badgeText = Palette.activeBadgeText
  1208. } else {
  1209. fill = isHovering ? Palette.hoverFill : Palette.restFill
  1210. border = Palette.restBorder
  1211. textColor = Palette.restText
  1212. badgeFill = Palette.restBadge
  1213. badgeText = Palette.restBadgeText
  1214. }
  1215. layer?.backgroundColor = fill.cgColor
  1216. layer?.borderColor = border.cgColor
  1217. layer?.borderWidth = 1
  1218. titleLabel.textColor = textColor
  1219. symbolView.contentTintColor = textColor
  1220. badgePill.layer?.backgroundColor = badgeFill.cgColor
  1221. badgeLabel.textColor = badgeText
  1222. }
  1223. }
  1224. // MARK: - Template card
  1225. /// Premium gallery card: live résumé thumbnail, soft shadow, and an animated
  1226. /// brand border when selected.
  1227. private final class CVTemplateCard: NSView {
  1228. static let layoutHeight: CGFloat = 292
  1229. var onSelect: (() -> Void)?
  1230. var isSelected: Bool = false { didSet { applyChrome() } }
  1231. /// Distinguishes this card from others that may share the same catalog `template.id`.
  1232. let selectionToken = UUID()
  1233. var templateID: String { template.id }
  1234. /// Definition used for this card’s preview; pass through on “Use template” so layout cannot diverge from a later id-only lookup.
  1235. var catalogTemplate: CVTemplate { template }
  1236. private let template: CVTemplate
  1237. private let palette: CVTemplateCardPalette
  1238. private let previewSurface = NSView()
  1239. private let footerView = NSView()
  1240. private let preview: CVTemplatePreviewView
  1241. private let nameLabel = NSTextField(labelWithString: "")
  1242. private let categoryLabel = NSTextField(labelWithString: "")
  1243. private var trackingArea: NSTrackingArea?
  1244. private var isHovering: Bool = false
  1245. private var didPushCursor: Bool = false
  1246. init(template: CVTemplate, palette: CVTemplateCardPalette) {
  1247. self.template = template
  1248. self.palette = palette
  1249. self.preview = CVTemplatePreviewView(template: template, palette: palette)
  1250. super.init(frame: .zero)
  1251. wantsLayer = true
  1252. layer?.masksToBounds = false
  1253. layer?.cornerRadius = 24
  1254. layer?.backgroundColor = palette.cardShellBackground.cgColor
  1255. translatesAutoresizingMaskIntoConstraints = false
  1256. heightAnchor.constraint(equalToConstant: Self.layoutHeight).isActive = true
  1257. previewSurface.translatesAutoresizingMaskIntoConstraints = false
  1258. previewSurface.wantsLayer = true
  1259. previewSurface.layer?.backgroundColor = palette.previewSurface.cgColor
  1260. preview.translatesAutoresizingMaskIntoConstraints = false
  1261. previewSurface.addSubview(preview)
  1262. nameLabel.stringValue = template.name
  1263. nameLabel.font = .systemFont(ofSize: 14, weight: .semibold)
  1264. nameLabel.textColor = palette.primaryText
  1265. nameLabel.isBordered = false
  1266. nameLabel.drawsBackground = false
  1267. nameLabel.isEditable = false
  1268. nameLabel.isSelectable = false
  1269. categoryLabel.stringValue = "\(template.category) · \(template.layoutType.gallerySubtitle)"
  1270. categoryLabel.font = .systemFont(ofSize: 11.5, weight: .regular)
  1271. categoryLabel.textColor = palette.secondaryText
  1272. categoryLabel.isBordered = false
  1273. categoryLabel.drawsBackground = false
  1274. categoryLabel.isEditable = false
  1275. categoryLabel.isSelectable = false
  1276. let footerStack = NSStackView(views: [nameLabel, categoryLabel])
  1277. footerStack.orientation = .vertical
  1278. footerStack.spacing = 3
  1279. footerStack.alignment = .leading
  1280. footerStack.translatesAutoresizingMaskIntoConstraints = false
  1281. footerView.translatesAutoresizingMaskIntoConstraints = false
  1282. footerView.wantsLayer = true
  1283. footerView.layer?.backgroundColor = palette.footerBackground.cgColor
  1284. footerView.addSubview(footerStack)
  1285. NSLayoutConstraint.activate([
  1286. footerStack.leadingAnchor.constraint(equalTo: footerView.leadingAnchor, constant: 16),
  1287. footerStack.trailingAnchor.constraint(lessThanOrEqualTo: footerView.trailingAnchor, constant: -16),
  1288. footerStack.topAnchor.constraint(equalTo: footerView.topAnchor, constant: 13),
  1289. footerStack.bottomAnchor.constraint(equalTo: footerView.bottomAnchor, constant: -13)
  1290. ])
  1291. addSubview(previewSurface)
  1292. addSubview(footerView)
  1293. NSLayoutConstraint.activate([
  1294. previewSurface.topAnchor.constraint(equalTo: topAnchor),
  1295. previewSurface.leadingAnchor.constraint(equalTo: leadingAnchor),
  1296. previewSurface.trailingAnchor.constraint(equalTo: trailingAnchor),
  1297. previewSurface.heightAnchor.constraint(greaterThanOrEqualToConstant: 236),
  1298. preview.topAnchor.constraint(equalTo: previewSurface.topAnchor, constant: 14),
  1299. preview.leadingAnchor.constraint(equalTo: previewSurface.leadingAnchor, constant: 16),
  1300. preview.trailingAnchor.constraint(equalTo: previewSurface.trailingAnchor, constant: -16),
  1301. preview.bottomAnchor.constraint(equalTo: previewSurface.bottomAnchor, constant: -14),
  1302. footerView.topAnchor.constraint(equalTo: previewSurface.bottomAnchor),
  1303. footerView.leadingAnchor.constraint(equalTo: leadingAnchor),
  1304. footerView.trailingAnchor.constraint(equalTo: trailingAnchor),
  1305. footerView.bottomAnchor.constraint(equalTo: bottomAnchor)
  1306. ])
  1307. applyChrome()
  1308. }
  1309. @available(*, unavailable)
  1310. required init?(coder: NSCoder) {
  1311. fatalError("init(coder:) has not been implemented")
  1312. }
  1313. override func layout() {
  1314. super.layout()
  1315. layer?.shadowPath = CGPath(roundedRect: bounds, cornerWidth: 24, cornerHeight: 24, transform: nil)
  1316. }
  1317. override func hitTest(_ point: NSPoint) -> NSView? {
  1318. guard let superview else { return super.hitTest(point) }
  1319. let local = convert(point, from: superview)
  1320. return bounds.contains(local) ? self : nil
  1321. }
  1322. override func mouseDown(with event: NSEvent) {
  1323. playTapPulse()
  1324. onSelect?()
  1325. }
  1326. private func playTapPulse() {
  1327. guard let l = layer else { return }
  1328. let a = CABasicAnimation(keyPath: "transform")
  1329. a.fromValue = NSValue(caTransform3D: CATransform3DIdentity)
  1330. a.toValue = NSValue(caTransform3D: CATransform3DMakeScale(0.985, 0.985, 1))
  1331. a.duration = 0.1
  1332. a.autoreverses = true
  1333. a.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
  1334. l.add(a, forKey: "tapPulse")
  1335. }
  1336. override func updateTrackingAreas() {
  1337. super.updateTrackingAreas()
  1338. if let area = trackingArea { removeTrackingArea(area) }
  1339. let area = NSTrackingArea(
  1340. rect: bounds,
  1341. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  1342. owner: self,
  1343. userInfo: nil
  1344. )
  1345. addTrackingArea(area)
  1346. trackingArea = area
  1347. }
  1348. override func mouseEntered(with event: NSEvent) {
  1349. super.mouseEntered(with: event)
  1350. isHovering = true
  1351. applyChrome()
  1352. if !didPushCursor {
  1353. NSCursor.pointingHand.push()
  1354. didPushCursor = true
  1355. }
  1356. }
  1357. override func mouseExited(with event: NSEvent) {
  1358. super.mouseExited(with: event)
  1359. isHovering = false
  1360. applyChrome()
  1361. if didPushCursor {
  1362. NSCursor.pop()
  1363. didPushCursor = false
  1364. }
  1365. }
  1366. override func viewWillMove(toWindow newWindow: NSWindow?) {
  1367. super.viewWillMove(toWindow: newWindow)
  1368. if newWindow == nil, didPushCursor {
  1369. NSCursor.pop()
  1370. didPushCursor = false
  1371. isHovering = false
  1372. }
  1373. }
  1374. private func applyChrome() {
  1375. // Same border + shadow metrics in every state — only color changes on select
  1376. // so thumbnails keep identical insets (stroke is drawn inside the layer).
  1377. let uniformBorder: CGFloat = 2
  1378. let borderColor: NSColor
  1379. if isSelected {
  1380. borderColor = palette.borderSelected
  1381. } else if isHovering {
  1382. borderColor = palette.borderHover
  1383. } else {
  1384. borderColor = palette.border
  1385. }
  1386. layer?.backgroundColor = palette.cardShellBackground.cgColor
  1387. previewSurface.layer?.backgroundColor = palette.previewSurface.cgColor
  1388. footerView.layer?.backgroundColor = palette.footerBackground.cgColor
  1389. nameLabel.textColor = palette.primaryText
  1390. categoryLabel.textColor = palette.secondaryText
  1391. layer?.borderColor = borderColor.cgColor
  1392. layer?.borderWidth = uniformBorder
  1393. layer?.shadowColor = NSColor.black.cgColor
  1394. layer?.shadowOpacity = isSelected ? 0.14 : (isHovering ? 0.11 : 0.08)
  1395. layer?.shadowRadius = 14
  1396. layer?.shadowOffset = CGSize(width: 0, height: 8)
  1397. }
  1398. }
  1399. // MARK: - Helpers
  1400. /// Flipped origin so the grid stacks fill from the top.
  1401. private final class TopFlippedView: NSView {
  1402. override var isFlipped: Bool { true }
  1403. }
  1404. /// Local copy of the dashboard's hoverable button so this file stays
  1405. /// self-contained without exposing the existing private classes.
  1406. private final class CVHoverableButton: NSButton {
  1407. var hoverHandler: ((Bool) -> Void)?
  1408. var pointerCursor: Bool = false
  1409. private(set) var isHovering: Bool = false
  1410. private var trackingArea: NSTrackingArea?
  1411. private var didPushCursor: Bool = false
  1412. override func updateTrackingAreas() {
  1413. super.updateTrackingAreas()
  1414. if let area = trackingArea { removeTrackingArea(area) }
  1415. let area = NSTrackingArea(
  1416. rect: bounds,
  1417. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  1418. owner: self,
  1419. userInfo: nil
  1420. )
  1421. addTrackingArea(area)
  1422. trackingArea = area
  1423. }
  1424. override func mouseEntered(with event: NSEvent) {
  1425. super.mouseEntered(with: event)
  1426. isHovering = true
  1427. hoverHandler?(true)
  1428. if pointerCursor, !didPushCursor {
  1429. NSCursor.pointingHand.push()
  1430. didPushCursor = true
  1431. }
  1432. }
  1433. override func mouseExited(with event: NSEvent) {
  1434. super.mouseExited(with: event)
  1435. isHovering = false
  1436. hoverHandler?(false)
  1437. if didPushCursor {
  1438. NSCursor.pop()
  1439. didPushCursor = false
  1440. }
  1441. }
  1442. override func viewWillMove(toWindow newWindow: NSWindow?) {
  1443. super.viewWillMove(toWindow: newWindow)
  1444. if newWindow == nil, didPushCursor {
  1445. NSCursor.pop()
  1446. didPushCursor = false
  1447. isHovering = false
  1448. }
  1449. }
  1450. }