PostGeneratorView.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. import AppKit
  2. import SwiftUI
  3. import UniformTypeIdentifiers
  4. struct PostGeneratorView: View {
  5. @Bindable var viewModel: PostGeneratorViewModel
  6. private enum Layout {
  7. static let horizontalPadding: CGFloat = 24
  8. static let columnWidth: CGFloat = 300
  9. static let columnSpacing: CGFloat = 20
  10. static let sectionSpacing: CGFloat = 12
  11. static let imageUploadHeight: CGFloat = 140
  12. }
  13. var body: some View {
  14. VStack(spacing: 0) {
  15. header
  16. messageBanners
  17. ScrollView {
  18. VStack(alignment: .leading, spacing: 12) {
  19. tabBar
  20. PostPageBoundary {
  21. switch viewModel.selectedTab {
  22. case .compose:
  23. composeContent
  24. case .preview:
  25. previewContent
  26. }
  27. }
  28. }
  29. .padding(.horizontal, Layout.horizontalPadding)
  30. .padding(.top, 12)
  31. .padding(.bottom, 24)
  32. }
  33. }
  34. .background(AppTheme.background)
  35. .fileImporter(
  36. isPresented: $viewModel.showImageImporter,
  37. allowedContentTypes: [.image],
  38. allowsMultipleSelection: false
  39. ) { result in
  40. switch result {
  41. case .success(let urls):
  42. if let url = urls.first {
  43. viewModel.setImage(from: url)
  44. }
  45. case .failure(let error):
  46. viewModel.handleImageImportFailure(error)
  47. }
  48. }
  49. .alert("Replace existing content?", isPresented: $viewModel.showOverwriteConfirmation) {
  50. Button("Cancel", role: .cancel) {
  51. viewModel.cancelOverwriteConfirmation()
  52. }
  53. Button("Replace", role: .destructive) {
  54. Task { await viewModel.confirmOverwriteAndGenerate() }
  55. }
  56. } message: {
  57. Text("Generating will replace your current title, body, and poll options.")
  58. }
  59. .onChange(of: viewModel.draft.topic) { _, _ in viewModel.notifyDraftEdited() }
  60. .onChange(of: viewModel.draft.subreddit) { _, _ in viewModel.notifyDraftEdited() }
  61. .onChange(of: viewModel.draft.title) { _, _ in viewModel.notifyDraftEdited() }
  62. .onChange(of: viewModel.draft.body) { _, _ in viewModel.notifyDraftEdited() }
  63. .onChange(of: viewModel.draft.linkURL) { _, _ in viewModel.notifyDraftEdited() }
  64. .onChange(of: viewModel.draft.videoURL) { _, _ in viewModel.notifyDraftEdited() }
  65. .onChange(of: viewModel.draft.flair) { _, _ in viewModel.notifyDraftEdited() }
  66. }
  67. // MARK: - Header
  68. private var header: some View {
  69. VStack(spacing: 0) {
  70. HStack(spacing: 14) {
  71. ModernSidebarIconView(kind: .postGenerator, size: 40)
  72. VStack(alignment: .leading, spacing: 2) {
  73. HStack(spacing: 6) {
  74. Text("Post Generator")
  75. .font(.system(size: 18, weight: .semibold))
  76. .foregroundStyle(AppTheme.textPrimary)
  77. if viewModel.hasDraftChanges {
  78. Circle()
  79. .fill(AppTheme.accentOrange)
  80. .frame(width: 6, height: 6)
  81. .help("Draft has unsaved edits")
  82. }
  83. }
  84. Text(viewModel.generationEngineSubtitle)
  85. .font(.system(size: 11))
  86. .foregroundStyle(AppTheme.textSecondary)
  87. }
  88. Spacer()
  89. headerActions
  90. }
  91. .padding(.horizontal, Layout.horizontalPadding)
  92. .padding(.vertical, 16)
  93. FullWidthDivider()
  94. }
  95. }
  96. @ViewBuilder
  97. private var messageBanners: some View {
  98. if let error = viewModel.errorMessage {
  99. PostGeneratorMessageBanner(message: error, isError: true)
  100. .padding(.horizontal, Layout.horizontalPadding)
  101. .padding(.top, 8)
  102. } else if let success = viewModel.successMessage {
  103. PostGeneratorMessageBanner(message: success, isError: false)
  104. .padding(.horizontal, Layout.horizontalPadding)
  105. .padding(.top, 8)
  106. }
  107. }
  108. private var headerActions: some View {
  109. HStack(spacing: 8) {
  110. Button {
  111. viewModel.resetDraft()
  112. } label: {
  113. Label("Reset", systemImage: "arrow.counterclockwise")
  114. .font(.system(size: 11, weight: .medium))
  115. }
  116. .buttonStyle(AppSecondaryButtonStyle())
  117. Button {
  118. viewModel.copyToClipboard()
  119. } label: {
  120. Label("Copy", systemImage: "doc.on.doc")
  121. .font(.system(size: 11, weight: .medium))
  122. }
  123. .buttonStyle(AppSecondaryButtonStyle())
  124. .disabled(!viewModel.canExport)
  125. Button {
  126. Task { await viewModel.generatePost() }
  127. } label: {
  128. HStack(spacing: 6) {
  129. if viewModel.isGenerating {
  130. ProgressView()
  131. .controlSize(.small)
  132. .tint(.white)
  133. } else {
  134. Image(systemName: "sparkles")
  135. .font(.system(size: 11, weight: .semibold))
  136. }
  137. Text(viewModel.isGenerating ? "Generating…" : "Generate")
  138. .font(.system(size: 11, weight: .semibold))
  139. }
  140. .foregroundStyle(.white)
  141. .padding(.horizontal, 14)
  142. .padding(.vertical, 8)
  143. .background(viewModel.canGenerate ? AppTheme.accentPurple : AppTheme.accentPurple.opacity(0.4))
  144. .clipShape(RoundedRectangle(cornerRadius: 8))
  145. }
  146. .buttonStyle(AppPrimaryButtonStyle())
  147. .disabled(!viewModel.canGenerate)
  148. }
  149. }
  150. // MARK: - Tab Bar
  151. private var tabBar: some View {
  152. ToolSegmentedTabBar(
  153. selection: $viewModel.selectedTab,
  154. accentColor: AppTheme.accentPurple,
  155. width: 220
  156. )
  157. }
  158. // MARK: - Compose
  159. private var composeContent: some View {
  160. composeColumns
  161. }
  162. private var composeColumns: some View {
  163. HStack(alignment: .top, spacing: Layout.columnSpacing) {
  164. composeColumn(title: "Configuration", icon: "slider.horizontal.3") {
  165. configurationPanel
  166. }
  167. .frame(width: Layout.columnWidth)
  168. .layoutPriority(1)
  169. Rectangle()
  170. .fill(AppTheme.border)
  171. .frame(width: 1)
  172. .padding(.vertical, 2)
  173. composeColumn(title: "Post Content", icon: "doc.text") {
  174. editorPanel
  175. }
  176. .frame(minWidth: 0, maxWidth: .infinity)
  177. .layoutPriority(0)
  178. }
  179. }
  180. private func composeColumn<Content: View>(
  181. title: String,
  182. icon: String,
  183. @ViewBuilder content: () -> Content
  184. ) -> some View {
  185. VStack(alignment: .leading, spacing: Layout.sectionSpacing) {
  186. composeSectionHeader(title: title, icon: icon)
  187. content()
  188. }
  189. }
  190. private func composeSectionHeader(title: String, icon: String) -> some View {
  191. HStack(spacing: 6) {
  192. Image(systemName: icon)
  193. .font(.system(size: 10, weight: .semibold))
  194. .foregroundStyle(AppTheme.accentPurpleLight)
  195. Text(title)
  196. .font(.system(size: 11, weight: .semibold))
  197. .foregroundStyle(AppTheme.textSecondary)
  198. }
  199. .textCase(.uppercase)
  200. .tracking(0.4)
  201. }
  202. private var configurationPanel: some View {
  203. VStack(spacing: Layout.sectionSpacing) {
  204. PostFormCard(title: "Post Type", subtitle: "Choose how you want to post") {
  205. PostTypePicker(selectedType: Binding(
  206. get: { viewModel.draft.postType },
  207. set: { viewModel.selectPostType($0) }
  208. ))
  209. }
  210. PostFormCard(title: "Target Subreddit", subtitle: "Where will this be posted?") {
  211. VStack(alignment: .leading, spacing: 6) {
  212. PostFormField(
  213. label: "Subreddit",
  214. placeholder: "technology",
  215. text: $viewModel.draft.subreddit,
  216. prefix: "r/",
  217. isRequired: true
  218. )
  219. if !viewModel.draft.subreddit.isEmpty,
  220. !PostDraftValidator.isValidSubreddit(viewModel.draft.subreddit) {
  221. validationHint("Use 3–21 characters: letters, numbers, underscores only.")
  222. }
  223. }
  224. }
  225. PostFormCard(title: "AI Settings", subtitle: "Guide the tone and topic") {
  226. VStack(alignment: .leading, spacing: 12) {
  227. PostFormField(
  228. label: "Topic / Keywords",
  229. placeholder: "e.g. macOS productivity tips",
  230. text: $viewModel.draft.topic,
  231. isRequired: true
  232. )
  233. VStack(alignment: .leading, spacing: 6) {
  234. Text("Tone")
  235. .font(.system(size: 10, weight: .medium))
  236. .foregroundStyle(AppTheme.textTertiary)
  237. TonePicker(selectedTone: $viewModel.draft.tone)
  238. }
  239. }
  240. }
  241. PostFormCard(title: "Labels", subtitle: "Tags and optional flair") {
  242. VStack(alignment: .leading, spacing: 12) {
  243. HStack(spacing: 8) {
  244. PostTagToggle(
  245. title: "NSFW",
  246. systemImage: "exclamationmark.triangle.fill",
  247. activeColor: Color(hex: 0xEF4444),
  248. isOn: $viewModel.draft.isNSFW
  249. )
  250. .frame(maxWidth: .infinity)
  251. PostTagToggle(
  252. title: "Spoiler",
  253. systemImage: "eye.slash.fill",
  254. activeColor: AppTheme.textSecondary,
  255. isOn: $viewModel.draft.isSpoiler
  256. )
  257. .frame(maxWidth: .infinity)
  258. PostTagToggle(
  259. title: "OC",
  260. systemImage: "star.fill",
  261. activeColor: AppTheme.accentGreen,
  262. isOn: $viewModel.draft.isOC
  263. )
  264. .frame(maxWidth: .infinity)
  265. }
  266. PostFormField(
  267. label: "Flair",
  268. placeholder: "Discussion, Question, Meme…",
  269. text: $viewModel.draft.flair
  270. )
  271. }
  272. }
  273. }
  274. }
  275. private var editorPanel: some View {
  276. VStack(spacing: Layout.sectionSpacing) {
  277. PostFormCard(title: "Title", subtitle: "Filled by AI after generating, or write your own") {
  278. PostFormField(
  279. label: "Post Title",
  280. placeholder: "An engaging title for your post",
  281. text: $viewModel.draft.title
  282. )
  283. }
  284. postTypeEditor
  285. .frame(minHeight: 260, alignment: .top)
  286. characterCountFooter
  287. }
  288. }
  289. @ViewBuilder
  290. private var postTypeEditor: some View {
  291. switch viewModel.draft.postType {
  292. case .text:
  293. textPostEditor
  294. case .image:
  295. imagePostEditor
  296. case .link:
  297. linkPostEditor
  298. case .video:
  299. videoPostEditor
  300. case .poll:
  301. pollPostEditor
  302. }
  303. }
  304. private var textPostEditor: some View {
  305. PostFormCard(title: "Body", subtitle: "Markdown supported — **bold**, *italic*, links") {
  306. PostFormTextEditor(
  307. label: "Post Body",
  308. placeholder: "Write your post content here…",
  309. text: $viewModel.draft.body,
  310. minHeight: 220
  311. )
  312. }
  313. }
  314. private var imagePostEditor: some View {
  315. PostFormCard(title: "Image", subtitle: "Upload an image for your post") {
  316. VStack(alignment: .leading, spacing: 12) {
  317. imageUploadArea
  318. PostFormTextEditor(
  319. label: "Caption (optional)",
  320. placeholder: "Add context for your image…",
  321. text: $viewModel.draft.body,
  322. minHeight: 80
  323. )
  324. }
  325. }
  326. }
  327. private var linkPostEditor: some View {
  328. PostFormCard(title: "Link", subtitle: "Share a URL with the community") {
  329. VStack(alignment: .leading, spacing: 12) {
  330. PostFormField(
  331. label: "URL",
  332. placeholder: "https://example.com/article",
  333. text: $viewModel.draft.linkURL
  334. )
  335. if !viewModel.draft.linkURL.isEmpty,
  336. !PostDraftValidator.isValidHTTPURL(viewModel.draft.linkURL) {
  337. validationHint("Enter a valid http or https URL.")
  338. }
  339. PostFormTextEditor(
  340. label: "Description (optional)",
  341. placeholder: "Why are you sharing this link?",
  342. text: $viewModel.draft.body,
  343. minHeight: 100
  344. )
  345. }
  346. }
  347. }
  348. private var videoPostEditor: some View {
  349. PostFormCard(title: "Video", subtitle: "Link to YouTube, Vimeo, or direct video URL") {
  350. VStack(alignment: .leading, spacing: 12) {
  351. PostFormField(
  352. label: "Video URL",
  353. placeholder: "https://youtube.com/watch?v=…",
  354. text: $viewModel.draft.videoURL
  355. )
  356. if !viewModel.draft.videoURL.isEmpty,
  357. !PostDraftValidator.isValidHTTPURL(viewModel.draft.videoURL) {
  358. validationHint("Enter a valid http or https URL.")
  359. }
  360. PostFormTextEditor(
  361. label: "Description (optional)",
  362. placeholder: "Add context for your video…",
  363. text: $viewModel.draft.body,
  364. minHeight: 100
  365. )
  366. }
  367. }
  368. }
  369. private var pollPostEditor: some View {
  370. PostFormCard(title: "Poll", subtitle: "2–6 options, community votes") {
  371. VStack(alignment: .leading, spacing: 12) {
  372. ForEach(Array(viewModel.draft.pollOptions.enumerated()), id: \.element.id) { index, option in
  373. HStack(spacing: 8) {
  374. PostFormField(
  375. label: "Option \(index + 1)",
  376. placeholder: "Enter poll option",
  377. text: Binding(
  378. get: { option.text },
  379. set: { viewModel.updatePollOption(id: option.id, text: $0) }
  380. )
  381. )
  382. if viewModel.canRemovePollOption {
  383. Button {
  384. viewModel.removePollOption(option)
  385. } label: {
  386. Image(systemName: "minus.circle.fill")
  387. .font(.system(size: 14))
  388. .foregroundStyle(Color(hex: 0xEF4444).opacity(0.8))
  389. }
  390. .buttonStyle(AppPlainButtonStyle())
  391. .hoverOverlay(cornerRadius: 7)
  392. .padding(.top, 18)
  393. }
  394. }
  395. }
  396. if viewModel.canAddPollOption {
  397. Button {
  398. viewModel.addPollOption()
  399. } label: {
  400. Label("Add Option", systemImage: "plus.circle.fill")
  401. .font(.system(size: 11, weight: .medium))
  402. .foregroundStyle(AppTheme.accentPurpleLight)
  403. }
  404. .buttonStyle(AppPlainButtonStyle())
  405. .hoverOverlay(cornerRadius: 6)
  406. }
  407. VStack(alignment: .leading, spacing: 6) {
  408. Text("Poll Duration")
  409. .font(.system(size: 10, weight: .medium))
  410. .foregroundStyle(AppTheme.textTertiary)
  411. HStack(spacing: 8) {
  412. ForEach(PollDuration.allCases) { duration in
  413. Button {
  414. viewModel.draft.pollDuration = duration
  415. viewModel.notifyDraftEdited()
  416. } label: {
  417. Text(duration.label)
  418. .font(.system(size: 10, weight: .semibold))
  419. .foregroundStyle(
  420. viewModel.draft.pollDuration == duration ? .white : AppTheme.textSecondary
  421. )
  422. .frame(maxWidth: .infinity)
  423. .padding(.vertical, 7)
  424. .background(
  425. RoundedRectangle(cornerRadius: 7)
  426. .fill(
  427. viewModel.draft.pollDuration == duration
  428. ? AppTheme.accentPurple
  429. : AppTheme.panelBackground
  430. )
  431. )
  432. .overlay(
  433. RoundedRectangle(cornerRadius: 7)
  434. .stroke(AppTheme.cardBorder, lineWidth: 1)
  435. )
  436. }
  437. .buttonStyle(AppPlainButtonStyle())
  438. .hoverOverlay(cornerRadius: 7)
  439. }
  440. }
  441. }
  442. PostFormTextEditor(
  443. label: "Context (optional)",
  444. placeholder: "Explain why you're running this poll…",
  445. text: $viewModel.draft.body,
  446. minHeight: 80
  447. )
  448. }
  449. }
  450. }
  451. @ViewBuilder
  452. private var imageUploadArea: some View {
  453. Group {
  454. if let url = viewModel.draft.imageFileURL, let nsImage = NSImage(contentsOf: url) {
  455. ZStack(alignment: .topTrailing) {
  456. Image(nsImage: nsImage)
  457. .resizable()
  458. .scaledToFit()
  459. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  460. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  461. .clipped()
  462. Button {
  463. viewModel.removeImage()
  464. } label: {
  465. Image(systemName: "xmark.circle.fill")
  466. .font(.system(size: 18))
  467. .foregroundStyle(.white)
  468. .shadow(radius: 2)
  469. }
  470. .buttonStyle(AppPlainButtonStyle())
  471. .hoverOverlay(cornerRadius: 8)
  472. .padding(8)
  473. }
  474. } else {
  475. Button {
  476. viewModel.showImageImporter = true
  477. } label: {
  478. VStack(spacing: 8) {
  479. Image(systemName: "photo.badge.plus")
  480. .font(.system(size: 24))
  481. .foregroundStyle(AppTheme.accentPurpleLight)
  482. Text("Click to upload image")
  483. .font(.system(size: 11, weight: .medium))
  484. .foregroundStyle(AppTheme.textSecondary)
  485. Text("PNG, JPG, GIF, WebP")
  486. .font(.system(size: 9))
  487. .foregroundStyle(AppTheme.textTertiary)
  488. }
  489. .frame(maxWidth: .infinity, maxHeight: .infinity)
  490. .background(AppTheme.panelBackground)
  491. .clipShape(RoundedRectangle(cornerRadius: 8))
  492. .overlay(
  493. RoundedRectangle(cornerRadius: 8)
  494. .strokeBorder(
  495. AppTheme.accentPurple.opacity(0.3),
  496. style: StrokeStyle(lineWidth: 1, dash: [6, 4])
  497. )
  498. )
  499. }
  500. .buttonStyle(AppPlainButtonStyle())
  501. .hoverCard(cornerRadius: 8)
  502. }
  503. }
  504. .frame(maxWidth: .infinity)
  505. .frame(height: Layout.imageUploadHeight)
  506. .clipShape(RoundedRectangle(cornerRadius: 8))
  507. }
  508. private var characterCountFooter: some View {
  509. HStack(spacing: 12) {
  510. Text(titleCharacterCount)
  511. .font(.system(size: 10, weight: .medium, design: .monospaced))
  512. .foregroundStyle(
  513. viewModel.draft.title.count > PostDraftValidator.maxTitleLength
  514. ? Color(hex: 0xF87171)
  515. : AppTheme.textTertiary
  516. )
  517. if !viewModel.draft.body.isEmpty {
  518. Text("·")
  519. .foregroundStyle(AppTheme.textTertiary)
  520. Text(bodyCharacterCount)
  521. .font(.system(size: 10, weight: .medium, design: .monospaced))
  522. .foregroundStyle(
  523. viewModel.draft.body.count > PostDraftValidator.maxBodyLength
  524. ? Color(hex: 0xF87171)
  525. : AppTheme.textTertiary
  526. )
  527. }
  528. Spacer()
  529. Text("Reddit limits: 300 title · 40,000 body")
  530. .font(.system(size: 10))
  531. .foregroundStyle(AppTheme.textTertiary)
  532. }
  533. .padding(.horizontal, 12)
  534. .padding(.vertical, 9)
  535. .background(
  536. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  537. .fill(AppTheme.cardBackground)
  538. .overlay(
  539. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  540. .stroke(AppTheme.cardBorder, lineWidth: 1)
  541. )
  542. )
  543. }
  544. private var titleCharacterCount: String {
  545. "\(viewModel.draft.title.count) / \(PostDraftValidator.maxTitleLength) title"
  546. }
  547. private var bodyCharacterCount: String {
  548. "\(viewModel.draft.body.count) / \(PostDraftValidator.maxBodyLength) body"
  549. }
  550. // MARK: - Preview
  551. private var previewContent: some View {
  552. VStack(alignment: .leading, spacing: Layout.columnSpacing) {
  553. composeSectionHeader(title: "Live Preview", icon: "eye")
  554. HStack {
  555. Spacer(minLength: 0)
  556. VStack(spacing: Layout.sectionSpacing) {
  557. RedditPostPreviewCard(
  558. draft: viewModel.draft,
  559. formattedSubreddit: viewModel.formattedSubreddit
  560. )
  561. previewMetadata
  562. }
  563. .frame(maxWidth: 560)
  564. Spacer(minLength: 0)
  565. }
  566. }
  567. }
  568. private var previewMetadata: some View {
  569. VStack(alignment: .leading, spacing: 0) {
  570. metadataRow(label: "Type", value: viewModel.draft.postType.title)
  571. metadataDivider
  572. metadataRow(label: "Subreddit", value: viewModel.formattedSubreddit)
  573. metadataDivider
  574. metadataRow(label: "Tone", value: viewModel.draft.tone.title)
  575. metadataDivider
  576. metadataRow(label: "Engine", value: viewModel.usesLiveAI ? "AI" : "Local templates")
  577. if viewModel.draft.isNSFW || viewModel.draft.isSpoiler || viewModel.draft.isOC {
  578. metadataDivider
  579. metadataRow(
  580. label: "Tags",
  581. value: [
  582. viewModel.draft.isNSFW ? "NSFW" : nil,
  583. viewModel.draft.isSpoiler ? "Spoiler" : nil,
  584. viewModel.draft.isOC ? "OC" : nil,
  585. ]
  586. .compactMap { $0 }
  587. .joined(separator: ", ")
  588. )
  589. }
  590. }
  591. .padding(14)
  592. .frame(maxWidth: .infinity, alignment: .leading)
  593. .background(
  594. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  595. .fill(AppTheme.cardBackground)
  596. .overlay(
  597. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  598. .stroke(AppTheme.cardBorder, lineWidth: 1)
  599. )
  600. )
  601. }
  602. private var metadataDivider: some View {
  603. Rectangle()
  604. .fill(AppTheme.border)
  605. .frame(height: 1)
  606. .padding(.vertical, 6)
  607. }
  608. private func metadataRow(label: String, value: String) -> some View {
  609. HStack(alignment: .top, spacing: 12) {
  610. Text(label)
  611. .font(.system(size: 10, weight: .medium))
  612. .foregroundStyle(AppTheme.textTertiary)
  613. .frame(width: 72, alignment: .leading)
  614. Text(value)
  615. .font(.system(size: 10))
  616. .foregroundStyle(AppTheme.textSecondary)
  617. .fixedSize(horizontal: false, vertical: true)
  618. }
  619. }
  620. private func validationHint(_ message: String) -> some View {
  621. HStack(spacing: 4) {
  622. Image(systemName: "exclamationmark.circle.fill")
  623. .font(.system(size: 9))
  624. Text(message)
  625. .font(.system(size: 9))
  626. }
  627. .foregroundStyle(Color(hex: 0xF87171))
  628. }
  629. }
  630. private struct PostSecondaryButtonStyle: ButtonStyle {
  631. func makeBody(configuration: Configuration) -> some View {
  632. AppSecondaryButtonStyle().makeBody(configuration: configuration)
  633. }
  634. }
  635. #Preview {
  636. PostGeneratorView(viewModel: PostGeneratorViewModel())
  637. .frame(width: 880, height: 720)
  638. }