import { __ } from '@wordpress/i18n'; // এই লাইনটি মিসিং ছিল, তাই এরর আসছিল
import { InspectorControls, PanelColorSettings, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, RangeControl, ToggleControl } from '@wordpress/components';
import ServerSideRender from '@wordpress/server-side-render';

export default function Edit({ attributes, setAttributes }) {
    // enableAutoplay এখানে নিয়ে আসা হয়েছে
    const { postCount, accentColor, autoplaySpeed, enableAutoplay, titleColor, priceColor, excerptColor, blobColor1, blobColor2, featuredTagBg, featuredTagText, enableTitleTrim, titleTrimLength } = attributes;
    const blockProps = useBlockProps();

    return (
        <div {...blockProps}>
            <InspectorControls>
                <PanelBody title={__('Slider Settings', 'author-website-templates')}>
                    <RangeControl
                        label={__('Number of Books', 'author-website-templates')}
                        value={postCount}
                        onChange={(value) => setAttributes({ postCount: value })}
                        min={1}
                        max={10}
                    />

                    {/* Autoplay অন/অফ করার টগল বাটন */}
                    <ToggleControl
                        label={__('Enable Autoplay', 'author-website-templates')}
                        checked={enableAutoplay}
                        onChange={(value) => setAttributes({ enableAutoplay: value })}
                    />

                    {/* যদি Autoplay অন থাকে, তখনই কেবল স্পিড কন্ট্রোল দেখাবে */}
                    {enableAutoplay && (
                        <RangeControl
                            label={__('Autoplay Speed (ms)', 'author-website-templates')}
                            value={autoplaySpeed}
                            onChange={(value) => setAttributes({ autoplaySpeed: value })}
                            min={2000}
                            max={10000}
                            step={500}
                        />
                    )}

                    <ToggleControl
                        label={__('Trim Book Title', 'author-website-templates')}
                        checked={enableTitleTrim}
                        onChange={(value) => setAttributes({ enableTitleTrim: value })}
                    />

                    {enableTitleTrim && (
                        <RangeControl
                            label={__('Title Word Limit', 'author-website-templates')}
                            value={titleTrimLength}
                            onChange={(value) => setAttributes({ titleTrimLength: value })}
                            min={2}
                            max={30}
                        />
                    )}
                </PanelBody>

                <PanelColorSettings
                    title={__('Color Settings', 'author-website-templates')}
                    initialOpen={true}
                    colorSettings={[
                        {
                            value: accentColor,
                            onChange: (value) => setAttributes({ accentColor: value }),
                            label: __('Accent Color', 'author-website-templates'),
                        },
                        {
                            value: titleColor,
                            onChange: (value) => setAttributes({ titleColor: value }),
                            label: __('Title Color', 'author-website-templates'),
                        },
                        {
                            value: priceColor,
                            onChange: (value) => setAttributes({ priceColor: value }),
                            label: __('Price Color', 'author-website-templates'),
                        },
                        {
                            value: excerptColor,
                            onChange: (value) => setAttributes({ excerptColor: value }),
                            label: __('Excerpt Color', 'author-website-templates'),
                        },
                        {
                            value: blobColor1,
                            onChange: (value) => setAttributes({ blobColor1: value }),
                            label: __('Top Blob Color (Top Right)', 'author-website-templates'),
                        },
                        {
                            value: blobColor2,
                            onChange: (value) => setAttributes({ blobColor2: value }),
                            label: __('Bottom Blob Color (Bottom Left)', 'author-website-templates'),
                        },
                        {
                            value: featuredTagBg,
                            onChange: (value) => setAttributes({ featuredTagBg: value }),
                            label: __('Featured Tag Background', 'author-website-templates'),
                        },
                        {
                            value: featuredTagText,
                            onChange: (value) => setAttributes({ featuredTagText: value }),
                            label: __('Featured Tag Text', 'author-website-templates'),
                        },
                    ]}
                />
            </InspectorControls>

            <ServerSideRender
                block="awt/author-pro-hero-book-slider"
                attributes={attributes}
            />
        </div>
    );
}