Files
canina/frontend/admin-panel/src/pages/UITexts.tsx
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

1287 lines
63 KiB
TypeScript

import {
Award,
BookOpen,
Building2,
Check,
ChevronDown,
CreditCard,
Eye,
FileText,
Globe,
Heart,
HelpCircle,
Home,
Languages,
Layout,
Link as LinkIcon,
Monitor,
PhoneCall,
Pill,
Save,
Search,
Shield,
ShieldCheck,
ShoppingBag,
Sliders,
Smartphone,
Sparkles,
Truck,
Upload,
User,
Video
} from 'lucide-react';
import React,{ useEffect,useState } from 'react';
import { toast } from 'react-hot-toast';
import { useSearchParams } from 'react-router-dom';
import Button from '../components/ui/Button';
import IconPickerModal,{ ICON_REGISTRY } from '../components/ui/IconPickerModal';
import ImagePreviewModal from '../components/ui/ImagePreviewModal';
import MediaSelector from '../components/ui/MediaSelector';
import RichTextEditor from '../components/ui/RichTextEditor';
import Spinner from '../components/ui/Spinner';
import ToggleSwitch from '../components/ui/ToggleSwitch';
import api,{ BASE_DOMAIN } from '../services/api';
// Structured Page Builder Definitions
interface SectionField {
key: string;
label: string;
type: 'rich-text' | 'text' | 'image' | 'icon' | 'boolean' | 'textarea';
description?: string;
defaultVal?: string;
}
interface PageSection {
id: string;
title: string;
icon: React.ComponentType<{ className?: string }>;
isSeo?: boolean;
fields: SectionField[];
}
interface AppSitePage {
id: string;
title: string;
path: string;
icon: React.ComponentType<{ className?: string }>;
sections: PageSection[];
}
// Generate Standard SEO Section Fields for any Page
const createSeoSection = (pagePrefix: string, pageNameFa: string, defaultMetaTitle: string, defaultMetaDesc: string): PageSection => ({
id: 'seo',
title: 'تنظیمات سئو و پیش‌نمایش گوگل (Google SERP)',
icon: Globe,
isSeo: true,
fields: [
{
key: `${pagePrefix}_meta_title`,
label: `عنوان صفحه در گوگل (Meta Title) - ${pageNameFa}`,
type: 'text',
description: 'حداکثر ۶۰ کاراکتر - عنوانی که در تب مرورگر و عنوان آبی‌رنگ گوگل ظاهر می‌شود.',
defaultVal: defaultMetaTitle,
},
{
key: `${pagePrefix}_meta_desc`,
label: `توضیحات متا (Meta Description) - ${pageNameFa}`,
type: 'textarea',
description: 'حداکثر ۱۵۵ کاراکتر - چکیده محتوای صفحه برای ترغیب کلیک در نتایج جستجو.',
defaultVal: defaultMetaDesc,
},
{
key: `${pagePrefix}_keywords`,
label: 'کلمات کلیدی سئو (Keywords)',
type: 'text',
description: 'کلمات کلیدی مرتبط که با کاما (,) از یکدیگر تفکیک شده‌اند.',
defaultVal: 'کنینا, مکمل تخصصی سگ و گربه, داروی پت, کنینا آلمان',
},
{
key: `${pagePrefix}_canonical`,
label: 'آدرس کانونیکال اختصاصی (Canonical URL)',
type: 'text',
description: 'آدرس اصلی این صفحه جهت جلوگیری از خطای Duplicate Content در موتورهای جستجو.',
},
],
});
// Full Application Pages Registry (All 15 routes from frontend/application/app)
const SITE_PAGES: AppSitePage[] = [
{
id: 'home',
title: 'صفحه اصلی (Home Page)',
path: '/',
icon: Home,
sections: [
createSeoSection('home', 'صفحه اصلی', 'کنینا ایران | نماینده رسمی مکمل‌های دارویی Canina آلمان', 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های درمانی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی.'),
{
id: 'hero',
title: 'بنر اصلی (Hero Banner)',
icon: Sliders,
fields: [
{ key: 'hero_badge', label: 'بج بالای تیتر بنر', type: 'text' },
{ key: 'hero_title', label: 'عنوان اصلی بنر (H1 سئو)', type: 'rich-text', description: 'تگ‌های H1 یا رنگ کلمات کلیدی را مشخص کنید' },
{ key: 'hero_desc', label: 'متن توضیحات بنر', type: 'rich-text' },
{ key: 'hero_btn_advisor', label: 'متن دکمه دستیار سلامت', type: 'text' },
{ key: 'hero_btn_products', label: 'متن دکمه کاتالوگ محصولات', type: 'text' },
{ key: 'hero_image_url', label: 'تصویر پس‌زمینه یا گرافیک بنر اصلی', type: 'image' },
{ key: 'hero_image_title', label: 'متن روی کارت تصویر', type: 'text' },
{ key: 'hero_image_badge', label: 'بج روی کارت تصویر', type: 'text' },
{ key: 'hero_icon_badge', label: 'آیکون بج بنر', type: 'icon' },
{ key: 'hero_stat_founded', label: 'آمار قدمت کنینا (سال تأسیس)', type: 'text' },
{ key: 'hero_stat_agencies', label: 'آمار نمایندگی‌ها', type: 'text' },
{ key: 'hero_stat_german_formula', label: 'آمار فرمولاسیون آلمانی', type: 'text' },
],
},
{
id: 'smart_advisor',
title: 'مشاور و تجویز هوشمند (Smart Advisor)',
icon: Sparkles,
fields: [
{ key: 'advisor_badge', label: 'بج بالای بخش مشاور', type: 'text' },
{ key: 'advisor_title', label: 'عنوان اصلی مشاور سلامت (H2)', type: 'rich-text' },
{ key: 'advisor_subtitle', label: 'متن توضیحات راهنمای ۴ قدمه', type: 'rich-text' },
{ key: 'advisor_card1_title', label: 'عنوان کارت ۱ (چرا ثبت شناسنامه؟)', type: 'text' },
{ key: 'advisor_card1_desc', label: 'متن کارت ۱ (دوز دقیق و فرمول غلیظ)', type: 'rich-text' },
{ key: 'advisor_card1_footer', label: 'برچسب پایین کارت ۱', type: 'text' },
{ key: 'advisor_card2_title', label: 'عنوان کارت ۲ (تطبیق علائم بالینی)', type: 'text' },
{ key: 'advisor_card2_desc', label: 'متن کارت ۲ (تطبیق علائم مثل لنگیدن و ریزش مو)', type: 'rich-text' },
{ key: 'advisor_card2_footer', label: 'برچسب پایین کارت ۲', type: 'text' },
{ key: 'advisor_card3_title', label: 'عنوان کارت ۳ (پایش موجودی و یادآور)', type: 'text' },
{ key: 'advisor_card3_desc', label: 'متن کارت ۳ (تنظیم زمان مصرف و هشدار شارژ)', type: 'rich-text' },
{ key: 'advisor_card3_footer', label: 'برچسب پایین کارت ۳', type: 'text' },
],
},
{
id: 'featured',
title: 'محصولات برگزیده (Featured Products)',
icon: ShoppingBag,
fields: [
{ key: 'featured_badge', label: 'بج بالای سکشن', type: 'text' },
{ key: 'featured_title_line1', label: 'عنوان سطر اول محصولات برگزیده (H2)', type: 'rich-text' },
{ key: 'featured_title_line2', label: 'عنوان سطر دوم محصولات برگزیده', type: 'rich-text' },
{ key: 'featured_desc', label: 'توضیحات معرفی مکمل‌ها', type: 'rich-text' },
{ key: 'featured_view_all', label: 'متن دکمه مشاهده همه محصولات', type: 'text' },
{ key: 'featured_no_products_title', label: 'عنوان در صورت عدم وجود محصول', type: 'text' },
{ key: 'featured_no_products_desc', label: 'متن توضیح عدم وجود محصول', type: 'text' },
],
},
{
id: 'nav_cards',
title: 'کارت‌های ناوبری سریع (Navigation Cards)',
icon: Layout,
fields: [
{ key: 'nav_card_shop_title', label: 'عنوان کارت فروشگاه', type: 'text' },
{ key: 'nav_card_shop_desc', label: 'توضیح کارت فروشگاه', type: 'text' },
{ key: 'nav_card_shop_cta', label: 'دکمه اقدام کارت فروشگاه', type: 'text' },
{ key: 'nav_card_wiki_title', label: 'عنوان کارت دانشنامه', type: 'text' },
{ key: 'nav_card_wiki_desc', label: 'توضیح کارت دانشنامه', type: 'text' },
{ key: 'nav_card_wiki_cta', label: 'دکمه اقدام کارت دانشنامه', type: 'text' },
],
},
{
id: 'videos',
title: 'ویدئوها و آموزش‌ها (Videos Showcase)',
icon: Video,
fields: [
{ key: 'videos_badge', label: 'بج بالای بخش ویدئوها', type: 'text' },
{ key: 'videos_title', label: 'عنوان بخش ویدئوها (H2)', type: 'rich-text' },
{ key: 'videos_title_highlight', label: 'متن هایلایت‌شده عنوان ویدئو', type: 'text' },
{ key: 'videos_desc', label: 'توضیحات کوتاه بخش ویدئوها', type: 'rich-text' },
{ key: 'videos_view_all', label: 'متن دکمه مشاهده همه ویدئوها', type: 'text' },
],
},
{
id: 'about',
title: 'درباره اصالت و کیفیت (About & Standards)',
icon: Award,
fields: [
{ key: 'about_label', label: 'برچسب بالای بخش', type: 'text' },
{ key: 'about_title', label: 'عنوان اصلی درباره کنینا', type: 'rich-text' },
{ key: 'about_image_url', label: 'تصویر آزمایشگاه و معرفی برند', type: 'image' },
{ key: 'about_image_alt', label: 'متن جایگزین (Alt) تصویر درباره برند', type: 'text' },
{ key: 'about_badge_title', label: 'عنوان بج روی تصویر (پیش‌فرض: کیفیت)', type: 'text' },
{ key: 'about_badge_subtitle', label: 'زیرعنوان بج روی تصویر (پیش‌فرض: استانداردهای فوق‌دارویی)', type: 'text' },
{ key: 'about_item1_title', label: 'عنوان ویژگی اول (مواد اولیه نایاب)', type: 'text' },
{ key: 'about_item1_desc', label: 'توضیحات ویژگی اول', type: 'rich-text' },
{ key: 'about_item1_footnote', label: 'پاورقی ویژگی اول (استاندارد انسانی)', type: 'text' },
{ key: 'about_item2_title', label: 'عنوان ویژگی دوم (فاقد مواد نگهدارنده)', type: 'text' },
{ key: 'about_item2_desc', label: 'توضیحات ویژگی دوم', type: 'rich-text' },
{ key: 'about_item3_title', label: 'عنوان ویژگی سوم (تاییدیه اروپا)', type: 'text' },
{ key: 'about_item3_desc', label: 'توضیحات ویژگی سوم', type: 'rich-text' },
{ key: 'about_item3_footnote', label: 'پاورقی ویژگی سوم (استانداردهای HACCP & IFS)', type: 'text' },
],
},
{
id: 'testimonials',
title: 'نظرات دامپزشکان و مشتریان (Testimonials)',
icon: Award,
fields: [
{ key: 'testimonials_badge', label: 'بج بالای بخش نظرات', type: 'text' },
{ key: 'testimonials_title_1', label: 'بخش اول عنوان نظرات', type: 'text' },
{ key: 'testimonials_title_2', label: 'بخش رنگی عنوان نظرات', type: 'text' },
{ key: 'testimonials_desc', label: 'توضیحات معرفی بخش نظرات', type: 'rich-text' },
],
},
{
id: 'blog_preview',
title: 'پیش‌نمایش مقالات وبلاگ (Blog Preview)',
icon: FileText,
fields: [
{ key: 'blog_preview_badge', label: 'بج بالای مقالات وبلاگ', type: 'text' },
{ key: 'blog_preview_title', label: 'بخش اول عنوان مقالات', type: 'text' },
{ key: 'blog_preview_title_highlight', label: 'بخش هایلایت عنوان مقالات', type: 'text' },
{ key: 'blog_preview_desc', label: 'توضیحات کوتاه زیر عنوان مقالات', type: 'rich-text' },
{ key: 'blog_preview_view_all', label: 'متن دکمه مشاهده همه مقالات', type: 'text' },
],
},
{
id: 'faq',
title: 'سوالات متداول (FAQ Section)',
icon: HelpCircle,
fields: [
{ key: 'faq_badge', label: 'بج بالای سوالات متداول', type: 'text' },
{ key: 'faq_title_1', label: 'بخش اول تیتر سوالات متداول', type: 'text' },
{ key: 'faq_title_2', label: 'بخش رنگی تیتر سوالات متداول', type: 'text' },
{ key: 'faq_desc', label: 'توضیحات کوتاه زیر تیتر', type: 'rich-text' },
],
},
{
id: 'cta',
title: 'باکس دعوت به اقدام (Call To Action)',
icon: Sparkles,
fields: [
{ key: 'cta_title', label: 'عنوان اصلی کادر دعوت به خرید (H2)', type: 'rich-text' },
{ key: 'cta_desc', label: 'متن توضیحات و ترغیب', type: 'rich-text' },
{ key: 'cta_btn_primary', label: 'متن دکمه اصلی (دریافت رژیم مکمل رایگان)', type: 'text' },
{ key: 'cta_btn_secondary', label: 'متن دکمه ثانویه (پروانه دامپزشکی و اصالت کالا)', type: 'text' },
],
},
],
},
{
id: 'shop',
title: 'فروشگاه و محصولات (Shop)',
path: '/shop',
icon: ShoppingBag,
sections: [
createSeoSection('shop', 'فروشگاه', 'فروشگاه تخصصی مکمل‌های دارویی سگ و گربه', 'خرید آنلاین انواع مکمل‌های درمانی مفاصل، پوست و مو، گوارش و ویتامینه سگ و گربه با تضمین اصالت کالا و مشاوره بالینی.'),
{
id: 'shop_header',
title: 'هدر و فیلترهای فروشگاه',
icon: Sliders,
fields: [
{ key: 'shop_catalog_title', label: 'تیتر بالای لیست محصولات (پیش‌فرض: کاتولوگ دارویی Canina - پاک کنید تا پنهان شود)', type: 'rich-text' },
{ key: 'shop_filter_title', label: 'عنوان سایدبار فیلترها (پیش‌فرض: فیلترهای تخصصی)', type: 'text' },
{ key: 'shop_filter_pet_type', label: 'عنوان فیلتر نوع پت', type: 'text' },
{ key: 'shop_filter_solutions', label: 'عنوان فیلتر راهکار درمانی', type: 'text' },
{ key: 'shop_search_placeholder', label: 'متن کادر جستجوی محصول', type: 'text' },
{ key: 'shop_promo_card_title', label: 'عنوان کارت بنفش سایدبار (مشاوره رایگان)', type: 'text' },
{ key: 'shop_promo_card_desc', label: 'متن کارت بنفش سایدبار', type: 'rich-text' },
],
},
],
},
{
id: 'catalog',
title: 'کاتالوگ ورق‌زن دیجیتال (Digital Catalog)',
path: '/catalog',
icon: BookOpen,
sections: [
createSeoSection('catalog', 'کاتالوگ دیجیتال', 'کاتالوگ رسمی مکمل‌های درمانی و دارویی', 'مشاهده و مطالعه کاتالوگ جامع دارویی و مکمل‌های تغذیه‌ای تخصصی کنینا با قابلیت تورق تعاملی و ثبت پیش‌خرید.'),
{
id: 'catalog_header',
title: 'محتوا و راهنمای کاتالوگ',
icon: BookOpen,
fields: [
{ key: 'catalog_hero_title', label: 'عنوان صفحه کاتالوگ دیجیتال (H1)', type: 'rich-text' },
{ key: 'catalog_hero_desc', label: 'توضیحات معرفی و نحوه استفاده از کاتالوگ', type: 'rich-text' },
{ key: 'catalog_download_btn', label: 'متن دکمه دریافت نسخه کامل PDF', type: 'text' },
],
},
],
},
{
id: 'blog',
title: 'وبلاگ و مقالات تخصصی (Blog)',
path: '/blog',
icon: FileText,
sections: [
createSeoSection('blog', 'وبلاگ', 'مجله سلامت و دانشنامه مقالات تخصصی پت', 'جدیدترین مقالات، راهنماهای تغذیه، بیماری‌های مفاصل و سلامت پت توسط تیم دامپزشکی کنینا.'),
{
id: 'blog_header',
title: 'هدر و بنر وبلاگ',
icon: FileText,
fields: [
{ key: 'blog_page_title', label: 'عنوان صفحه مقالات و وبلاگ (H1)', type: 'rich-text' },
{ key: 'blog_page_desc', label: 'توضیحات سئو و مقدمه مقالات علمی', type: 'rich-text' },
{ key: 'blog_search_placeholder', label: 'متن کادر جستجو در مقالات', type: 'text' },
],
},
],
},
{
id: 'wiki',
title: 'دانشنامه ترکیبات و داروها (Wiki)',
path: '/wiki',
icon: Pill,
sections: [
createSeoSection('wiki', 'دانشنامه', 'دانشنامه علمی ترکیبات و اصطلاحات دارویی', 'مرجع تخصصی اثرات بالینی، مواد تشکیل‌دهنده، ویتامین‌ها و ترکیبات گیاهی به کار رفته در محصولات کنینا.'),
{
id: 'wiki_header',
title: 'هدر و ناوبری دانشنامه',
icon: Pill,
fields: [
{ key: 'wiki_page_title', label: 'عنوان صفحه دانشنامه (H1)', type: 'rich-text' },
{ key: 'wiki_page_desc', label: 'توضیحات سئو دانشنامه دارویی', type: 'rich-text' },
{ key: 'wiki_search_placeholder', label: 'متن جستجوی اصطلاح یا ترکیب', type: 'text' },
],
},
],
},
{
id: 'about',
title: 'درباره ما و تاریخچه برند (About Us)',
path: '/about',
icon: Award,
sections: [
createSeoSection('about', 'درباره ما', 'درباره شرکت کنینا ایران و اصالت آلمانی', 'آشنایی با تاریخچه شرکت Canina Pharma آلمان، تعهد به کیفیت بیولوژیک و بیش از ۴۰ سال سابقه پیشرو در سلامت حیوانات خانگی.'),
{
id: 'about_content',
title: 'متن و داستان برند',
icon: Award,
fields: [
{ key: 'about_page_title', label: 'عنوان صفحه درباره ما (H1)', type: 'rich-text' },
{ key: 'about_page_subtitle', label: 'زیرعنوان و شعار اصالت', type: 'text' },
{ key: 'about_full_history', label: 'تاریخچه کامل برند و شرکت (H2/P)', type: 'rich-text' },
{ key: 'about_mission_title', label: 'عنوان ماموریت و تعهدات', type: 'text' },
{ key: 'about_mission_desc', label: 'متن ماموریت سازمانی', type: 'rich-text' },
],
},
],
},
{
id: 'contact',
title: 'تماس با ما و پشتیبانی (Contact)',
path: '/contact',
icon: PhoneCall,
sections: [
createSeoSection('contact', 'تماس با ما', 'تماس با ما و مشاوره تخصصی دامپزشکی', 'راه‌های ارتباط با دفتر مرکزی کنینا در ایران، ثبت پیام، مشاوره رایگان دارویی و شماره تماس کارشناسان.'),
{
id: 'contact_info',
title: 'اطلاعات تماس و پیام‌ها',
icon: PhoneCall,
fields: [
{ key: 'contact_page_title', label: 'عنوان صفحه تماس با ما (H1)', type: 'rich-text' },
{ key: 'contact_page_desc', label: 'توضیحات بالای فرم تماس', type: 'rich-text' },
{ key: 'contact_form_success_msg', label: 'پیام تشکر بعد از ارسال پیام', type: 'text' },
],
},
],
},
{
id: 'b2b',
title: 'پرتال همکاران عمده‌فروشی (B2B Portal)',
path: '/b2b',
icon: Building2,
sections: [
createSeoSection('b2b', 'همکاران تجاری B2B', 'پرتال همکاران تجاری، کلینیک‌ها و پت‌شاپ‌ها', 'ثبت درخواست عاملیت فروش، خرید عمده با تخفیف سازمانی ویژه دامپزشکان، کلینیک‌ها و پت‌شاپ‌های سراسر کشور.'),
{
id: 'b2b_landing',
title: 'صفحه معرفی و شرایط همکاری B2B',
icon: Building2,
fields: [
{ key: 'b2b_hero_title', label: 'عنوان بنر همکاری B2B (H1)', type: 'rich-text' },
{ key: 'b2b_hero_desc', label: 'توضیحات و مزایای همکاری تجاری', type: 'rich-text' },
{ key: 'b2b_form_title', label: 'عنوان فرم درخواست نمایندگی', type: 'text' },
{ key: 'b2b_form_desc', label: 'راهنمای ارسال مدارک داروخانه/کلینیک', type: 'rich-text' },
],
},
],
},
{
id: 'videos',
title: 'ویدئوها و آموزش‌های تصویری (Videos)',
path: '/videos',
icon: Video,
sections: [
createSeoSection('videos', 'ویدئوهای آموزشی', 'ویدئوهای آموزشی و توصیه‌های بالینی دامپزشکان', 'مشاهده ویدئوهای تخصصی نحوه مصرف مکمل‌ها، نظرات دامپزشکان و راهکارهای درمانی تصویری.'),
{
id: 'videos_hub',
title: 'هدر و متن صفحه ویدئوها',
icon: Video,
fields: [
{ key: 'videos_page_title', label: 'عنوان صفحه ویدئوها (H1)', type: 'rich-text' },
{ key: 'videos_page_desc', label: 'توضیحات معرفی دوره‌ها و کلیپ‌های آموزشی', type: 'rich-text' },
],
},
],
},
{
id: 'search',
title: 'جستجوی پیشرفته سایت (Search)',
path: '/search',
icon: Search,
sections: [
createSeoSection('search', 'جستجو', 'جستجوی هوشمند مکمل‌ها و دانشنامه سلامت', 'جستجوی سریع محصولات، مکمل‌های تخصصی، بیماری‌ها و علائم بالینی سگ و گربه.'),
{
id: 'search_content',
title: 'متون راهنما و کادر جستجو',
icon: Search,
fields: [
{ key: 'search_results_title', label: 'عنوان نتایج جستجو', type: 'text' },
{ key: 'search_no_results_text', label: 'متن پیام در صورت عدم یافتن نتیجه', type: 'text' },
],
},
],
},
{
id: 'dashboard',
title: 'داشبورد و حساب کاربری (User Dashboard)',
path: '/dashboard',
icon: User,
sections: [
createSeoSection('dashboard', 'داشبورد کاربر', 'داشبورد کاربری و پیگیری سفارشات', 'مشاهده تاریخچه خریدها، وضعیت کیف پول، پیگیری آنلاین بسته‌های پستی و مدیریت پت‌ها.'),
{
id: 'dashboard_content',
title: 'عناوین و پیام‌های داشبورد',
icon: User,
fields: [
{ key: 'dashboard_welcome_msg', label: 'پیام خوش‌آمدگویی بالای داشبورد', type: 'text' },
{ key: 'dashboard_wallet_title', label: 'عنوان کارت کیف پول کنینا', type: 'text' },
],
},
],
},
{
id: 'pet_profiles',
title: 'پرونده سلامت همدم (Pet Profiles)',
path: '/profile/pets',
icon: Heart,
sections: [
createSeoSection('profile_pets', 'پرونده سلامت پت', 'پرونده الکترونیک سلامت پت', 'مدیریت و ثبت پرونده سلامت سگ و گربه، تنظیم یادآورهای دوز دارو و تاریخچه تغذیه مکمل‌ها.'),
{
id: 'pet_profiles_info',
title: 'عناوین پرونده سلامت و یادآورها',
icon: Heart,
fields: [
{ key: 'pet_profile_title', label: 'عنوان بخش پرونده سلامت پت', type: 'rich-text' },
{ key: 'pet_profile_desc', label: 'توضیحات پرونده و برنامه تغذیه', type: 'rich-text' },
],
},
],
},
{
id: 'checkout',
title: 'تسویه‌حساب و فاکتور نهایی (Checkout)',
path: '/checkout',
icon: CreditCard,
sections: [
createSeoSection('checkout', 'تسویه‌حساب', 'تسویه‌حساب و پرداخت امن', 'انتخاب آدرس تحویل، انتخاب روش پرداخت و تسویه‌حساب سریع و امن سفارشات کنینا.'),
{
id: 'checkout_content',
title: 'پیام‌ها و راهنمای تسویه',
icon: CreditCard,
fields: [
{ key: 'checkout_step1_title', label: 'عنوان مرحله انتخاب آدرس', type: 'text' },
{ key: 'checkout_step2_title', label: 'عنوان مرحله شیوه پرداخت', type: 'text' },
{ key: 'checkout_charity_notice', label: 'متن توضیح طرح ردپای مهربانی در فاکتور', type: 'text' },
],
},
],
},
{
id: 'track',
title: 'پیگیری آنلاین سفارش و مرسوله (Track Order)',
path: '/track',
icon: Truck,
sections: [
createSeoSection('track', 'پیگیری سفارش', 'پیگیری آنلاین سفارش و مرسوله پستی', 'پیگیری وضعیت بسته‌بندی، کد رهگیری پست پیشتاز و تاریخچه تحویل سفارشات.'),
{
id: 'track_content',
title: 'متن و کادر رهگیری',
icon: Truck,
fields: [
{ key: 'track_page_title', label: 'عنوان صفحه رهگیری (H1)', type: 'rich-text' },
{ key: 'track_page_desc', label: 'توضیحات نحوه پیگیری با شماره همراه یا کد سفارش', type: 'rich-text' },
],
},
],
},
{
id: 'trust_seals',
title: 'مجوزها و نمادهای اعتماد (Trust Seals)',
path: '/trust-seals',
icon: Shield,
sections: [
createSeoSection('trust_seals', 'مجوزها و اصالت', 'مجوزهای رسمی، گواهی اصالت و اینماد', 'بررسی تاییدیه‌های سازمان دامپزشکی، گواهی استاندارد آلمان و اینماد رسمی کنینا.'),
{
id: 'trust_seals_content',
title: 'متن مجوزها و گواهی‌ها',
icon: Shield,
fields: [
{ key: 'trust_page_title', label: 'عنوان صفحه مجوزها (H1)', type: 'rich-text' },
{ key: 'trust_page_desc', label: 'توضیحات و ضمانت‌های بهداشتی و قانونی', type: 'rich-text' },
],
},
],
},
{
id: 'privacy',
title: 'حریم خصوصی و قوانین سایت (Privacy & Terms)',
path: '/privacy',
icon: ShieldCheck,
sections: [
createSeoSection('privacy', 'حریم خصوصی', 'حریم خصوصی و شرایط استفاده', 'قوانین خرید، عودت کالا، حفاظت از اطلاعات کاربران و شرایط استفاده از خدمات کنینا.'),
{
id: 'privacy_content',
title: 'متن قوانین و مقررات',
icon: ShieldCheck,
fields: [
{ key: 'privacy_page_title', label: 'عنوان صفحه قوانین و مقررات (H1)', type: 'rich-text' },
{ key: 'privacy_full_terms', label: 'متن کامل شرایط استفاده و حریم خصوصی', type: 'rich-text' },
],
},
],
},
];
const SHARED_HEADER_FIELDS: SectionField[] = [
{ key: 'shipping_notice', label: 'متن نوار متحرک بالای سایت (Ticker Announcement)', type: 'rich-text', description: 'نمایش در بالاترین نوار زرد تمام صفحات' },
{ key: 'brand_name_fa', label: 'نام فارسی برند در هدر', type: 'text' },
{ key: 'brand_subtitle', label: 'زیرعنوان نمایندگی در هدر', type: 'text' },
{ key: 'nav_solutions', label: 'عنوان منوی راهکارهای درمانی', type: 'text' },
{ key: 'nav_products', label: 'عنوان منوی کاتالوگ محصولات', type: 'text' },
{ key: 'nav_wiki', label: 'عنوان منوی دانشنامه', type: 'text' },
{ key: 'nav_blog', label: 'عنوان منوی وبلاگ', type: 'text' },
{ key: 'nav_pet_profiles', label: 'عنوان منوی پرونده سلامت', type: 'text' },
{ key: 'nav_search_placeholder', label: 'متن پیش‌فرض کادر جستجو', type: 'text' },
{ key: 'nav_cart', label: 'متن دکمه سبد خرید', type: 'text' },
{ key: 'header_logo_icon', label: 'آیکون نماد هدر', type: 'icon' },
];
const SHARED_FOOTER_FIELDS: SectionField[] = [
{ key: 'footer_brand_title', label: 'عنوان برند در فوتر', type: 'text' },
{ key: 'footer_brand_subtitle', label: 'زیرعنوان برند در فوتر', type: 'text' },
{ key: 'footer_brand_desc', label: 'متن معرفی شرکت در فوتر (سئو فوتر)', type: 'rich-text' },
{ key: 'footer_links_title', label: 'عنوان ستون دسترسی سریع', type: 'text' },
{ key: 'footer_contact_title', label: 'عنوان ستون راه‌های ارتباطی', type: 'text' },
{ key: 'footer_phone_label', label: 'برچسب تلفن پشتیبانی', type: 'text' },
{ key: 'footer_email_label', label: 'برچسب ایمیل', type: 'text' },
{ key: 'footer_address_label', label: 'برچسب آدرس دفتر', type: 'text' },
{ key: 'footer_copyright', label: 'متن حق نشر و کپی‌رایت انتهای فوتر', type: 'rich-text' },
{ key: 'footer_auth_badge', label: 'متن بج اصالت آلمان', type: 'text' },
];
export default function UITexts() {
const [searchParams, setSearchParams] = useSearchParams();
const [v2SubTab, setV2SubTabState] = useState<'header' | 'footer' | 'pages'>(() => (searchParams.get('subTab') as 'header' | 'footer' | 'pages') || 'pages');
const [openPageId, setOpenPageIdState] = useState<string>(() => searchParams.get('pageId') || 'home');
const [openSectionId, setOpenSectionIdState] = useState<string>(() => searchParams.get('sectionId') || 'seo');
const [previewDevice, setPreviewDevice] = useState<'desktop' | 'mobile'>('desktop');
const updateUrlState = (updates: Record<string, string | null>) => {
const current = Object.fromEntries(searchParams.entries());
const merged = { ...current, ...updates };
const cleaned: Record<string, string> = {};
Object.entries(merged).forEach(([k, v]) => {
if (v !== null && v !== undefined && v !== '') cleaned[k] = v;
});
setSearchParams(cleaned, { replace: true });
};
const setV2SubTab = (t: 'header' | 'footer' | 'pages') => {
setV2SubTabState(t);
updateUrlState({ subTab: t === 'pages' ? null : t });
};
const setOpenPageId = (pid: string) => {
setOpenPageIdState(pid);
updateUrlState({ pageId: pid === 'home' ? null : pid });
};
const setOpenSectionId = (sid: string) => {
setOpenSectionIdState(sid);
updateUrlState({ sectionId: sid === 'seo' ? null : sid });
};
// State
const [texts, setTexts] = useState<Record<string, string>>({});
const [edits, setEdits] = useState<Record<string, string>>({});
const [savingKey, setSavingKey] = useState<string | null>(null);
const [savedKey, setSavedKey] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
const [isSavingAll, setIsSavingAll] = useState(false);
// Modals
const [previewModalUrl, setPreviewModalUrl] = useState<string | null>(() => searchParams.get('previewModal') || null);
const [mediaSelectorKey, setMediaSelectorKeyState] = useState<string | null>(() => searchParams.get('mediaKey') || null);
const [iconPickerKey, setIconPickerKeyState] = useState<string | null>(() => searchParams.get('iconKey') || null);
const setMediaSelectorKey = (k: string | null) => {
setMediaSelectorKeyState(k);
updateUrlState({ mediaKey: k });
};
const setIconPickerKey = (k: string | null) => {
setIconPickerKeyState(k);
updateUrlState({ iconKey: k });
};
useEffect(() => {
let isSubscribed = true;
api.get('/settings/ui-texts')
.then((res) => {
if (!isSubscribed) return;
const textsObj: Record<string, string> = {};
if (Array.isArray(res.data)) {
res.data.forEach((item: { key?: string; value?: string }) => {
if (item && item.key) {
textsObj[item.key] = typeof item.value === 'string' ? item.value : (item.value ? JSON.stringify(item.value) : '');
}
});
} else if (typeof res.data === 'object' && res.data !== null) {
Object.assign(textsObj, res.data);
}
setTexts(textsObj);
})
.catch((e) => {
console.error('Failed to load UI texts:', e);
})
.finally(() => {
if (isSubscribed) setLoading(false);
});
return () => {
isSubscribed = false;
};
}, []);
const handleSave = async (key: string) => {
const value = edits[key] ?? texts[key] ?? '';
setSavingKey(key);
try {
await api.put(`/settings/ui-texts/${encodeURIComponent(key)}`, { value });
setTexts((prev) => ({ ...prev, [key]: value }));
setSavedKey(key);
toast.success('محتوا با موفقیت ذخیره شد');
setTimeout(() => setSavedKey(null), 2000);
} catch {
try {
await api.patch(`/settings/ui-texts/${encodeURIComponent(key)}`, { value });
setTexts((prev) => ({ ...prev, [key]: value }));
setSavedKey(key);
toast.success('محتوا با موفقیت ذخیره شد');
setTimeout(() => setSavedKey(null), 2000);
} catch (err: any) {
const errorMsg = err?.response?.data?.message || 'خطا در ذخیره‌سازی محتوا';
toast.error(errorMsg);
}
} finally {
setSavingKey(null);
}
};
const handleSaveAll = async () => {
const dirtyKeys = Object.keys(edits);
if (dirtyKeys.length === 0) {
toast('هیچ تغییری برای ذخیره وجود ندارد');
return;
}
setIsSavingAll(true);
try {
await api.put('/settings/ui-texts', edits);
setTexts((prev) => ({ ...prev, ...edits }));
setEdits({});
toast.success(`${dirtyKeys.length} تغییر با موفقیت ذخیره شد`);
} catch {
try {
const promises = dirtyKeys.map((k) =>
api.put(`/settings/ui-texts/${encodeURIComponent(k)}`, { value: edits[k] })
);
await Promise.all(promises);
setTexts((prev) => ({ ...prev, ...edits }));
setEdits({});
toast.success(`${dirtyKeys.length} تغییر با موفقیت ذخیره شد`);
} catch {
toast.error('خطا در ذخیره‌سازی گروهی تغییرات');
}
} finally {
setIsSavingAll(false);
}
};
if (loading) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<Spinner size="lg" className="text-purple-600" />
</div>
);
}
const hasUnsavedChanges = Object.keys(edits).length > 0;
// Render a Single Field in Page Builder
const renderField = (field: SectionField) => {
const val = edits[field.key] ?? texts[field.key] ?? field.defaultVal ?? '';
const isSaved = savedKey === field.key;
const isSaving = savingKey === field.key;
return (
<div key={field.key} className="bg-gray-50/70 p-5 rounded-2xl border border-gray-200/80 space-y-3">
<div className="flex items-center justify-between">
<div>
<span className="text-sm font-black text-gray-900 block">{field.label}</span>
{field.description && (
<span className="text-[11px] text-gray-500 font-medium block mt-0.5">{field.description}</span>
)}
<code className="text-[10px] text-purple-600 font-mono font-bold block mt-0.5" dir="ltr">
{field.key}
</code>
</div>
{isSaved && (
<span className="text-xs text-emerald-600 font-black flex items-center gap-1 bg-emerald-50 px-2.5 py-1 rounded-lg border border-emerald-200">
<Check className="w-3.5 h-3.5" /> ذخیره شد
</span>
)}
</div>
{/* Input by Type */}
{field.type === 'rich-text' ? (
<RichTextEditor
value={val}
onChange={(html) => setEdits({ ...edits, [field.key]: html })}
placeholder="متن خود را وارد کنید..."
/>
) : field.type === 'textarea' ? (
<textarea
rows={3}
value={val}
onChange={(e) => setEdits({ ...edits, [field.key]: e.target.value })}
placeholder={field.defaultVal || 'توضیحات خود را وارد کنید...'}
className="w-full px-4 py-2.5 bg-white border border-gray-200 rounded-xl text-xs font-bold text-gray-900 outline-none focus:ring-2 focus:ring-purple-500 leading-relaxed"
/>
) : field.type === 'image' ? (
<div className="space-y-3">
<div className="flex gap-2">
<input
type="text"
value={val}
onChange={(e) => setEdits({ ...edits, [field.key]: e.target.value })}
placeholder="https://... یا انتخاب از گالری"
className="flex-1 px-4 py-2.5 bg-white border border-gray-200 rounded-xl text-xs font-mono font-bold outline-none focus:ring-2 focus:ring-purple-500"
dir="ltr"
/>
<button
type="button"
onClick={() => setMediaSelectorKey(field.key)}
className="px-4 py-2.5 bg-purple-600 hover:bg-purple-700 text-white rounded-xl text-xs font-bold transition-all flex items-center gap-1.5 shadow-sm cursor-pointer"
>
<Upload className="w-4 h-4" />
<span>گالری و آپلود</span>
</button>
</div>
{val && (
<div className="flex items-center gap-3 p-3 bg-white rounded-xl border border-gray-200">
<div className="w-16 h-16 rounded-lg bg-gray-50 border border-gray-100 overflow-hidden shrink-0 flex items-center justify-center p-1">
<img
src={val.startsWith('http') ? val : `${BASE_DOMAIN}${val}`}
alt="Preview"
className="max-w-full max-h-full object-contain"
/>
</div>
<div className="flex-1 truncate text-xs text-gray-600 font-mono" dir="ltr">
{val}
</div>
<button
type="button"
onClick={() => setPreviewModalUrl(val.startsWith('http') ? val : `${BASE_DOMAIN}${val}`)}
className="p-2 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors cursor-pointer"
title="مشاهده بزرگ‌تر"
>
<Eye className="w-4 h-4" />
</button>
</div>
)}
</div>
) : field.type === 'icon' ? (
<div className="flex items-center gap-3 bg-white p-3 rounded-xl border border-gray-200">
<div className="w-12 h-12 rounded-xl bg-purple-50 text-purple-600 border border-purple-200 flex items-center justify-center font-black shrink-0">
{ICON_REGISTRY[val] ? (
React.createElement(ICON_REGISTRY[val], { className: 'w-6 h-6' })
) : (
<Sparkles className="w-6 h-6 text-gray-400" />
)}
</div>
<div className="flex-1">
<span className="text-xs font-bold text-gray-900 block">
{val ? `آیکون انتخاب‌شده: ${val}` : 'هیچ آیکونی انتخاب نشده است'}
</span>
<span className="text-[11px] text-gray-400 font-mono block">از کتابخانه Lucide Icons</span>
</div>
<button
type="button"
onClick={() => setIconPickerKey(field.key)}
className="px-4 py-2 bg-purple-50 hover:bg-purple-100 text-purple-700 border border-purple-200 rounded-xl text-xs font-black transition-all cursor-pointer"
>
انتخاب آیکون
</button>
</div>
) : field.type === 'boolean' ? (
<div className="flex items-center justify-between p-3 bg-white rounded-xl border border-gray-200">
<span className="text-xs font-bold text-gray-700">
وضعیت: {val === 'true' ? <strong className="text-green-600">فعال (روشن)</strong> : <strong className="text-gray-400">غیرفعال (خاموش)</strong>}
</span>
<ToggleSwitch
checked={val === 'true'}
onChange={(c) => setEdits({ ...edits, [field.key]: String(c) })}
/>
</div>
) : (
<input
type="text"
value={val}
onChange={(e) => setEdits({ ...edits, [field.key]: e.target.value })}
className="w-full px-4 py-2.5 bg-white border border-gray-200 rounded-xl text-xs font-bold text-gray-900 outline-none focus:ring-2 focus:ring-purple-500"
/>
)}
<div className="flex justify-end pt-1">
<Button
type="button"
variant="primary"
size="xs"
startIcon={Save}
onClick={() => handleSave(field.key)}
isLoading={isSaving}
>
ذخیره این فیلد
</Button>
</div>
</div>
);
};
return (
<div className="space-y-6 font-vazir text-right" dir="rtl">
{/* Top Header */}
<div className="bg-white p-6 rounded-3xl border border-gray-200 shadow-xs flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h1 className="text-2xl font-black text-gray-900 flex items-center gap-3">
<Languages className="w-7 h-7 text-purple-600" />
مدیریت جامع صفحات و ویرایشگر سئو (Page Builder v2)
</h1>
<p className="text-xs text-gray-500 font-bold mt-1">
پوشش کامل تمام {SITE_PAGES.length} صفحه برنامه شامل پیش‌نمایش زنده در گوگل (Google SERP)، ویرایشگر متن، تصاویر و آیکون‌ها
</p>
</div>
<div className="flex items-center gap-3">
<Button
type="button"
variant="primary"
size="sm"
startIcon={Save}
onClick={handleSaveAll}
disabled={!hasUnsavedChanges}
isLoading={isSavingAll}
>
ذخیره تمامی تغییرات {hasUnsavedChanges ? `(${Object.keys(edits).length})` : ''}
</Button>
</div>
</div>
{/* Modern Page Builder Interface */}
<div className="space-y-6">
{/* Sub Tabs: Header, Footer, Site Pages */}
<div className="flex items-center gap-2 bg-white p-2 rounded-2xl border border-gray-200 shadow-xs overflow-x-auto no-scrollbar">
<button
type="button"
onClick={() => setV2SubTab('pages')}
className={`px-6 py-3 rounded-xl text-xs font-black transition-all flex items-center gap-2 cursor-pointer shrink-0 ${
v2SubTab === 'pages'
? 'bg-purple-600 text-white shadow-md shadow-purple-200'
: 'text-gray-600 hover:bg-gray-50 hover:text-purple-700'
}`}
>
<Layout className="w-4 h-4" />
<span>تمام صفحات فروشگاه ({SITE_PAGES.length} صفحه تفکیک‌شده)</span>
</button>
<button
type="button"
onClick={() => setV2SubTab('header')}
className={`px-6 py-3 rounded-xl text-xs font-black transition-all flex items-center gap-2 cursor-pointer shrink-0 ${
v2SubTab === 'header'
? 'bg-purple-600 text-white shadow-md shadow-purple-200'
: 'text-gray-600 hover:bg-gray-50 hover:text-purple-700'
}`}
>
<LinkIcon className="w-4 h-4" />
<span>هدر و ناوبری مشترک (Header)</span>
</button>
<button
type="button"
onClick={() => setV2SubTab('footer')}
className={`px-6 py-3 rounded-xl text-xs font-black transition-all flex items-center gap-2 cursor-pointer shrink-0 ${
v2SubTab === 'footer'
? 'bg-purple-600 text-white shadow-md shadow-purple-200'
: 'text-gray-600 hover:bg-gray-50 hover:text-purple-700'
}`}
>
<Languages className="w-4 h-4" />
<span>فوتر و کپی‌رایت مشترک (Footer)</span>
</button>
</div>
{/* Sub Tab: Shared Header */}
{v2SubTab === 'header' && (
<div className="bg-white p-6 sm:p-8 rounded-3xl border border-gray-200 shadow-sm space-y-6">
<div className="flex items-center justify-between border-b border-gray-100 pb-4">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-2xl bg-purple-50 text-purple-600 flex items-center justify-center font-black">
<LinkIcon className="w-5 h-5" />
</div>
<div>
<h3 className="text-base font-black text-gray-900">تنظیمات هدر، اعلان بالا و منوها</h3>
<p className="text-xs text-gray-500 font-medium">محتوای مشترک بالای تمام صفحات فروشگاه</p>
</div>
</div>
</div>
<div className="grid gap-6 md:grid-cols-2">
{SHARED_HEADER_FIELDS.map((f) => renderField(f))}
</div>
</div>
)}
{/* Sub Tab: Shared Footer */}
{v2SubTab === 'footer' && (
<div className="bg-white p-6 sm:p-8 rounded-3xl border border-gray-200 shadow-sm space-y-6">
<div className="flex items-center justify-between border-b border-gray-100 pb-4">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-2xl bg-purple-50 text-purple-600 flex items-center justify-center font-black">
<Languages className="w-5 h-5" />
</div>
<div>
<h3 className="text-base font-black text-gray-900">تنظیمات فوتر، کپی‌رایت و ستون‌های پیوند</h3>
<p className="text-xs text-gray-500 font-medium">محتوای مشترک انتهای تمام صفحات سایت</p>
</div>
</div>
</div>
<div className="grid gap-6 md:grid-cols-2">
{SHARED_FOOTER_FIELDS.map((f) => renderField(f))}
</div>
</div>
)}
{/* Sub Tab: Site Pages Accordion */}
{v2SubTab === 'pages' && (
<div className="space-y-4">
{SITE_PAGES.map((page) => {
const PageIcon = page.icon;
const isOpen = openPageId === page.id;
const activeSection = page.sections.find((s) => s.id === openSectionId) || page.sections[0];
// Dynamic SEO Preview Derived Values
const seoTitleKey = `${page.id}_meta_title`;
const seoDescKey = `${page.id}_meta_desc`;
const seoCanonicalKey = `${page.id}_canonical`;
const rawPageMetaTitle =
edits[seoTitleKey] ??
texts[seoTitleKey] ??
page.sections.find((s) => s.id === 'seo')?.fields[0]?.defaultVal ??
page.title;
const brandName = texts['brand_name_fa'] || 'کنینا ایران';
const titleSep = texts['title_separator'] || '|';
const titlePos = texts['title_position'] || 'suffix';
const formatPreviewTitle = (raw: string, isHome = false): string => {
if (!raw || !raw.trim()) return brandName;
const clean = raw.trim();
if (isHome) return clean;
const escapedBrand = brandName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const brandRegex = new RegExp(`(\\s*[-|•]\\s*${escapedBrand}|${escapedBrand}\\s*[-|•]\\s*)`, 'gi');
const baseTitle = clean.replace(brandRegex, '').trim();
if (titlePos === 'none') return baseTitle || clean;
if (titlePos === 'prefix') return `${brandName} ${titleSep} ${baseTitle || clean}`;
return `${baseTitle || clean} ${titleSep} ${brandName}`;
};
const pageMetaTitle = formatPreviewTitle(rawPageMetaTitle, page.id === 'home');
const pageMetaDesc =
edits[seoDescKey] ??
texts[seoDescKey] ??
page.sections.find((s) => s.id === 'seo')?.fields[1]?.defaultVal ??
`مشاهده و بررسی آنلاین ${page.title} در وب‌سایت رسمی ${brandName} با ضمانت اصالت کالا و مشاوره دارویی.`;
const pageCanonical =
edits[seoCanonicalKey] ??
texts[seoCanonicalKey] ??
`https://canina.ir${page.path === '/' ? '' : page.path}`;
return (
<div
key={page.id}
className="bg-white rounded-3xl border border-gray-200 shadow-xs overflow-hidden transition-all"
>
{/* Collapsible Page Header */}
<button
type="button"
onClick={() => setOpenPageId(isOpen ? '' : page.id)}
className={`w-full p-5 sm:p-6 flex items-center justify-between transition-colors cursor-pointer text-right ${
isOpen ? 'bg-purple-50/70 border-b border-purple-100' : 'hover:bg-gray-50'
}`}
>
<div className="flex items-center gap-3.5">
<div
className={`w-10 h-10 rounded-2xl flex items-center justify-center transition-all ${
isOpen
? 'bg-purple-600 text-white shadow-md shadow-purple-200'
: 'bg-gray-100 text-gray-600'
}`}
>
<PageIcon className="w-5 h-5" />
</div>
<div>
<h3 className="text-base font-black text-gray-900">{page.title}</h3>
<span className="text-xs text-purple-600 font-mono font-bold" dir="ltr">
{page.path}
</span>
</div>
</div>
<div className="flex items-center gap-3">
<span className="text-xs font-bold px-3 py-1 bg-white rounded-xl border border-gray-200 text-gray-600">
{page.sections.length} بخش (شامل سئو)
</span>
<ChevronDown
className={`w-5 h-5 text-gray-400 transition-transform duration-200 ${
isOpen ? 'rotate-180 text-purple-600' : ''
}`}
/>
</div>
</button>
{/* Page Content & Section Tabs */}
{isOpen && (
<div className="p-6 sm:p-8 space-y-6">
{/* Section Tabs */}
{page.sections.length > 1 && (
<div className="flex items-center gap-2 overflow-x-auto pb-2 border-b border-gray-100 no-scrollbar">
{page.sections.map((sec) => {
const SecIcon = sec.icon;
const isSecActive = (openSectionId || page.sections[0].id) === sec.id;
return (
<button
key={sec.id}
type="button"
onClick={() => setOpenSectionId(sec.id)}
className={`px-4 py-2 rounded-xl text-xs font-black transition-all flex items-center gap-2 cursor-pointer shrink-0 border ${
isSecActive
? sec.isSeo
? 'bg-sky-600 text-white border-sky-600 shadow-sm'
: 'bg-purple-600 text-white border-purple-600 shadow-sm'
: 'bg-gray-50 text-gray-700 border-gray-200 hover:bg-gray-100'
}`}
>
<SecIcon className="w-3.5 h-3.5" />
<span>{sec.title}</span>
{sec.isSeo && (
<span className="text-[10px] bg-white/20 px-1.5 py-0.2 rounded font-mono">
Google
</span>
)}
</button>
);
})}
</div>
)}
{/* If Active Section is SEO: Render Google SERP Live Preview Box Side-by-Side */}
{activeSection.isSeo ? (
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start">
{/* Left/Main Column: SEO Inputs */}
<div className="lg:col-span-7 space-y-4">
<div className="flex items-center gap-2 pb-2">
<span className="w-2.5 h-2.5 rounded-full bg-sky-600" />
<h4 className="text-sm font-black text-gray-800">
فیلدهای متادیتای سئو (SEO Meta Tags)
</h4>
</div>
<div className="space-y-4">
{activeSection.fields.map((f) => renderField(f))}
</div>
</div>
{/* Right Column: Google SERP Preview Box */}
<div className="lg:col-span-5 lg:sticky lg:top-4 bg-slate-50 border border-slate-200 rounded-3xl p-5 space-y-4 shadow-xs">
<div className="flex items-center justify-between border-b border-slate-200 pb-3">
<div className="flex items-center gap-2">
<div className="w-7 h-7 rounded-lg bg-white border border-slate-200 flex items-center justify-center shadow-xs">
<Globe className="w-4 h-4 text-sky-600" />
</div>
<span className="text-xs font-black text-slate-800">پیش‌نمایش در گوگل</span>
</div>
<div className="flex items-center gap-1 bg-white p-1 rounded-xl border border-slate-200">
<button
type="button"
onClick={() => setPreviewDevice('desktop')}
className={`p-1.5 rounded-lg transition-colors cursor-pointer ${
previewDevice === 'desktop'
? 'bg-sky-50 text-sky-700 font-bold'
: 'text-gray-400 hover:text-gray-600'
}`}
title="نمای دسکتاپ"
>
<Monitor className="w-3.5 h-3.5" />
</button>
<button
type="button"
onClick={() => setPreviewDevice('mobile')}
className={`p-1.5 rounded-lg transition-colors cursor-pointer ${
previewDevice === 'mobile'
? 'bg-sky-50 text-sky-700 font-bold'
: 'text-gray-400 hover:text-gray-600'
}`}
title="نمای موبایل"
>
<Smartphone className="w-3.5 h-3.5" />
</button>
</div>
</div>
{/* Google Snippet Card */}
<div
className={`bg-white rounded-2xl border border-slate-200 p-4 shadow-sm text-right font-sans space-y-2 transition-all ${
previewDevice === 'mobile' ? 'max-w-[340px] mx-auto border-sky-200' : ''
}`}
dir="rtl"
>
{/* Breadcrumbs / Domain */}
<div className="flex items-center gap-2 text-xs text-[#202124]">
<div className="w-5 h-5 rounded-full bg-slate-100 flex items-center justify-center text-[10px] font-bold text-slate-700 border">
C
</div>
<div className="flex flex-col truncate">
<span className="font-bold text-slate-900 text-[11px]">کنینا ایران - Canina</span>
<span className="text-[10px] text-slate-500 font-mono" dir="ltr">
{pageCanonical}
</span>
</div>
</div>
{/* Title */}
<h4 className="text-[17px] text-[#1a0dab] hover:underline cursor-pointer leading-tight font-medium font-sans select-none line-clamp-2">
{pageMetaTitle}
</h4>
{/* Snippet */}
<p className="text-xs text-[#4d5156] leading-relaxed font-sans select-none break-words line-clamp-3">
{pageMetaDesc}
</p>
</div>
{/* Live Metrics & Length Warning Indicators */}
<div className="space-y-2 text-[11px] font-bold text-slate-600 pt-2 border-t border-slate-200">
<div className="flex items-center justify-between">
<span>طول عنوان (Meta Title):</span>
<span
className={`px-2 py-0.5 rounded-lg ${
pageMetaTitle.length > 60
? 'bg-amber-100 text-amber-800'
: 'bg-emerald-100 text-emerald-800'
}`}
>
{pageMetaTitle.length} / ۶۰ کاراکتر
</span>
</div>
<div className="flex items-center justify-between">
<span>طول توضیحات (Description):</span>
<span
className={`px-2 py-0.5 rounded-lg ${
pageMetaDesc.length > 160
? 'bg-amber-100 text-amber-800'
: 'bg-emerald-100 text-emerald-800'
}`}
>
{pageMetaDesc.length} / ۱۶۰ کاراکتر
</span>
</div>
</div>
</div>
</div>
) : (
/* Non-SEO Content Section Grid */
<div className="space-y-4">
<div className="flex items-center gap-2 pb-2">
<span className="w-2 h-2 rounded-full bg-purple-600" />
<h4 className="text-sm font-black text-gray-800">
فیلدهای محتوایی: {activeSection.title}
</h4>
</div>
<div className="grid gap-6 md:grid-cols-2">
{activeSection.fields.map((f) => renderField(f))}
</div>
</div>
)}
</div>
)}
</div>
);
})}
</div>
)}
</div>
{/* Media Selector Modal */}
{mediaSelectorKey && (
<MediaSelector
isOpen={!!mediaSelectorKey}
onClose={() => setMediaSelectorKey(null)}
onSelect={(url) => {
setEdits({ ...edits, [mediaSelectorKey]: url });
setMediaSelectorKey(null);
}}
/>
)}
{/* Icon Picker Modal */}
{iconPickerKey && (
<IconPickerModal
isOpen={!!iconPickerKey}
onClose={() => setIconPickerKey(null)}
currentIcon={edits[iconPickerKey] ?? texts[iconPickerKey]}
onSelect={(iconName) => {
setEdits({ ...edits, [iconPickerKey]: iconName });
setIconPickerKey(null);
}}
/>
)}
{/* Image Preview Modal */}
<ImagePreviewModal
isOpen={!!previewModalUrl}
imageUrl={previewModalUrl || ''}
onClose={() => setPreviewModalUrl(null)}
/>
</div>
);
}