PostGeneratorView.swift 27 KB

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