PostGeneratorView.swift 27 KB

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