const sellerBreadcrumbLabels = { products: 'Products', add: 'Add Product', categories: 'Categories', brands: 'Brands', orders: 'Orders', returns: 'Returns & Refunds', cancelled: 'Cancellations', finance: 'Finance', withdrawals: 'Withdrawals', settings: 'Settings', store: 'Store', profile: 'Store Profile', shipping: 'Shipping Settings', marketing: 'Marketing', promotions: 'Promotions', discounts: 'Discounts', coupons: 'Coupons', ads: 'Ads Campaigns', recommendations: 'Marketing Recommendations', performance: 'Marketing Performance', help: 'Help Center', support: 'Seller Support' }

function SellerRouteLayout() {
  const { pathname: path } = useLocation()
  const sellerActiveItem = path.startsWith('/seller-center/marketing') || path === '/seller-center/coupons'
    ? (path.includes('/promotions') ? 'promotions' : path.includes('/discounts') ? 'discounts' : path.includes('/coupons') || path === '/seller-center/coupons' ? 'coupons' : path.includes('/ads') || path.includes('/campaigns') ? 'ads' : path.includes('/recommendations') ? 'recommendations' : path.includes('/performance') ? 'performance' : 'marketing-overview')
    : path.startsWith('/seller-center/products') || ['/seller-center/categories', '/seller-center/brands', '/seller-center/reviews'].includes(path)
    ? (path.includes('/add') ? 'add-product' : path.includes('/categories') ? 'categories' : path.includes('/brands') ? 'brands' : path.includes('/reviews') ? 'reviews' : 'all-products')
    : path.startsWith('/seller-center/orders')
    ? (path.includes('/returns') ? 'returns' : path.includes('/cancelled') ? 'cancelled' : 'all-orders')
    : path.startsWith('/seller-center/finance') || path === '/seller-center/earnings' || path === '/seller-center/withdrawals'
    ? (path.includes('withdraw') ? 'withdrawals' : path.includes('settings') ? 'payment-methods' : 'overview')
    : path.startsWith('/seller-center/store')
    ? (path.includes('shipping') ? 'shipping-settings' : path.includes('settings') ? 'store-settings' : 'store-profile')
    : path === '/seller-center/help' ? 'support-page'
    : path.startsWith('/seller-center/support') ? 'seller-support'
    : 'dashboard'
  const sellerBreadcrumbs = [{ label: 'Dashboard', onClick: () => navigateTo('/seller-center') }]
  path.split('/').filter(Boolean).slice(1).forEach((segment) => {
    const label = sellerBreadcrumbLabels[segment]
    if (label && sellerBreadcrumbs[sellerBreadcrumbs.length - 1].label !== label) sellerBreadcrumbs.push({ label })
  })
  return <SiteChromeContext.Provider value={false}>
    <SellerLayout activeItem={sellerActiveItem} breadcrumbs={sellerBreadcrumbs}><Outlet /></SellerLayout>
  </SiteChromeContext.Provider>
}

function SellerAddProductEditRoute() {
  const { id } = useParams()
  return <SellerAddProduct editMode productId={id} />
}
function SellerSupportDetailRoute() {
  const { id } = useParams()
  return <SellerSupport view="detail" requestId={id} />
}
function SellerReturnsDetailRoute() {
  const { id } = useParams()
  return <SellerRequestDetails type="returns" requestId={id} />
}
function SellerCancelledDetailRoute() {
  const { id } = useParams()
  return <SellerRequestDetails type="cancellations" requestId={id} />
}
