import {FC, FormEventHandler} from 'react'
import { LeftSidebarWithMenu } from '@tesseract-design/viewfinder'
import {models} from '@tonality/library-common'
import CreateRingtoneForm from '../../organisms/forms/CreateRingtone'
import Link from '../../molecules/navigation/Link'
import OmnisearchForm from '../../organisms/forms/Omnisearch'
import Brand from '../../molecules/brand/Brand'

type Props = {
	onSearch?: FormEventHandler,
	onSubmit?: FormEventHandler,
	composer: models.Composer,
	currentRingtone?: models.Ringtone,
	composerRingtones: models.Ringtone[],
}

const CreateRingtoneTemplate: FC<Props> = ({
	onSearch,
	onSubmit,
	composer,
	currentRingtone = {},
	composerRingtones = [],
}) => {
	return (
		<LeftSidebarWithMenu.Layout
			brand={
				<Brand />
			}
			userLink={
				<div>
					User
				</div>
			}
			topBarCenter={
				<OmnisearchForm
					labels={{
						form: 'Search',
						query: 'Query',
					}}
					onSubmit={onSearch}
					action="/api/a/search"
				/>
			}
			linkComponent={({ url, icon, label, }) => (
				<Link
					href={url}
				>
					<LeftSidebarWithMenu.SidebarMenuContainer>
						<LeftSidebarWithMenu.SidebarMenuItemIcon>
							{icon}
						</LeftSidebarWithMenu.SidebarMenuItemIcon>
						{label}
					</LeftSidebarWithMenu.SidebarMenuContainer>
				</Link>
			)}
			moreLinkMenuItem={{
				label: 'More',
				icon: 'M',
				url: {},
			}}
			moreLinkComponent={({ url, icon, label, }) => (
				<Link
					href={url}
				>
					<LeftSidebarWithMenu.MoreSidebarMenuContainer>
						<LeftSidebarWithMenu.MoreSidebarMenuItemIcon>
							{icon}
						</LeftSidebarWithMenu.MoreSidebarMenuItemIcon>
						{label}
					</LeftSidebarWithMenu.MoreSidebarMenuContainer>
				</Link>
			)}
			sidebarMenuItems={[
				{
					id: 'browse',
					label: 'Browse',
					icon: 'B',
					url: {
						pathname: '/ringtones',
					},
				},
				{
					id: 'compose',
					label: 'Compose',
					icon: 'C',
					url: {
						pathname: '/my/create/ringtone',
					},
				},
			]}
			sidebarMain={
				<LeftSidebarWithMenu.SidebarMainContainer>
					Hi
				</LeftSidebarWithMenu.SidebarMainContainer>
			}
		>
			<LeftSidebarWithMenu.ContentContainer>
				<CreateRingtoneForm
					onSubmit={onSubmit}
					defaultValues={{
						...currentRingtone,
						composerId: composer.id,
					}}
					action="/api/a/create/ringtone"
					labels={{
						form: 'Create Ringtone',
						name: 'Name',
						data: 'Data',
						cta: 'Post',
					}}
				/>
			</LeftSidebarWithMenu.ContentContainer>
		</LeftSidebarWithMenu.Layout>
	)
}

export default CreateRingtoneTemplate
