import { Meta } from "@storybook/react";
import { EditorProps } from "./EditorProps";
import Editor from "./Editor";
import { EditorTools } from "@progress/kendo-react-editor";

const {
  Bold,
  Italic,
  Underline,
  Strikethrough,
  Subscript,
  Superscript,
  AlignLeft,
  AlignCenter,
  AlignRight,
  AlignJustify,
  Indent,
  Outdent,
  OrderedList,
  UnorderedList,
  Undo,
  Redo,
  FontSize,
  FontName,
  FormatBlock,
  Link,
  Unlink,
  InsertImage,
  ViewHtml,
  InsertTable,
  AddRowBefore,
  AddRowAfter,
  AddColumnBefore,
  AddColumnAfter,
  DeleteRow,
  DeleteColumn,
  DeleteTable,
  MergeCells,
  SplitCell,
} = EditorTools;

export default {
  title: "Design System/Editor",
  component: Editor,
  tags: ["autodocs"],
  parameters: {
    docs: {
      description: {
        component:
          'The React Editor, part of KendoReact, is built from the ground up and specifically for React, so that you get a high-performance control which integrates tightly with your application and with the rest of the KendoReact components.  \n\n```javascript\nimport { Editor } from "@renault-ui-library"\n```',
      },
    },
  },
  argTypes: {
    dataTestId: {
      control: { type: "text" },
      description: "Specifies the data-test-id attribute for testing purposes.",
    },
    ariaDescribedBy: {
      control: { type: "text" },
      description:
        "Identifies the element(s) which will describe the component, similar to HTML aria-describedby attribute.",
    },
    ariaLabel: {
      control: { type: "text" },
      description: "Sets the aria-label attribute.",
    },
    ariaLabelledBy: {
      control: { type: "text" },
      description: "Identifies the element(s) which will label the component.",
    },
    className: {
      control: { type: "text" },
      description: "Sets additional classes to the Editor.",
    },
    contentStyle: {
      control: { type: "object" },
      description: "Sets the styles of the content.",
    },
    defaultContent: {
      control: { type: "text" },
      description: "Sets the default content of the Editor.",
    },
    defaultEditMode: {
      control: { type: "select", options: ["div", "iframe"] },
      description: "Sets the default edit mode.",
    },
    dir: {
      control: { type: "text" },
      description: "Represents the dir HTML attribute.",
    },
    keyboardNavigation: {
      control: { type: "boolean" },
      description: "Enables the keyboard navigation.",
    },
    preserveWhitespace: {
      control: { type: "boolean" },
      description: "Preserves the white spaces.",
    },
    resizable: {
      control: { type: "boolean" },
      description: "Enables the resizing of the Editor.",
    },
    style: {
      control: { type: "object" },
      description: "Sets the styles of the Editor.",
    },
    tools: {
      control: { type: "array" },
      description: "Sets the tools of the Editor.",
    },
    value: {
      control: { type: "text" },
      description: "Sets the value of the Editor.",
    },
    onBlur: {
      control: { type: "object" },
      description: "Fires when the Editor loses focus.",
    },
    onChange: {
      control: { type: "object" },
      description: "Fires when the Editor value changes.",
    },
    onExecute: {
      control: { type: "object" },
      description: "Fires when a command is executed.",
    },
    onFocus: {
      control: { type: "object" },
      description: "Fires when the Editor gains focus.",
    },
    onMount: {
      control: { type: "object" },
      description: "Fires when the Editor is mounted.",
    },
    onPasteHtml: {
      control: { type: "object" },
      description: "Fires when HTML is pasted into the Editor.",
    },
  },
} as Meta;

export const Default = (args: EditorProps): JSX.Element => (
  <Editor
    tools={[
      [Bold, Italic, Underline, Strikethrough],
      [Subscript, Superscript],
      [AlignLeft, AlignCenter, AlignRight, AlignJustify],
      [Indent, Outdent],
      [OrderedList, UnorderedList],
      FontSize,
      FontName,
      FormatBlock,
      [Undo, Redo],
      [Link, Unlink, InsertImage, ViewHtml],
      [InsertTable],
      [AddRowBefore, AddRowAfter, AddColumnBefore, AddColumnAfter],
      [DeleteRow, DeleteColumn, DeleteTable],
      [MergeCells, SplitCell],
    ]}
    contentStyle={{ height: 630 }}
    value={args.value}
    {...args}
  />
);

Default.args = {
  dataTestId: "editor-data-testid",
  defaultContent: "<p>Hello World</p>",
  defaultEditMode: "iframe",
};
