PostGeneratorView.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. )
  218. if !viewModel.draft.subreddit.isEmpty,
  219. !PostDraftValidator.isValidSubreddit(viewModel.draft.subreddit) {
  220. validationHint("Use 3–21 characters: letters, numbers, underscores only.")
  221. }
  222. }
  223. }
  224. PostFormCard(title: "AI Settings", subtitle: "Guide the tone and topic") {
  225. VStack(alignment: .leading, spacing: 12) {
  226. PostFormField(
  227. label: "Topic / Keywords",
  228. placeholder: "e.g. macOS productivity tips",
  229. text: $viewModel.draft.topic
  230. )
  231. VStack(alignment: .leading, spacing: 6) {
  232. Text("Tone")
  233. .font(.system(size: 10, weight: .medium))
  234. .foregroundStyle(AppTheme.textTertiary)
  235. TonePicker(selectedTone: $viewModel.draft.tone)
  236. }
  237. }
  238. }
  239. PostFormCard(title: "Labels", subtitle: "Tags and optional flair") {
  240. VStack(alignment: .leading, spacing: 12) {
  241. HStack(spacing: 8) {
  242. PostTagToggle(
  243. title: "NSFW",
  244. systemImage: "exclamationmark.triangle.fill",
  245. activeColor: Color(hex: 0xEF4444),
  246. isOn: $viewModel.draft.isNSFW
  247. )
  248. .frame(maxWidth: .infinity)
  249. PostTagToggle(
  250. title: "Spoiler",
  251. systemImage: "eye.slash.fill",
  252. activeColor: AppTheme.textSecondary,
  253. isOn: $viewModel.draft.isSpoiler
  254. )
  255. .frame(maxWidth: .infinity)
  256. PostTagToggle(
  257. title: "OC",
  258. systemImage: "star.fill",
  259. activeColor: AppTheme.accentGreen,
  260. isOn: $viewModel.draft.isOC
  261. )
  262. .frame(maxWidth: .infinity)
  263. }
  264. PostFormField(
  265. label: "Flair",
  266. placeholder: "Discussion, Question, Meme…",
  267. text: $viewModel.draft.flair
  268. )
  269. }
  270. }
  271. }
  272. }
  273. private var editorPanel: some View {
  274. VStack(spacing: Layout.sectionSpacing) {
  275. PostFormCard(title: "Title", subtitle: "Required for all post types") {
  276. PostFormField(
  277. label: "Post Title",
  278. placeholder: "An engaging title for your post",
  279. text: $viewModel.draft.title
  280. )
  281. }
  282. postTypeEditor
  283. .frame(minHeight: 260, alignment: .top)
  284. characterCountFooter
  285. }
  286. }
  287. @ViewBuilder
  288. private var postTypeEditor: some View {
  289. switch viewModel.draft.postType {
  290. case .text:
  291. textPostEditor
  292. case .image:
  293. imagePostEditor
  294. case .link:
  295. linkPostEditor
  296. case .video:
  297. videoPostEditor
  298. case .poll:
  299. pollPostEditor
  300. }
  301. }
  302. private var textPostEditor: some View {
  303. PostFormCard(title: "Body", subtitle: "Markdown supported — **bold**, *italic*, links") {
  304. PostFormTextEditor(
  305. label: "Post Body",
  306. placeholder: "Write your post content here…",
  307. text: $viewModel.draft.body,
  308. minHeight: 220
  309. )
  310. }
  311. }
  312. private var imagePostEditor: some View {
  313. PostFormCard(title: "Image", subtitle: "Upload an image for your post") {
  314. VStack(alignment: .leading, spacing: 12) {
  315. imageUploadArea
  316. PostFormTextEditor(
  317. label: "Caption (optional)",
  318. placeholder: "Add context for your image…",
  319. text: $viewModel.draft.body,
  320. minHeight: 80
  321. )
  322. }
  323. }
  324. }
  325. private var linkPostEditor: some View {
  326. PostFormCard(title: "Link", subtitle: "Share a URL with the community") {
  327. VStack(alignment: .leading, spacing: 12) {
  328. PostFormField(
  329. label: "URL",
  330. placeholder: "https://example.com/article",
  331. text: $viewModel.draft.linkURL
  332. )
  333. if !viewModel.draft.linkURL.isEmpty,
  334. !PostDraftValidator.isValidHTTPURL(viewModel.draft.linkURL) {
  335. validationHint("Enter a valid http or https URL.")
  336. }
  337. PostFormTextEditor(
  338. label: "Description (optional)",
  339. placeholder: "Why are you sharing this link?",
  340. text: $viewModel.draft.body,
  341. minHeight: 100
  342. )
  343. }
  344. }
  345. }
  346. private var videoPostEditor: some View {
  347. PostFormCard(title: "Video", subtitle: "Link to YouTube, Vimeo, or direct video URL") {
  348. VStack(alignment: .leading, spacing: 12) {
  349. PostFormField(
  350. label: "Video URL",
  351. placeholder: "https://youtube.com/watch?v=…",
  352. text: $viewModel.draft.videoURL
  353. )
  354. if !viewModel.draft.videoURL.isEmpty,
  355. !PostDraftValidator.isValidHTTPURL(viewModel.draft.videoURL) {
  356. validationHint("Enter a valid http or https URL.")
  357. }
  358. PostFormTextEditor(
  359. label: "Description (optional)",
  360. placeholder: "Add context for your video…",
  361. text: $viewModel.draft.body,
  362. minHeight: 100
  363. )
  364. }
  365. }
  366. }
  367. private var pollPostEditor: some View {
  368. PostFormCard(title: "Poll", subtitle: "2–6 options, community votes") {
  369. VStack(alignment: .leading, spacing: 12) {
  370. ForEach(Array(viewModel.draft.pollOptions.enumerated()), id: \.element.id) { index, option in
  371. HStack(spacing: 8) {
  372. PostFormField(
  373. label: "Option \(index + 1)",
  374. placeholder: "Enter poll option",
  375. text: Binding(
  376. get: { option.text },
  377. set: { viewModel.updatePollOption(id: option.id, text: $0) }
  378. )
  379. )
  380. if viewModel.canRemovePollOption {
  381. Button {
  382. viewModel.removePollOption(option)
  383. } label: {
  384. Image(systemName: "minus.circle.fill")
  385. .font(.system(size: 14))
  386. .foregroundStyle(Color(hex: 0xEF4444).opacity(0.8))
  387. }
  388. .buttonStyle(AppPlainButtonStyle())
  389. .hoverOverlay(cornerRadius: 7)
  390. .padding(.top, 18)
  391. }
  392. }
  393. }
  394. if viewModel.canAddPollOption {
  395. Button {
  396. viewModel.addPollOption()
  397. } label: {
  398. Label("Add Option", systemImage: "plus.circle.fill")
  399. .font(.system(size: 11, weight: .medium))
  400. .foregroundStyle(AppTheme.accentPurpleLight)
  401. }
  402. .buttonStyle(AppPlainButtonStyle())
  403. .hoverOverlay(cornerRadius: 6)
  404. }
  405. VStack(alignment: .leading, spacing: 6) {
  406. Text("Poll Duration")
  407. .font(.system(size: 10, weight: .medium))
  408. .foregroundStyle(AppTheme.textTertiary)
  409. HStack(spacing: 8) {
  410. ForEach(PollDuration.allCases) { duration in
  411. Button {
  412. viewModel.draft.pollDuration = duration
  413. viewModel.notifyDraftEdited()
  414. } label: {
  415. Text(duration.label)
  416. .font(.system(size: 10, weight: .semibold))
  417. .foregroundStyle(
  418. viewModel.draft.pollDuration == duration ? .white : AppTheme.textSecondary
  419. )
  420. .frame(maxWidth: .infinity)
  421. .padding(.vertical, 7)
  422. .background(
  423. RoundedRectangle(cornerRadius: 7)
  424. .fill(
  425. viewModel.draft.pollDuration == duration
  426. ? AppTheme.accentPurple
  427. : AppTheme.panelBackground
  428. )
  429. )
  430. .overlay(
  431. RoundedRectangle(cornerRadius: 7)
  432. .stroke(AppTheme.cardBorder, lineWidth: 1)
  433. )
  434. }
  435. .buttonStyle(AppPlainButtonStyle())
  436. .hoverOverlay(cornerRadius: 7)
  437. }
  438. }
  439. }
  440. PostFormTextEditor(
  441. label: "Context (optional)",
  442. placeholder: "Explain why you're running this poll…",
  443. text: $viewModel.draft.body,
  444. minHeight: 80
  445. )
  446. }
  447. }
  448. }
  449. @ViewBuilder
  450. private var imageUploadArea: some View {
  451. Group {
  452. if let url = viewModel.draft.imageFileURL, let nsImage = NSImage(contentsOf: url) {
  453. ZStack(alignment: .topTrailing) {
  454. Image(nsImage: nsImage)
  455. .resizable()
  456. .scaledToFit()
  457. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  458. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  459. .clipped()
  460. Button {
  461. viewModel.removeImage()
  462. } label: {
  463. Image(systemName: "xmark.circle.fill")
  464. .font(.system(size: 18))
  465. .foregroundStyle(.white)
  466. .shadow(radius: 2)
  467. }
  468. .buttonStyle(AppPlainButtonStyle())
  469. .hoverOverlay(cornerRadius: 8)
  470. .padding(8)
  471. }
  472. } else {
  473. Button {
  474. viewModel.showImageImporter = true
  475. } label: {
  476. VStack(spacing: 8) {
  477. Image(systemName: "photo.badge.plus")
  478. .font(.system(size: 24))
  479. .foregroundStyle(AppTheme.accentPurpleLight)
  480. Text("Click to upload image")
  481. .font(.system(size: 11, weight: .medium))
  482. .foregroundStyle(AppTheme.textSecondary)
  483. Text("PNG, JPG, GIF, WebP")
  484. .font(.system(size: 9))
  485. .foregroundStyle(AppTheme.textTertiary)
  486. }
  487. .frame(maxWidth: .infinity, maxHeight: .infinity)
  488. .background(AppTheme.panelBackground)
  489. .clipShape(RoundedRectangle(cornerRadius: 8))
  490. .overlay(
  491. RoundedRectangle(cornerRadius: 8)
  492. .strokeBorder(
  493. AppTheme.accentPurple.opacity(0.3),
  494. style: StrokeStyle(lineWidth: 1, dash: [6, 4])
  495. )
  496. )
  497. }
  498. .buttonStyle(AppPlainButtonStyle())
  499. .hoverCard(cornerRadius: 8)
  500. }
  501. }
  502. .frame(maxWidth: .infinity)
  503. .frame(height: Layout.imageUploadHeight)
  504. .clipShape(RoundedRectangle(cornerRadius: 8))
  505. }
  506. private var characterCountFooter: some View {
  507. HStack(spacing: 12) {
  508. Text(titleCharacterCount)
  509. .font(.system(size: 10, weight: .medium, design: .monospaced))
  510. .foregroundStyle(
  511. viewModel.draft.title.count > PostDraftValidator.maxTitleLength
  512. ? Color(hex: 0xF87171)
  513. : AppTheme.textTertiary
  514. )
  515. if !viewModel.draft.body.isEmpty {
  516. Text("·")
  517. .foregroundStyle(AppTheme.textTertiary)
  518. Text(bodyCharacterCount)
  519. .font(.system(size: 10, weight: .medium, design: .monospaced))
  520. .foregroundStyle(
  521. viewModel.draft.body.count > PostDraftValidator.maxBodyLength
  522. ? Color(hex: 0xF87171)
  523. : AppTheme.textTertiary
  524. )
  525. }
  526. Spacer()
  527. Text("Reddit limits: 300 title · 40,000 body")
  528. .font(.system(size: 10))
  529. .foregroundStyle(AppTheme.textTertiary)
  530. }
  531. .padding(.horizontal, 12)
  532. .padding(.vertical, 9)
  533. .background(
  534. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  535. .fill(AppTheme.cardBackground)
  536. .overlay(
  537. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  538. .stroke(AppTheme.cardBorder, lineWidth: 1)
  539. )
  540. )
  541. }
  542. private var titleCharacterCount: String {
  543. "\(viewModel.draft.title.count) / \(PostDraftValidator.maxTitleLength) title"
  544. }
  545. private var bodyCharacterCount: String {
  546. "\(viewModel.draft.body.count) / \(PostDraftValidator.maxBodyLength) body"
  547. }
  548. // MARK: - Preview
  549. private var previewContent: some View {
  550. VStack(alignment: .leading, spacing: Layout.columnSpacing) {
  551. composeSectionHeader(title: "Live Preview", icon: "eye")
  552. HStack {
  553. Spacer(minLength: 0)
  554. VStack(spacing: Layout.sectionSpacing) {
  555. RedditPostPreviewCard(
  556. draft: viewModel.draft,
  557. formattedSubreddit: viewModel.formattedSubreddit
  558. )
  559. previewMetadata
  560. }
  561. .frame(maxWidth: 560)
  562. Spacer(minLength: 0)
  563. }
  564. }
  565. }
  566. private var previewMetadata: some View {
  567. VStack(alignment: .leading, spacing: 0) {
  568. metadataRow(label: "Type", value: viewModel.draft.postType.title)
  569. metadataDivider
  570. metadataRow(label: "Subreddit", value: viewModel.formattedSubreddit)
  571. metadataDivider
  572. metadataRow(label: "Tone", value: viewModel.draft.tone.title)
  573. metadataDivider
  574. metadataRow(label: "Engine", value: viewModel.usesLiveAI ? "AI" : "Local templates")
  575. if viewModel.draft.isNSFW || viewModel.draft.isSpoiler || viewModel.draft.isOC {
  576. metadataDivider
  577. metadataRow(
  578. label: "Tags",
  579. value: [
  580. viewModel.draft.isNSFW ? "NSFW" : nil,
  581. viewModel.draft.isSpoiler ? "Spoiler" : nil,
  582. viewModel.draft.isOC ? "OC" : nil,
  583. ]
  584. .compactMap { $0 }
  585. .joined(separator: ", ")
  586. )
  587. }
  588. }
  589. .padding(14)
  590. .frame(maxWidth: .infinity, alignment: .leading)
  591. .background(
  592. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  593. .fill(AppTheme.cardBackground)
  594. .overlay(
  595. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  596. .stroke(AppTheme.cardBorder, lineWidth: 1)
  597. )
  598. )
  599. }
  600. private var metadataDivider: some View {
  601. Rectangle()
  602. .fill(AppTheme.border)
  603. .frame(height: 1)
  604. .padding(.vertical, 6)
  605. }
  606. private func metadataRow(label: String, value: String) -> some View {
  607. HStack(alignment: .top, spacing: 12) {
  608. Text(label)
  609. .font(.system(size: 10, weight: .medium))
  610. .foregroundStyle(AppTheme.textTertiary)
  611. .frame(width: 72, alignment: .leading)
  612. Text(value)
  613. .font(.system(size: 10))
  614. .foregroundStyle(AppTheme.textSecondary)
  615. .fixedSize(horizontal: false, vertical: true)
  616. }
  617. }
  618. private func validationHint(_ message: String) -> some View {
  619. HStack(spacing: 4) {
  620. Image(systemName: "exclamationmark.circle.fill")
  621. .font(.system(size: 9))
  622. Text(message)
  623. .font(.system(size: 9))
  624. }
  625. .foregroundStyle(Color(hex: 0xF87171))
  626. }
  627. }
  628. private struct PostSecondaryButtonStyle: ButtonStyle {
  629. func makeBody(configuration: Configuration) -> some View {
  630. AppSecondaryButtonStyle().makeBody(configuration: configuration)
  631. }
  632. }
  633. #Preview {
  634. PostGeneratorView(viewModel: PostGeneratorViewModel())
  635. .frame(width: 880, height: 720)
  636. }