import { Meta } from "@storybook/react";
import MultiSelect from "./MultiSelect";
import { MultiSelectProps } from "./MultiSelectProps";
import React from "react";
import { MultiSelectChangeEvent as KendoMultiSelectChangeEvent } from "@progress/kendo-react-dropdowns";
import Hint from "@/components/Labels/Hint/Hint";

const sports = [
  "Baseball",
  "Basketball",
  "Cricket",
  "Field Hockey",
  "Football",
  "Table Tennis",
  "Tennis",
  "Volleyball",
];

export default {
  title: "Design System/Dropdowns/MultiSelect",
  component: MultiSelect,
  tags: ["autodocs"],
  parameters: {
    docs: {
      description: {
        component:
          'The KendoReact MultiSelect is a form component that displays a list of options and allows for multiple selections from this list and supports custom rendering of popup items and tags, header and footer elements, virtualization, and configurable options for controlling the list behavior. \n\n```javascript\nimport { MultiSelect } from "@renault-ui-library"\n```',
      },
    },
  },
  argTypes: {
    dataTestId: {
      control: { type: "text" },
      description: "Specifies the data-test-id attribute for testing purposes.",
    },
    accessKey: {
      control: { type: "text" },
      description: "Specifies the accessKey of the MultiSelect.",
    },
    adaptive: {
      control: { type: "boolean" },
      description:
        "Providing different rendering of the popup element based on the screen dimensions.",
    },
    adaptiveFilter: {
      control: { type: "text" },
      description:
        "Sets the value of the adaptive filtering input of the of MultiSelect.",
    },
    adaptiveTitle: {
      control: { type: "text" },
      description:
        "Specifies the text that is rendered as title in the adaptive popup.",
    },
    allowCustom: {
      control: { type: "boolean" },
      description:
        "Specifies whether the MultiSelect allows user-defined values that are not present in the dataset.",
    },
    ariaDescribedBy: {
      control: { type: "text" },
      description:
        "Identifies the element(s) which will describe the component, similar to HTML aria-describedby attribute.",
    },
    ariaLabelledBy: {
      control: { type: "text" },
      description: "Identifies the element(s) which will label the component.",
    },
    autoClose: {
      control: { type: "boolean" },
      description:
        "Determines whether to close the options list of the MultiSelect after the item selection is finished.",
    },
    className: {
      control: { type: "text" },
      description: "Sets additional classes to the MultiSelect.",
    },
    data: {
      control: { type: "object" },
      description: "Sets the data of the MultiSelect.",
    },
    dataItemKey: {
      control: { type: "text" },
      description:
        "Sets the key for comparing the data items of the MultiSelect.",
    },
    defaultValue: {
      control: { type: "object" },
      description:
        "Sets the default value of the MultiSelect. Similar to the native select HTML element.",
    },
    dir: {
      control: { type: "text" },
      description: "Represents the dir HTML attribute.",
    },
    disabled: {
      control: { type: "boolean" },
      description: "Sets the disabled state of the MultiSelect.",
    },
    fillMode: {
      control: {
        type: "select",
        options: ["null", "flat", "outline", "solid"],
      },
      description: "Configures the fillMode of the MultiSelect.",
    },
    filter: {
      control: { type: "text" },
      description:
        "Sets the value of filtering input. Useful for making the filtering input a controlled component.",
    },
    filterable: {
      control: { type: "boolean" },
      description: "Enables the filtering functionality of the MultiSelect.",
    },
    footer: {
      control: { type: "object" },
      description: "Sets the footer component of the MultiSelect.",
    },
    groupField: {
      control: { type: "text" },
      description:
        "Sets the data item field that represents the start of a group. Applicable to objects data.",
    },
    header: {
      control: { type: "object" },
      description: "Sets the header component of the MultiSelect.",
    },
    id: {
      control: { type: "text" },
      description: "Specifies the id of the component.",
    },
    label: {
      control: { type: "text" },
      description: "Renders a floating label for the MultiSelect.",
    },
    loading: {
      control: { type: "boolean" },
      description: "Sets the loading state of the MultiSelect.",
    },
    name: {
      control: { type: "text" },
      description: "Specifies the name property of the input DOM element.",
    },
    opened: {
      control: { type: "boolean" },
      description: "Sets the opened and closed state of the MultiSelect.",
    },
    placeholder: {
      control: { type: "text" },
      description: "The hint that is displayed when the MultiSelect is empty.",
    },
    popupSettings: {
      control: { type: "object" },
      description: "Configures the popup of the MultiSelect.",
    },
    required: {
      control: { type: "boolean" },
      description: "Specifies if null is a valid value for the component.",
    },
    rounded: {
      control: {
        type: "select",
        options: ["null", "small", "medium", "full", "large"],
      },
      description: "Configures the roundness of the MultiSelect.",
    },
    size: {
      control: {
        type: "select",
        options: ["null", "small", "medium", "large"],
      },
      description: "Configures the size of the MultiSelect.",
    },
    skipDisabledItems: {
      control: { type: "boolean" },
      description:
        "Defines if MultiSelect's disabled items will be skipped or focused when navigating through the list of items using a keyboard.",
    },
    style: {
      control: { type: "object" },
      description: "The styles that are applied to the MultiSelect.",
    },
    tabIndex: {
      control: { type: "number" },
      description: "Specifies the tabIndex of the MultiSelect.",
    },
    tags: {
      control: { type: "object" },
      description: "Sets the tags of the MultiSelect.",
    },
    textField: {
      control: { type: "text" },
      description: "Sets the data item field that represents the item text.",
    },
    valid: {
      control: { type: "boolean" },
      description: "Overrides the validity state of the component.",
    },
    validationMessage: {
      control: { type: "text" },
      description: "Controls the form error message of the component.",
    },
    validityStyles: {
      control: { type: "boolean" },
      description:
        "If set to false, no visual representation of the invalid state of the component will be applied.",
    },
    value: {
      control: { type: "object" },
      description: "Sets the value of the MultiSelect.",
    },
    virtual: {
      control: { type: "object" },
      description: "Configures the virtual scrolling of the MultiSelect.",
    },
    focusedItemIndex: {
      control: { type: "function" },
      description:
        "If set, the MultiSelect will use it to get the focused item index.",
    },
    groupHeaderItemRender: {
      control: { type: "function" },
      description: "Fires when a group header item is about to be rendered.",
    },
    groupStickyHeaderItemRender: {
      control: { type: "function" },
      description:
        "Fires when a sticky group header item is about to be rendered.",
    },
    itemRender: {
      control: { type: "function" },
      description: "Fires when a list item is about to be rendered.",
    },
    listNoDataRender: {
      control: { type: "function" },
      description:
        "Fires when the element which indicates no data in the popup is about to be rendered.",
    },
    onBlur: {
      control: { type: "function" },
      description: "Fires each time the MultiSelect gets blurred.",
    },
    onCancel: {
      control: { type: "function" },
      description:
        "Fires each time the user discards changes in the input field.",
    },
    onChange: {
      control: { type: "function" },
      description:
        "Fires each time the value of the MultiSelect is about to be changed.",
    },
    onClose: {
      control: { type: "function" },
      description:
        "Fires each time the popup of the MultiSelect is about to close.",
    },
    onFilterChange: {
      control: { type: "function" },
      description:
        "Fires each time the user types in the filtering input. The event is preventable.",
    },
    onFocus: {
      control: { type: "function" },
      description: "Fires each time the MultiSelect gets focused.",
    },
    onOpen: {
      control: { type: "function" },
      description:
        "Fires each time the popup of the MultiSelect is about to open.",
    },
    onPageChange: {
      control: { type: "function" },
      description:
        "Fires when the MultiSelect is about to change its current page of items.",
    },
    tagRender: {
      control: { type: "function" },
      description: "Fires when a tag is about to be rendered.",
    },
  },
} as Meta;

export const Default = (args: MultiSelectProps): JSX.Element => {
  const [value, setValue] = React.useState<string[]>([
    "Baseball",
    "Volleyball",
  ]);

  const onChange = (event: KendoMultiSelectChangeEvent) => {
    setValue([...event.value]);
  };

  return (
    <>
      <MultiSelect data={args.data} onChange={onChange} value={value} />
      <Hint>You can choose more than one option</Hint>
    </>
  );
};

Default.args = {
  dataTestId: "multi-select-data-testid",
  placeholder: "Please select ...",
  data: sports,
  fillMode: "solid",
  rounded: "medium",
  size: "large",
  disabled: false,
};
