import styled from '@client/styledComponents' ; import moment from 'moment' ; import { GQLLocation , GQLIdentifier } from '@opencrvs/gateway/src/graphql/schema' ; import { IUserDetails } from '@client/utils/userUtils' ; import { ILocation } from '@client/offline/reducer' ; export const Header = styled . h1 `
  color: ${ ( { theme } ) => theme . colors . menuBackground };
  ${ ( { theme } ) => theme . fonts . h4Style };
` ; export function getMonthDateRange ( year , month ) { const currentYear = year + Math . trunc ( ( month - 1 ) / 12 ) ; const start = moment ( [ currentYear , ( month - 1 ) % 12 ] ) ; const end = moment ( start ) . endOf ( 'month' ) ; return { start , end } ; } export const ReportHeader = styled . div `
  margin: 32px 0 24px 0;
` ; export const SubHeader = styled . div `
  color: ${ ( { theme } ) => theme . colors . copy };
  ${ ( { theme } ) => theme . fonts . bigBodyBoldStyle };
` ; export const Description = styled . div `
  margin: 8px 0px;
  color: ${ ( { theme } ) => theme . colors . placeholder };
  ${ ( { theme } ) => theme . fonts . bodyStyle };
` ; export const ActionContainer = styled . div `
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 0 -24px 0 -24px;
  padding: 12px 24px 11px 24px;
  border-bottom: 1px solid ${ ( { theme } ) => theme . colors . dividerDark };
` ; export const FilterContainer = styled . div `
  display: flex;
  flex-wrap: wrap;

  & > :first-child {
    margin: 0 8px 8px 0;
  }

  & > :nth-child(2) {
    margin: 0 8px 8px 0;
  }

  & > :nth-child(3) {
    margin: 0 8px 8px 0;
  }

  & > :last-child {
    margin: 0;
  }
` ; export function getJurisidictionType ( location ) { let jurisdictionType = null ; const jurisdictionTypeIdentifier = location . identifier && ( location . identifier as GQLIdentifier [ ] ) . find ( ( { system } ) => system && system === 'http://opencrvs.org/specs/id/jurisdiction-type' ) ; if ( jurisdictionTypeIdentifier ) { jurisdictionType = jurisdictionTypeIdentifier . value as string ; } return jurisdictionType ; } export function isUnderJurisdictionOfUser ( locations , locationId , jurisdictionLocation ) { if ( ! jurisdictionLocation ) return false ; while ( locationId !== jurisdictionLocation && locationId !== '0' ) { locationId = locations [ locationId ] . partOf . split ( '/' ) [ 1 ] ; } return locationId !== '0' ; } export function getPrimaryLocationIdOfOffice ( locations , office ) { const location = locations [ office . partOf . split ( '/' ) [ 1 ] ] ; if ( ! location ) { throw new Error ( `Office location of ${ office . id } not found` ) ; } return location . id ; } export function getJurisdictionLocationIdFromUserDetails ( userDetails ) { const location = userDetails . catchmentArea && userDetails . catchmentArea . find ( ( location ) => { const jurisdictionTypeIdentifier = location . identifier && location . identifier . find ( ( identifier ) => identifier . system === 'http://opencrvs.org/specs/id/jurisdiction-type' ) ; return ( jurisdictionTypeIdentifier && jurisdictionTypeIdentifier . value ) ; } ) ; return location && location . id ; }