/**
 * Retrieves the translation of text.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
 */
import { __ } from '@wordpress/i18n';

/**
 * React hook that is used to mark the block wrapper element.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
 */
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';

/**
 * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
 *
 * @see https://www.npmjs.com/package/@wordpress/scripts#using-css
 */
import './editor.scss';
import SidePanel from './side-panel';

const TEMPLATE = [
  ['core/group', { 
    style: {
      spacing: {
        padding: {
          top: "2rem",
          right: "2rem",
          bottom: "2rem",
          left: "2rem"
        }
      },
      backgroundColor: "#f5f5f5",
      border: {
        radius: "4px",
        width: "1px",
        style: "solid",
        color: "#dddddd"
      }
    }
  }, [
    ['core/heading', { 
      level: 2, 
      content: 'Slide Title',
      style: {
        spacing: {
          margin: {
            bottom: "1rem"
          }
        }
      }
    }],
    ['core/paragraph', { 
      content: 'Add your content here...',
      style: {
        spacing: {
          margin: {
            top: "0",
            bottom: "0"
          }
        }
      }
    }]
  ]]
];

/**
 * The edit function describes the structure of your block in the context of the
 * editor. This represents what the editor will render when the block is used.
 *
 * @return {Element} Element to render.
 */
export default function Edit({ attributes, setAttributes }) {
  const { width } = attributes;

  const blockProps = useBlockProps({
    className: 'orphic-ui-carousel-slide',
    style: {
      width: width ? `${width}px` : '300px'
    }
  });

  return (
    <div {...blockProps}>
      <SidePanel attributes={attributes} setAttributes={setAttributes} />
      <InnerBlocks 
        template={TEMPLATE}
        templateLock={false}
      />
    </div>
  );
}
