import { Input, Form } from 'antd'
import { connect } from 'react-redux'
import commonStyles from '../../../../../Utils/Common.less'
import React, { useEffect } from 'react'
import { type CorporateConfigurationInterface } from '../../../../../Types/Client/RegisteredClients/Corporate'
const { TextArea } = Input

const GoCardlessForm = (
    props: CorporateConfigurationInterface
): React.ReactElement => {
    const { registeredClientCorporateConfiguration } = props
    const [form] = Form.useForm()

    useEffect(() => {
        form.setFieldsValue(registeredClientCorporateConfiguration.data)
    }, [registeredClientCorporateConfiguration])

    const handleFinish = (): void => {
        const formData = form.getFieldsValue()
        console.log(formData)
    }

    const customizeRequiredMark = (
        label: React.ReactNode,
        { required }: { required: boolean }
    ): React.ReactElement => (
        <>
            {label}
            &nbsp;
            {required && <span className={commonStyles.requireIcon}>*</span>}
        </>
    )

    return (
        <div className={commonStyles.formWrapper}>
            <Form
                name="complex-form"
                layout={'vertical'}
                autoComplete="off"
                form={form}
                onFinish={handleFinish}
                requiredMark={customizeRequiredMark}
                labelCol={{ span: 24 }}
                wrapperCol={{ span: 24 }}
            >
                <Form.Item
                    label="Company Name"
                    name="companyName"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter Company Name',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Given Name"
                    name="givenName"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter Given Name',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Family Name"
                    name="familyName"
                    rules={[
                        {
                            required: true,
                            message:
                                'familyName cannot be a number or contain numbers!',

                            pattern: /^[a-zA-Z]+$/,
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Email"
                    name="email"
                    rules={[
                        {
                            // type: 'email',
                            required: true,
                            message: 'Please input your email!',

                            // pattern:
                            //     /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Address Line1"
                    name="addressLine1"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter Address Line1',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item label="Address Line2" name="addressLine2">
                    <Input />
                </Form.Item>
                <Form.Item label="Address Line3" name="addressLine3">
                    <Input />
                </Form.Item>
                <Form.Item
                    label="City"
                    name="city"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter City',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Postal Code"
                    name="postalCode"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your PostCode!',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Country Code"
                    name="countryCode"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter Country Code',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Region"
                    name="region"
                    rules={[
                        {
                            required: true,
                            message:
                                'Region cannot be a number or contain numbers!',

                            pattern: /^[a-zA-Z]+$/,
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Language"
                    name="language"
                    rules={[
                        {
                            required: true,
                            message:
                                'Language cannot be a number or contain numbers!',

                            pattern: /^[a-zA-Z]+$/,
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="Phone Number"
                    name="phoneNumber"
                    rules={[
                        {
                            pattern: /^\(?(\d{2})\)?[- ]?(\d{4})[- ]?(\d{6})$/,
                            message: 'please enter valid mobile number',
                        },
                        {
                            required: true,
                            message: 'Please input your mobile number!',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="Description"
                    name="description"
                    rules={[
                        {
                            required: true,
                            message: 'Please Enter Description',
                        },
                    ]}
                >
                    <TextArea rows={4} />
                </Form.Item>
            </Form>
        </div>
    )
}

const mapStateToProps = (state: any): any => {
    return {
        registeredClientCorporateConfiguration:
            state.client.registeredClientCorporateConfiguration,
    }
}

export default connect(mapStateToProps)(GoCardlessForm)
