import createContextHook from '@nkzw/create-context-hook';
import { useState } from 'react';
import { GetDirectorInfoResponse } from '../../login/lib/api';

export type PersonType = 'yatt' | 'band' | 'legal_entity' | null;

interface RegisterState {
    personType: PersonType;
    setPersonType: (type: PersonType) => void;
    phone: string;
    setPhone: (phone: string) => void;
    referal: string;
    setReferal: (referal: string) => void;
    jshshr: string;
    setJshshr: (jshshr: string) => void;
    passportSeries: string;
    setPassportSeries: (series: string) => void;
    passportNumber: string;
    setPassportNumber: (number: string) => void;
    inn: string;
    setInn: (inn: string) => void;
    info: any;
    setInfo: (info: any) => void;
    reset_full: () => void;
    reset: () => void;
    directorJshshr: string;
    setDirectorJshshr: (directorJshshr: string) => void;
    directorInfo: GetDirectorInfoResponse | null;
    setDirectorInfo: (directorInfo: GetDirectorInfoResponse | null) => void;
}

export const [RegisterProvider, useRegister] = createContextHook<RegisterState>(() => {
    const [personType, setPersonType] = useState<PersonType>(null);
    const [phone, setPhone] = useState<string>('');
    const [referal, setReferal] = useState<string>('');
    const [jshshr, setJshshr] = useState<string>('');
    const [passportSeries, setPassportSeries] = useState<string>('');
    const [passportNumber, setPassportNumber] = useState<string>('');
    const [inn, setInn] = useState<string>('');
    const [info, setInfo] = useState<any>(null);
    const [directorJshshr, setDirectorJshshr] = useState<string>('');
    const [directorInfo, setDirectorInfo] = useState<GetDirectorInfoResponse | null>(null);

    const reset_full = () => {
        setPersonType(null);
        setPhone('');
        setReferal('');
        setJshshr('');
        setPassportSeries('');
        setPassportNumber('');
        setInn('');
        setInfo(null);
        setDirectorJshshr('');
        setDirectorInfo(null);
    };

    const reset = () => {
        setPhone('');
        setReferal('');
        setJshshr('');
        setPassportSeries('');
        setPassportNumber('');
        setInn('');
        setInfo(null);
        setDirectorJshshr('');
        setDirectorInfo(null);
    };

    return {
        personType,
        setPersonType,
        phone,
        setPhone,
        referal,
        setReferal,
        jshshr,
        setJshshr,
        passportSeries,
        setPassportSeries,
        passportNumber,
        setPassportNumber,
        inn,
        setInn,
        reset,
        info,
        setInfo,
        reset_full,
        directorJshshr,
        setDirectorJshshr,
        directorInfo,
        setDirectorInfo,
    };
});
