import { __ } from "@wordpress/i18n"; import { useDispatch, useSelect } from "@wordpress/data"; import { RichText } from "@wordpress/block-editor"; import { memo, useMemo, useState } from "@wordpress/element"; import { HeaderIcon, InfoIcon, TriggerButtonIcon } from "./icon"; import { ProIconLight } from "../../admin/icons"; // Writing tone list const writingTonesList = [ { label: "Balanced", value: "balanced" }, { label: "Professional", value: "professional" }, { label: "Friendly", value: "friendly" }, { label: "Conversational", value: "conversational" }, { label: "Informative", value: "informative" }, { label: "Technical", value: "technical" }, { label: "Persuasive", value: "persuasive" }, { label: "Supportive", value: "supportive" }, { label: "Documentation Style", value: "documentation_style" }, { label: "Beginner-Friendly", value: "beginner_friendly" }, ]; // Supported languages list const supportedLanguagesList = [ { label: "English", value: "english" }, { label: "Bengali", value: "bengali" }, { label: "Hindi", value: "hindi" }, { label: "Spanish", value: "spanish" }, { label: "French", value: "french" }, { label: "German", value: "german" }, { label: "Portuguese", value: "portuguese" }, { label: "Chinese", value: "chinese" }, { label: "Japanese", value: "japanese" }, { label: "Korean", value: "korean" }, { label: "Arabic", value: "arabic" }, { label: "Urdu", value: "urdu" }, { label: "Turkish", value: "turkish" }, { label: "Indonesian", value: "indonesian" }, { label: "Russian", value: "russian" }, { label: "Italian", value: "italian" }, { label: "Dutch", value: "dutch" }, ]; // Content source list const faqContentSourceList = [ { label: "Select Source", value: "" }, { label: "Pages", value: "page" }, { label: "Posts", value: "post" }, { label: "Products", value: "product" }, ]; const faqContentSourceLabels = { "": __("Select Content", "easy-accordion-free"), page: __("Select Page", "easy-accordion-free"), post: __("Select Post", "easy-accordion-free"), product: __("Select Product", "easy-accordion-free"), }; // TriggerButton. export const TriggerButton = memo(() => ( {__("Generate FAQs with AI", "easy-accordion-free")} )); // Controlled Select. const RenderSelect = ({ items, id, value, onChange }) => (
); // PromptCardHeading. export const PromptCardHeading = ({ onClose }) => (

{__("AI FAQs Generation", "easy-accordion-free")}

{__( "Configure the AI parameters to generate desired FAQs for your content.", "easy-accordion-free" )}

onClose(null)} className="eab-faq-gen-prompt-card__close-btn eab-icon-cross sp-cursor-pointer" >
); // PromptCard. export const PromptCard = memo( ({ formData, onFieldChange, handleFormSubmit, loading, modelOptions = [], generatedFaqItems }) => { // Fetch posts based on selected content source const allPosts = useSelect( (select) => select("core").getEntityRecords("postType", formData?.contentSource, { per_page: 100, status: "publish", }), [formData?.contentSource] ); const postOptions = useMemo(() => { return ( allPosts?.map((post) => ({ label: post?.title?.raw.length > 60 ? post?.title?.raw.substring(0, 60) + "..." : post?.title?.raw, value: post?.link, id: post?.id, })) || [] ); }, [allPosts]); return (
{/* Row 1 */}
{/* Row 2 */}
{/* Keywords */}
onFieldChange("keywords", e.target.value)} /> {__( "Add keywords to guide the AI and generate more relevant FAQs. Separate with commas.", "easy-accordion-free" )}
{/* Prompt */}