export default {
  name: "Textarea",
  acceptsChildren: false,
  category: "Input",
  props: [
    {
      label: "Initial Value",
      name: "defaultValue",
      type: { kind: "text", isDynamic: true },
      isDefault: true,
      default: "",
      placeholder: "Enter some text...",
      help: "The input's default value",
    },
    {
      label: "Placeholder",
      name: "placeholder",
      type: { kind: "text" },
      isDefault: true,
      default: "Enter some text...",
      placeholder: "Enter some text...",
      help: "The placeholder text to display",
    },
    {
      label: "Required",
      name: "required",
      type: { kind: "boolean" },
      default: false,
      isDefault: true,
      placeholder: "",
      help: "The is this value required by a form?",
    },
    {
      label: "Is disabled",
      name: "disabled",
      type: { kind: "boolean", isDynamic: true },
      default: false,
      placeholder: "",
      help: "Whether the input is disabled",
    },
    {
      label: "Min lines",
      name: "minRows",
      type: { kind: "number", isDynamic: true },
      default: null,
      placeholder: "1",
      help: "Minimum number of lines to show",
    },
    {
      label: "Max lines",
      name: "maxRows",
      type: { kind: "number", isDynamic: true },
      default: null,
      placeholder: "Infinity",
      help: "Maximum number of lines to show",
    },
    {
      label: "Submit on Enter",
      name: "submitOnEnter",
      type: { kind: "boolean" },
      placeholder: "",
      help: "If true, pressing enter without shift will submit the form",
    },
  ],
  events: [
    {
      label: "When changed",
      name: "onChange",
      help: "Select an action to run when input's value has changed",
    },
    {
      label: "When focused",
      name: "onFocus",
      help: "Select an action to run when input's has focused",
    },
    {
      label: "When blurred",
      name: "onBlur",
      help: "Select an action to run when input's has blurred",
      isDefault: true,
    },
  ],
  defaultStyles: {
    ":hover": {
      "border-color": "var(--theme-border-emphasized)",
    },
    ":focus": {
      "border-color": "var(--theme-brand-brand-ring)",
      "box-shadow": "var(--theme-brand-brand-ring) 0px 0px 0px 1px",
    },
    ":error": {
      "border-color": "var(--theme-border-error)",
    },
    "": {
      "font-family": "var(--theme-fonts-body)",
      "font-size": "var(--theme-fontSizes-md)",
      color: "var(--theme-fg-default)",
      "overflow-x": "hidden",
      "overflow-y": "hidden",
      width: "100%",
      "min-width": "0",
      "padding-right": "16px",
      "padding-left": "16px",
      "padding-top": "8px",
      "padding-bottom": "8px",
      "border-color": "var(--theme-border-default)",
      "border-radius": "var(--theme-radii-md)",
      "border-width": "1px",
      "border-style": "solid",
      "background-color": "transparent",
      "box-shadow": "var(--theme-shadows-none)",
      "scroll-padding-bottom": "8px",
      "text-align": "start",
      outline: "var(--theme-sizes-zero)",
      "line-height": "inherit",
    },
  },
  sources: [
    {
      id: "value",
      name: "{{= it.component.name }}'s current value",
      provider: "StateProvider",
      description: "The current value of the textarea",
      template:
        "$get('{{= it.component.id}}', { value: {{= it.stringify(it.component.props.defaultValue) }} ?? '' }).value",
      instanceTemplate: `{{= it.component.name }}'s current value`,
      outputType: { kind: "text" },
    },
  ],
  actions: [
    {
      id: "set",
      name: `Set "{{= it.component.name }}"'s value`,
      provider: "StateProvider",
      description: "Set the value of the input",
      async: false,
      template:
        // eslint-disable-next-line no-template-curly-in-string
        "$set('{{= it.component.id }}', { value: {{= it.stringify(it.data.value) }} });",
      instanceTemplate: `{{= it.stringify(it.data.value) }}`,
      props: [
        {
          label: "Value",
          name: "value",
          type: { kind: "text", isDynamic: true },
          placeholder: "Choose a value",
          required: true,
          default: null,
          help: "The value to set the state variable to",
        },
      ],
    },
    {
      id: "focus",
      name: `Focus "{{= it.component.name }}" textarea`,
      description: "Focus the textarea",
      async: false,
      template:
        // eslint-disable-next-line no-template-curly-in-string
        'document.querySelector(`[data-id="${$$getKey({{= it.stringify(it.component.id) }})}"]`)?.focus();',
      instanceTemplate: `Focus textarea "{{= it.component.name }}"`,
      props: [],
    },
    {
      id: "blur",
      name: `Blur "{{= it.component.name }}" textarea`,
      description: "Blur the textarea",
      async: false,
      template:
        // eslint-disable-next-line no-template-curly-in-string
        'document.querySelector(`[data-id="${$$getKey({{= it.stringify(it.component.id) }})}"]`)?.blur();',
      instanceTemplate: `Blur textarea "{{= it.component.name }}"`,
      props: [],
    },
  ],
} as const;
