register_content_controls(); $this->register_style_controls(); } private function register_content_controls(): void { $this->start_controls_section( 'section_content', [ 'label' => __( 'محتوا', 'crop-logic' ), ] ); $this->add_control( 'title', [ 'label' => __( 'عنوان', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'دستیار هوشمند کشاورزی', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'subtitle', [ 'label' => __( 'زیرعنوان', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'در مورد آبیاری، کوددهی، تنش گیاه یا بیماری سؤال بپرسید.', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'assistant_name', [ 'label' => __( 'نام دستیار', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'هوش مصنوعی کراپ لاجیک', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'assistant_id', [ 'label' => __( 'شناسه دستیار', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'label_block' => true, 'description' => __( 'شناسه اختیاری دستیار که به بکاند شما ارسال میشود.', 'crop-logic' ), ] ); $this->add_control( 'empty_title', [ 'label' => __( 'عنوان حالت خالی', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'یک گفتگوی جدید کشاورزی را شروع کنید', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'empty_subtitle', [ 'label' => __( 'زیرعنوان حالت خالی', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'از پیشنهادهای زیر استفاده کنید یا سؤال خودتان را بپرسید.', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'input_placeholder', [ 'label' => __( 'متن راهنمای ورودی', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'مشکل مزرعه را بنویسید یا درخواست پیشنهاد بدهید...', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'sidebar_title', [ 'label' => __( 'عنوان سایدبار', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'گفتگوهای اخیر', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'new_chat_label', [ 'label' => __( 'برچسب گفتگوی جدید', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'گفتگوی جدید', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'enable_sidebar', [ 'label' => __( 'فعالسازی تاریخچه سایدبار', 'crop-logic' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'نمایش', 'crop-logic' ), 'label_off' => __( 'مخفی', 'crop-logic' ), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_media_tools', [ 'label' => __( 'نمایش دکمه دوربین', 'crop-logic' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'نمایش', 'crop-logic' ), 'label_off' => __( 'مخفی', 'crop-logic' ), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_voice_button', [ 'label' => __( 'نمایش دکمه صدا', 'crop-logic' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'نمایش', 'crop-logic' ), 'label_off' => __( 'مخفی', 'crop-logic' ), 'return_value' => 'yes', 'default' => '', ] ); $this->end_controls_section(); $this->start_controls_section( 'section_auth_modal', [ 'label' => __( 'مودال احراز هویت', 'crop-logic' ), ] ); $this->add_control( 'auth_title', [ 'label' => __( 'عنوان مودال', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ورود یا ثبت نام', 'crop-logic' ), 'label_block' => true, ] ); $this->add_control( 'auth_description', [ 'label' => __( 'توضیح مودال', 'crop-logic' ), 'type' => Controls_Manager::TEXTAREA, 'default' => __( 'برای ادامه گفتگو ابتدا وارد حساب خود شوید.', 'crop-logic' ), ] ); $this->add_control( 'auth_login_tab', [ 'label' => __( 'تب ورود', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ورود', 'crop-logic' ), ] ); $this->add_control( 'auth_register_tab', [ 'label' => __( 'تب ثبت نام', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ثبت نام', 'crop-logic' ), ] ); $this->add_control( 'auth_forgot_tab', [ 'label' => __( 'تب فراموشی رمز', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'فراموشی رمز', 'crop-logic' ), ] ); $this->add_control( 'auth_reset_tab', [ 'label' => __( 'تب ریست رمز', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ریست رمز', 'crop-logic' ), ] ); $this->add_control( 'auth_login_button', [ 'label' => __( 'دکمه ورود', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ورود', 'crop-logic' ), ] ); $this->add_control( 'auth_register_button', [ 'label' => __( 'دکمه ثبت نام', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ثبت نام', 'crop-logic' ), ] ); $this->add_control( 'auth_forgot_button', [ 'label' => __( 'دکمه فراموشی رمز', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ارسال لینک بازیابی', 'crop-logic' ), ] ); $this->add_control( 'auth_reset_button', [ 'label' => __( 'دکمه ریست رمز', 'crop-logic' ), 'type' => Controls_Manager::TEXT, 'default' => __( 'ثبت رمز جدید', 'crop-logic' ), ] ); $this->end_controls_section(); } private function register_style_controls(): void { $this->start_controls_section( 'section_style_colors', [ 'label' => __( 'Colors', 'crop-logic' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'primary_color', [ 'label' => __( 'Primary', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#2b8a3e', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-primary: {{VALUE}};', ], ] ); $this->add_control( 'accent_color', [ 'label' => __( 'Accent', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#2d9cdb', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-accent: {{VALUE}};', ], ] ); $this->add_control( 'page_background', [ 'label' => __( 'Background', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#f5f7f1', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-bg: {{VALUE}};', ], ] ); $this->add_control( 'surface_color', [ 'label' => __( 'Surface', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-surface: {{VALUE}};', ], ] ); $this->add_control( 'border_color', [ 'label' => __( 'Border', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => 'rgba(43, 138, 62, 0.15)', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-border: {{VALUE}};', ], ] ); $this->add_control( 'text_color', [ 'label' => __( 'Text', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#16331b', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-text: {{VALUE}};', ], ] ); $this->add_control( 'muted_text_color', [ 'label' => __( 'Muted Text', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#5f6f62', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-muted: {{VALUE}};', ], ] ); $this->add_control( 'user_bubble_color', [ 'label' => __( 'User Bubble', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => 'rgba(43, 138, 62, 0.12)', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-user-bubble: {{VALUE}};', ], ] ); $this->add_control( 'assistant_bubble_color', [ 'label' => __( 'Assistant Bubble', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-assistant-bubble: {{VALUE}};', ], ] ); $this->add_control( 'input_background', [ 'label' => __( 'Composer Background', 'crop-logic' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .crop-logic-chat' => '--cl-input-bg: {{VALUE}};', ], ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_typography', [ 'label' => __( 'Typography', 'crop-logic' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'label' => __( 'عنوان', 'crop-logic' ), 'selector' => '{{WRAPPER}} .crop-logic-chat__title', ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'body_typography', 'label' => __( 'Body', 'crop-logic' ), 'selector' => '{{WRAPPER}} .crop-logic-chat, {{WRAPPER}} .crop-logic-chat__input', ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); $chips = []; $suggestions = isset( $settings['suggestions'] ) && is_array( $settings['suggestions'] ) ? $settings['suggestions'] : []; foreach ( $suggestions as $item ) { if ( ! empty( $item['label'] ) ) { $chips[] = (string) $item['label']; } } $client_settings = [ 'threadsUrl' => esc_url_raw( rest_url( 'crop-logic/v1/threads' ) ), 'messagesUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%/messages' ) ), 'sendUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%/send' ) ), 'deleteThreadUrlTemplate' => esc_url_raw( rest_url( 'crop-logic/v1/threads/%conversation_id%' ) ), 'verifyUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/verify' ) ), 'loginUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/login' ) ), 'registerUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/register' ) ), 'forgotUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/forgot-password' ) ), 'resetUrl' => esc_url_raw( rest_url( 'crop-logic/v1/auth/reset-password' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'widgetId' => $this->get_id(), 'assistantId' => sanitize_text_field( (string) $settings['assistant_id'] ), 'title' => (string) $settings['title'], 'assistantName' => (string) $settings['assistant_name'], 'emptyTitle' => (string) $settings['empty_title'], 'emptySubtitle' => (string) $settings['empty_subtitle'], 'inputPlaceholder' => (string) $settings['input_placeholder'], 'sidebarTitle' => (string) $settings['sidebar_title'], 'newChatLabel' => (string) $settings['new_chat_label'], 'enableSidebar' => 'yes' === $settings['enable_sidebar'], 'showMediaTools' => 'yes' === $settings['show_media_tools'], 'showVoiceButton' => 'yes' === $settings['show_voice_button'], 'suggestions' => $chips, 'i18n' => [ 'error' => __( 'در حال حاضر ارتباط با دستیار هوش مصنوعی برقرار نشد.', 'crop-logic' ), 'typing' => __( 'در حال فکر کردن...', 'crop-logic' ), 'sidebarEmpty' => __( 'هنوز گفتگویی ذخیره نشده است.', 'crop-logic' ), 'attachmentLabel' => __( 'تصویر پیوستشده', 'crop-logic' ), 'attachmentsLabel' => __( 'تصاویر پیوستشده', 'crop-logic' ), 'removeFile' => __( 'حذف فایل', 'crop-logic' ), 'deleteMessage' => __( 'حذف پیام', 'crop-logic' ), 'loading' => __( 'در حال بارگذاری گفتگوها...', 'crop-logic' ), 'loadingSubtitle' => __( 'لطفا کمی صبر کنید.', 'crop-logic' ), 'frequency' => __( 'تناوب', 'crop-logic' ), 'amount' => __( 'مقدار', 'crop-logic' ), 'timing' => __( 'زمان', 'crop-logic' ), 'whyThis' => __( 'چرا این پیشنهاد؟', 'crop-logic' ), 'attachmentPrompt' => __( 'لطفا تصویر پیوستشده را بررسی کن.', 'crop-logic' ), 'authTitle' => (string) $settings['auth_title'], 'authNeeded' => (string) $settings['auth_description'], 'loginTab' => (string) $settings['auth_login_tab'], 'registerTab' => (string) $settings['auth_register_tab'], 'forgotTab' => (string) $settings['auth_forgot_tab'], 'resetTab' => (string) $settings['auth_reset_tab'], 'loginHeading' => __( 'ورود به حساب کاربری', 'crop-logic' ), 'registerHeading' => __( 'ایجاد حساب جدید', 'crop-logic' ), 'forgotHeading' => __( 'بازیابی رمز عبور', 'crop-logic' ), 'resetHeading' => __( 'تنظیم رمز عبور جدید', 'crop-logic' ), 'registerHelp' => __( 'حساب خود را بسازید تا گفتگوها و پیشنهادهای کشاورزی برای شما ذخیره شود.', 'crop-logic' ), 'forgotHelp' => __( 'ایمیل حساب را وارد کنید تا لینک بازیابی برای شما ارسال شود.', 'crop-logic' ), 'resetHelp' => __( 'توکن بازیابی و رمز عبور جدید را وارد کنید تا دوباره وارد حساب شوید.', 'crop-logic' ), 'identifier' => __( 'ایمیل یا نام کاربری یا موبایل', 'crop-logic' ), 'email' => __( 'ایمیل', 'crop-logic' ), 'password' => __( 'رمز عبور', 'crop-logic' ), 'name' => __( 'نام', 'crop-logic' ), 'lastName' => __( 'نام خانوادگی', 'crop-logic' ), 'username' => __( 'نام کاربری', 'crop-logic' ), 'phone' => __( 'شماره موبایل', 'crop-logic' ), 'confirmPassword' => __( 'تکرار رمز عبور', 'crop-logic' ), 'resetToken' => __( 'توکن ریست', 'crop-logic' ), 'noAccount' => __( 'حساب کاربری ندارید؟', 'crop-logic' ), 'haveAccount' => __( 'قبلا ثبت نام کردهاید؟', 'crop-logic' ), 'rememberedPassword'=> __( 'رمز عبور را به خاطر آوردید؟', 'crop-logic' ), 'resetHint' => __( 'توکن بازیابی دارید؟ رمز را ریست کنید', 'crop-logic' ), 'submitLogin' => (string) $settings['auth_login_button'], 'submitRegister' => (string) $settings['auth_register_button'], 'submitForgot' => (string) $settings['auth_forgot_button'], 'submitReset' => (string) $settings['auth_reset_button'], 'logout' => __( 'خروج', 'crop-logic' ), 'deleteConversation'=> __( 'حذف گفتگو', 'crop-logic' ), 'closeModal' => __( 'بستن', 'crop-logic' ), 'notLoggedIn' => __( 'وارد نشده', 'crop-logic' ), 'loggedIn' => __( 'وارد شده', 'crop-logic' ), ], ]; ?>