import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';

import * as strings from 'PnPspSendEmailUtilityWebPartStrings';
import PnPspSendEmailUtility from './components/PnPspSendEmailUtility';
import { IPnPspSendEmailUtilityProps } from './components/IPnPspSendEmailUtilityProps';

export interface IPnPspSendEmailUtilityWebPartProps {
  description: string;
}

export default class PnPspSendEmailUtilityWebPart extends BaseClientSideWebPart <IPnPspSendEmailUtilityWebPartProps> {

  public render(): void {
    const element: React.ReactElement<IPnPspSendEmailUtilityProps> = React.createElement(
      PnPspSendEmailUtility,
      {
        description: this.properties.description,
        context:this.context,
        spconect:this.context,
      }
    );

    ReactDom.render(element, this.domElement);
  }

  protected onDispose(): void {
    ReactDom.unmountComponentAtNode(this.domElement);
  }

  protected get dataVersion(): Version {
    return Version.parse('1.0');
  }

  protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField('description', {
                  label: strings.DescriptionFieldLabel
                })
              ]
            }
          ]
        }
      ]
    };
  }
}
