import { useEffect, useState } from 'react' import { Link, useParams } from 'react-router-dom' import { CalendarDays, User } from 'lucide-react' import { useLocale } from '@meshkee/dashboard-ui' import { Breadcrumbs } from '../components/Breadcrumbs' import { InstructionCommentsSection } from '../components/InstructionCommentsSection' import { useT } from '../i18n/useT' import { ApiError } from '../lib/api' import { formatInstructionAuthor, formatInstructionDate, getInstructionDetail, resolveInstructionTitle, } from '../services/instructionService' import type { InstructionDetail } from '../types/instruction' import { textLocaleAttrs } from '../utils/textLocale' import pageStyles from '../components/PageContent.module.css' import styles from './BlogDetailsPage.module.css' export function InstructionDetailsPage() { const t = useT() const { locale } = useLocale() const { id } = useParams() const [video, setInstruction] = useState(null) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState('') useEffect(() => { if (!id) return const controller = new AbortController() async function loadVideo() { setIsLoading(true) setError('') try { const data = await getInstructionDetail(id!, controller.signal) setInstruction(data) } catch (err) { if (err instanceof DOMException && err.name === 'AbortError') return if (err instanceof ApiError) { setError(err.message) } else { setError(t('instruction.details.errorLoad')) } setInstruction(null) } finally { setIsLoading(false) } } void loadVideo() return () => controller.abort() }, [id]) if (isLoading) { return (

{t('instruction.details.loading')}

) } if (error || !video || !id) { return (

{error || t('instruction.details.notFound')}

{t('instruction.details.back')}
) } const displayTitle = resolveInstructionTitle(video, locale === 'fa' ? 'fa' : 'en') const displayDate = formatInstructionDate( video.publishedAt ?? video.createdAt, locale === 'fa' ? 'fa' : 'en', ) const titleLocale = textLocaleAttrs(displayTitle) const abstractLocale = textLocaleAttrs(video.abstract) const contentLocale = textLocaleAttrs( video.descriptionHtml?.replace(/<[^>]+>/g, ' ') ?? '', ) const providerLabel = video.videoProvider === 'youtube' ? 'YouTube' : 'Aparat' return (

{displayTitle}

{video.abstract ? (

{video.abstract}

) : null}
{video.coverImageUrl ? ( {displayTitle} ) : (
{displayDate} {(providerLabel || video.categoryName) && ( <> ยท
{providerLabel && ( {providerLabel} )} {video.categoryName && ( {video.categoryName} )}
)}
{video.embedCode ? (
) : null}
{video.descriptionHtml ? (
) : (

{t('instruction.details.noDescription')}

)}
{t('instruction.details.author')} {formatInstructionAuthor(video.author)}
) }